forked from rundeck/rundeck-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
298 lines (259 loc) · 9.05 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
* Copyright 2017 Rundeck, Inc. (http://rundeck.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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'
}
ext.githubUrl = "https://github.com/rundeck/rundeck-cli"
ext.changelogFile = file("CHANGELOG.md")
/**
* Unreleased changes list from the changelog file
* @param prevVersion
* @param changelog
* @return
*/
def unreleasedLog(prevVersion, changelog) {
def m = changelog?.text =~ ~/(?si)^(## unreleased(.*))## ${prevVersion}.*$/
if (m.find()) {
return m.group(2)?.split(/\n/).findAll { it }.collect { it.replaceAll(/^[\*-]\s*/, '') }
}
}
/**
* Generate partial or full changelog
* @param prevTag
* @param baseUrl
* @param curVersion
* @param prevVersion
* @param changelog
* @param full
* @return
*/
def genChangelog(prevTag, baseUrl, curVersion, prevVersion, File changelog, full = false) {
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:?.*/]
def unrel = changelog ? unreleasedLog(prevVersion, changelog) ?: [] : []
unrel.addAll(logs.findAll { t -> t && include.any { t ==~ it } })
logs = unrel.
collect { '* ' + it.replaceAll(/^[lL]og:\s+/,'').replaceAll(/(#(\d+))/, "[Issue \$1]($baseUrl/issues/\$2)") }.
join('\n')
logs = logs ? logs + '\n' : ''
if (full && changelog) {
def text = """## ${curVersion}
$logs
[Changes]($baseUrl/compare/${diff}v${curVersion})
"""
return changelog.text.replaceAll(
~/(?s)^(## unreleased(.*))?(## ${prevVersion}.*)$/,
Matcher.quoteReplacement(text) + '$3'
)
}
return logs
}
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 changelog = changelogFile
def changes = file('docs/changes.md')
def changest = file('docs/_changes.md')
def newtext = genChangelog(
"v${context.previousVersion}",
githubUrl,
context.currentVersion,
context.previousVersion,
changelog,
true
)
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 << {
def version = axionVersion
println genChangelog(
version.position.latestTag,
githubUrl,
version.version,
version.previousVersion,
changelogFile,
project.hasProperty("changelogFull")
)
}
/**
* 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 {
compileOnly "org.projectlombok:lombok:1.16.16"
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 'com.squareup.okhttp3:mockwebserver:3.4.1'
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'
}