forked from rundeck/rundeck-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
238 lines (203 loc) · 7.36 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import java.util.regex.Matcher
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
}
}
plugins {
id 'pl.allegro.tech.build.axion-release' version '1.4.1'
id 'groovy'
id 'com.github.johnrengelman.shadow' version '1.2.3'
id "nebula.ospackage" version "3.6.1"
id 'de.fuerstenau.buildconfig' version '1.1.8'
id 'idea'
id 'eclipse'
}
def genChangelog(prevTag, baseUrl) {
def diff = "${prevTag}..."
def serr = new StringBuilder(), sout = new StringBuilder()
def proc = ['git', 'log', '--no-merges','--pretty=format:%s', diff].execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
def logs = sout.toString().readLines()
def include = [~/.*[fF]ix(e[sd])? #\d+.*/, ~/^[fF]ix(e[sd])?(:|\s).*/, ~/^[lL]og:?.*/]
logs = logs.
findAll { t -> t && include.any { t ==~ it } }.
collect { '* ' + it.replaceAll(/^[lL]og:\s+/,'').replaceAll(/(#(\d+))/, "[Issue \$1]($baseUrl/issues/\$2)") }.
join('\n')
return logs ? logs + '\n' : ''
}
scmVersion {
tag {
prefix = 'v'
versionSeparator = ''
}
hooks {
pre 'fileUpdate', [file : 'docs/_config.yml',
pattern : { v, c -> /app_version: [^\s]+/ },
replacement: { v, c -> "app_version: $v" }]
pre 'fileUpdate', [file : 'src/main/resources/rd-banner.txt',
pattern : { v, c -> /\(v$v\)/ },
replacement: { v, c -> "(v$v)" }]
pre { context ->
def ghurl = "https://github.com/rundeck/rundeck-cli"
def changelog = file('CHANGELOG.md')
def changes = file('docs/changes.md')
def changest = file('docs/_changes.md')
def diff = "v${context.previousVersion}..."
def logs = genChangelog("v${context.previousVersion}", ghurl)
def text = """## ${context.currentVersion}
$logs
[Changes]($ghurl/compare/${diff}v${context.currentVersion})
"""
def newtext = changelog.text.replaceAll(
~/(?m)^(## ${context.previousVersion}.*)$/,
Matcher.quoteReplacement(text) + '$1'
)
changelog.text = newtext
changes.text = changest.text + newtext
context.addCommitPattern('docs/changes.md')
context.addCommitPattern('CHANGELOG.md')
}
pre 'commit'
}
}
allprojects {
project.version = scmVersion.version
ext.rpmVersion=project.version.replaceAll('-', '.')
}
def getAxionVersion() {
def ctx = pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext.create(project)
def rules = ctx.rules
scmVersion.versionService.currentVersion(
rules.version,
rules.tag,
rules.nextVersion
)
}
task previousVersion << {
println "Previous version: ${axionVersion.previousVersion}"
}
task changeLog << {
println genChangelog(axionVersion.position.latestTag, "https://github.com/rundeck/rundeck-cli")
}
/**
* Generates java source with embedded version info
*/
buildConfig {
clsName = 'Version'
packageName = 'org.rundeck.client'
}
apply plugin: 'idea'
apply plugin: 'groovy'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'nebula.ospackage'
mainClassName = 'org.rundeck.client.tool.Main'
applicationName = 'rd'
//install path in rpm/deb
ext.distInstallPath = '/var/lib/rundeck-cli'
defaultTasks 'clean', 'build'
repositories {
mavenLocal()
mavenCentral()
maven { url "https://jitpack.io" }
}
ext.toolbeltVersion = "0.1.18"
ext.toolbeltGroup = "com${toolbeltVersion.contains('SNAPSHOT')?'':'.github'}.simplifyops.cli-toolbelt"
dependencies {
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
compile 'com.squareup.retrofit2:converter-simplexml:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
compile "$toolbeltGroup:toolbelt:$toolbeltVersion"
compile "$toolbeltGroup:toolbelt-snakeyaml:$toolbeltVersion"
compile "$toolbeltGroup:toolbelt-json-jackson:$toolbeltVersion"
compile "$toolbeltGroup:toolbelt-jewelcli:$toolbeltVersion"
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'com.squareup.retrofit2:retrofit-mock:2.1.0'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.19'
testCompile "org.codehaus.groovy:groovy-all:2.3.7"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}
//force distZip/distTar artifacts to be overwritten by shadow versions
distShadowZip.mustRunAfter distZip
distShadowTar.mustRunAfter distTar
def scriptsClos = {
def addConfigSource = { regexTest, additionalText, line ->
// Looking for the line that starts with either CLASSPATH=
// or set CLASSPATH=, defined by the regexTest closure argument.
line = line.replaceAll(~/${regexTest}/) { original ->
additionalText + "\n" + original
}
}
def addUnixConfigSource = addConfigSource.curry(
'^# Determine the Java command to use to start the JVM.*',
'''
# Source user's config file
APP_CONFIG=$HOME/.$APP_NAME/$APP_NAME.conf
test -f $APP_CONFIG && source $APP_CONFIG
'''
)
// The default script content is generated and
// with the doLast method we can still alter
// the contents before the complete task ends.
doLast {
// Alter the start script for Unix systems.
unixScript.text =
unixScript
.readLines()
.collect(addUnixConfigSource)
.join('\n')
//TODO: modify windows start script to load config
}
}
startScripts scriptsClos
startShadowScripts scriptsClos
task verifyScripts {
group = "Verification"
description = 'Verify the start scripts (normal and shadow) contain the modifications for the APP_CONFIG'
doFirst {
[startScripts.outputDir, startShadowScripts.outputDir].each { dir ->
def f = new File(dir, applicationName)
assert f.exists()
assert f.text ==~ /(?s)^.*APP_CONFIG.*$/
}
}
}
check.dependsOn verifyScripts
/**
* Define rpm/deb details
*/
ospackage {
version = rpmVersion
release = 1
summary = "A commandline tool for Rundeck."
packageDescription = "The rd program provides an all-in-one commandline tool to interact with Rundeck"
url = 'https://github.com/rundeck/rundeck-cli'
vendor = 'SimplifyOps, Inc.'
license = 'APL'
os = 'LINUX'
packageGroup = 'System'
user = 'root'
//packaging includes the distShadowZip contents, exclude *.bat
from(zipTree(distShadowZip.outputs.files.singleFile)) {
exclude '**/*.bat'
into distInstallPath
}
def archivedir=distShadowZip.archiveName - ".${distShadowZip.extension}"
//symlink /usr/bin/rd to the rd script
link("/usr/bin/${applicationName}", "${distInstallPath}/${archivedir}/bin/${applicationName}")
}
//depend on the shadow artifact
buildDeb.dependsOn distShadowZip
buildRpm.dependsOn distShadowZip
assemble.dependsOn buildRpm, buildDeb
apply from: 'gradle/bintray.gradle'
task wrapper(type: Wrapper) {
gradleVersion = '2.13'
}