forked from rundeck/rundeck-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
175 lines (155 loc) · 5.02 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
/*
* 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.8.4'
}
}
plugins {
id 'pl.allegro.tech.build.axion-release' version '1.9.3'
id 'maven-publish'
}
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])?:.*/, ~/^[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 : 'rd-cli-tool/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('-', '.')
repositories {
mavenLocal()
jcenter()
mavenCentral()
}
}
ext.axionContext=
pl.allegro.tech.build.axion.release.infrastructure.di.GradleAwareContext.create(project, project.scmVersion)
def getAxionVersion = {
def rules = axionContext.rules
axionContext.versionService()
scmVersion.versionService.currentVersion(
rules.version,
rules.tag,
rules.nextVersion
)
}
def getPreviousTag = {
def rules = axionContext.rules
def curVersion = getAxionVersion()
rules.tag.serialize(rules.tag, curVersion.previousVersion.toString())
}
task previousVersion(){
doLast {
println "Previous version: ${getAxionVersion().previousVersion}"
println "Previous tag: ${getPreviousTag()}"
}
}
task changeLog(){
doLast {
def version = getAxionVersion()
def prevTag = getPreviousTag()
println genChangelog(
prevTag,
githubUrl,
version.version,
version.previousVersion,
changelogFile,
project.hasProperty("changelogFull")
)
}
}