forked from hivemq/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
178 lines (169 loc) · 7.72 KB
/
build.gradle.kts
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
/* ******************** update versions ******************** */
val updateOperatorChartVersion by tasks.registering(Exec::class) {
group = "version"
description =
"Bumps Operator Legacy Chart and Platform versions." +
"\n\tUsage: ./gradlew updateOperatorChartVersion -PchartVersion=a.b.c -PappVersion=x.y.z" +
"\n\t\t- 'chartVersion': Operator Legacy chart version. Optional, if not present, it will automatically be bumped to the next patch version." +
"\n\t\t- 'appVersion': Platform version. Optional."
doFirst {
updateChartAndValueFilesWithVersion(
arrayOf(
"charts/hivemq-operator/Chart.yaml",
"charts/hivemq-operator/values.yaml"
), """(image:\s+[^:]+:\w+-)(\S+)"""
)
}
dependsOn(gradle.includedBuild("tests-hivemq-operator").task(":updatePlatformVersion"))
workingDir(layout.projectDirectory)
commandLine("sh", "./manifests/hivemq-operator/manifests.sh")
}
val updateSwarmChartVersion by tasks.registering(Exec::class) {
group = "version"
description =
"Bumps Swarm Chart and Platform versions." +
"\n\tUsage: ./gradlew updateSwarmChartVersion -PchartVersion=a.b.c -PappVersion=x.y.z" +
"\n\t\t- 'chartVersion': Swarm chart version. Optional, if not present, it will automatically be bumped to the next patch version." +
"\n\t\t- 'appVersion': Platform version. Optional."
doFirst {
updateChartAndValueFilesWithVersion(
arrayOf(
"charts/hivemq-swarm/Chart.yaml",
"charts/hivemq-swarm/values.yaml"
), """(tag:\s*)(\S+)"""
)
}
workingDir(layout.projectDirectory)
commandLine("sh", "./manifests/hivemq-swarm/manifests.sh")
}
val updatePlatformOperatorChartVersion by tasks.registering(Exec::class) {
group = "version"
description =
"Bumps Platform Operator Chart and Operator Platform versions." +
"\n\tUsage: ./gradlew updatePlatformOperatorChartVersion -PchartVersion=a.b.c -PappVersion=x.y.z" +
"\n\t\t- 'chartVersion': Platform Operator chart version. Optional, if not present, it will automatically be bumped to the next patch version." +
"\n\t\t- 'appVersion': Platform Operator version. Optional."
doFirst {
updateChartAndValueFilesWithVersion(
arrayOf(
"charts/hivemq-platform-operator/Chart.yaml",
"charts/hivemq-platform-operator/values.yaml"
), """(tag:\s*)(\S+)"""
)
}
workingDir(layout.projectDirectory)
commandLine("sh", "./manifests/hivemq-platform-operator/manifests.sh")
}
val updatePlatformChartVersion by tasks.registering(Exec::class) {
group = "version"
description =
"Bumps Platform Chart and Platform versions." +
"\n\tUsage: ./gradlew updatePlatformChartVersion -PchartVersion=a.b.c -PappVersion=x.y.z" +
"\n\t\t- 'chartVersion': Platform chart version. Optional, if not present, it will automatically be bumped to the next patch version." +
"\n\t\t- 'appVersion': Platform release version. Optional."
doFirst {
updateChartAndValueFilesWithVersion(
arrayOf(
"charts/hivemq-platform/Chart.yaml",
"charts/hivemq-platform/values.yaml"
), """(tag:\s*)(\S+)"""
)
}
dependsOn(gradle.includedBuild("tests-hivemq-platform-operator").task(":updatePlatformVersion"))
workingDir(layout.projectDirectory)
commandLine("sh", "./manifests/hivemq-platform/manifests.sh")
}
var checkAppVersion = false
var checkAppVersionUsage = ""
val updateAllPlatformChartVersions by tasks.registering {
val usage = "Usage: ./gradlew updateAllPlatformChartVersions -PappVersion=x.y.z" +
"\n\t\t- 'appVersion': Platform release version. Mandatory."
group = "version"
description = "Bumps all Platform Charts and Platform versions except HiveMQ Platform Operator chart.\n\t$usage"
checkAppVersion = true
checkAppVersionUsage = usage
dependsOn(updateOperatorChartVersion)
dependsOn(updateSwarmChartVersion)
dependsOn(updatePlatformChartVersion)
}
val updateAllManifestFiles by tasks.registering {
group = "version"
description = "Updates all manifest files."
doLast {
exec {
workingDir(layout.projectDirectory)
commandLine("sh", "./manifests/hivemq-operator/manifests.sh")
}
exec {
workingDir(layout.projectDirectory)
commandLine("sh", "./manifests/hivemq-platform/manifests.sh")
}
exec {
workingDir(layout.projectDirectory)
commandLine("sh", "./manifests/hivemq-platform-operator/manifests.sh")
}
exec {
workingDir(layout.projectDirectory)
commandLine("sh", "./manifests/hivemq-swarm/manifests.sh")
}
}
}
val test by tasks.registering {
group = "test"
description = "Executes all Helm unit tests."
doLast {
exec {
workingDir(layout.projectDirectory)
commandLine("helm", "unittest", "./charts/hivemq-operator", "-f", "./tests/**/*_test.yaml")
}
exec {
workingDir(layout.projectDirectory)
commandLine("helm", "unittest", "./charts/hivemq-platform", "-f", "./tests/**/*_test.yaml")
}
exec {
workingDir(layout.projectDirectory)
commandLine("helm", "unittest", "./charts/hivemq-platform-operator", "-f", "./tests/**/*_test.yaml")
}
exec {
workingDir(layout.projectDirectory)
commandLine("helm", "unittest", "./charts/hivemq-swarm", "-f", "./tests/**/*_test.yaml")
}
}
}
fun updateChartAndValueFilesWithVersion(versionFilesToUpdate: Array<String>, valuesRegex: String) {
val appVersion = project.properties["appVersion"]
if (checkAppVersion && appVersion == null) {
error("`appVersion` must be set\n\n$checkAppVersionUsage")
}
val filesToUpdate = files(versionFilesToUpdate)
filesToUpdate.filter { file -> file.name == "Chart.yaml" }.forEach { file ->
var text = file.readText()
val chartVersion = project.properties["chartVersion"] ?: run {
// bump the last part of the current chart version
val chartVersionMatch = """(?m)^version:\s*(\S+)$""".toRegex().find(text)
val currentVersion = chartVersionMatch?.groupValues?.get(1)
?: error("Failed to determine current chart version in $file, set `chartVersion` manually.")
val versionParts = currentVersion.split('.').takeIf { it.size == 3 }
?: error("Failed to determine patch version of $currentVersion in $file, set `chartVersion` manually.")
val incrementedVersion = (versionParts[2].toIntOrNull() ?: 0) + 1
"${versionParts[0]}.${versionParts[1]}.$incrementedVersion"
}
text = text.replace("""(?m)^version:\s*\S+$""".toRegex(), "version: $chartVersion").also {
require(it != text) { error("Failed to replace version with $chartVersion in $file") }
}
if (appVersion != null) {
text = text.replace("""(?m)^appVersion:\s*\S+$""".toRegex(), "appVersion: $appVersion").also {
require(it != text) { error("Failed to replace appVersion with $appVersion in $file") }
}
}
file.writeText(text)
}
if (appVersion != null) {
filesToUpdate.filter { file -> file.name == "values.yaml" }.forEach { file ->
val text = file.readText()
file.writeText(text.replace(valuesRegex.toRegex()) {
"${it.groupValues[1]}${appVersion}"
})
}
}
}