-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.gradle.kts
421 lines (378 loc) · 16.7 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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
@file:Suppress("HasPlatformType")
import com.felipefzdz.gradle.shellcheck.Shellcheck
import org.gradle.crypto.checksum.Checksum
plugins {
id("base")
id("com.felipefzdz.gradle.shellcheck") version "1.5.0"
id("com.github.breadmoirai.github-release") version "2.5.2"
id("org.gradle.crypto.checksum") version "1.4.0"
}
group = "com.gradle"
repositories {
exclusiveContent {
forRepository {
ivy {
url = uri("https://github.com/matejak/")
patternLayout {
artifact("[module]/archive/refs/tags/[revision].[ext]")
}
metadataSources {
artifact()
}
}
}
filter {
includeModule("argbash", "argbash")
}
}
exclusiveContent {
forRepository {
ivy {
url = uri("https://raw.githubusercontent.com/gradle/develocity-ci-injection/")
patternLayout {
artifact("refs/tags/v[revision]/reference/develocity-injection.init.gradle")
}
metadataSources {
artifact()
}
}
}
filter {
includeModule("com.gradle", "develocity-injection")
}
}
exclusiveContent {
forRepository {
maven("https://repo.gradle.org/artifactory/solutions")
}
filter {
includeModule("com.gradle", "build-scan-summary")
}
}
mavenCentral()
}
val isDevelopmentRelease = !hasProperty("finalRelease")
val releaseVersion = releaseVersion()
val releaseNotes = releaseNotes()
val distributionVersion = distributionVersion()
val buildScanSummaryVersion = "1.0.1-2024.1"
allprojects {
version = releaseVersion.get()
}
val argbash by configurations.creating
val develocityInjection = configurations.dependencyScope("develocityInjection") {
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named("develocity-injection-script"))
}.get()
val develocityInjectionResolvable = configurations.resolvable("${develocityInjection.name}Resolvable") {
extendsFrom(develocityInjection)
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named("develocity-injection-script"))
}
val develocityComponents by configurations.creating {
attributes.attribute(
TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
objects.named(TargetJvmEnvironment.STANDARD_JVM)
)
}
val mavenComponents by configurations.creating
val thirdPartyMavenComponents by configurations.creating
val develocityMavenComponents by configurations.creating
dependencies {
argbash("argbash:argbash:2.10.0@zip")
develocityInjection("com.gradle:develocity-injection:1.1")
develocityComponents("com.gradle:build-scan-summary:$buildScanSummaryVersion")
develocityMavenComponents("com.gradle:gradle-enterprise-maven-extension:1.18.4")
mavenComponents(project(path = ":configure-develocity-maven-extension", configuration = "shadow"))
thirdPartyMavenComponents("com.gradle:common-custom-user-data-maven-extension:2.0.1")
}
shellcheck {
additionalArguments = "-a -x"
shellcheckVersion = "v0.10.0"
}
val copyDevelocityComponents by tasks.registering(Sync::class) {
from(develocityComponents)
into(project.layout.buildDirectory.dir("components/develocity"))
include("build-scan-summary-$buildScanSummaryVersion.jar")
}
val copyThirdPartyComponents by tasks.registering(Sync::class) {
from(develocityComponents)
into(project.layout.buildDirectory.dir("components/third-party"))
exclude("build-scan-summary-$buildScanSummaryVersion.jar")
}
val unpackArgbash by tasks.registering(Sync::class) {
group = "argbash"
description = "Unpacks Argbash."
from(zipTree(argbash.singleFile)) {
// All files in the zip are under an "argbash-VERSION/" directory. We only want everything under this directory.
// We can remove the top-level directory while unpacking the zip by dropping the first directory in each file's relative path.
eachFile {
relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray())
}
includeEmptyDirs = false
}
into(layout.buildDirectory.dir("argbash"))
}
val generateBashCliParsers by tasks.registering(ApplyArgbash::class) {
group = "argbash"
description = "Uses Argbash to generate Bash command line argument parsing code."
argbashHome.set(layout.dir(unpackArgbash.map { it.outputs.files.singleFile }))
scriptTemplates.set(fileTree("components/scripts") {
include("**/*-cli-parser.m4")
exclude("gradle/.data/")
exclude("maven/.data/")
})
supportingTemplates.set(fileTree("components/scripts") {
include("**/*.m4")
exclude("gradle/.data/")
exclude("maven/.data/")
})
}
val copyGradleScripts by tasks.registering(Sync::class) {
group = "build"
description = "Copies the Gradle source and the generated scripts to the output directory."
// local variable required for configuration cache compatibility
// https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:not_yet_implemented:accessing_top_level_at_execution
val releaseVersion = releaseVersion
val buildScanSummaryVersion = buildScanSummaryVersion
inputs.property("project.version", releaseVersion)
inputs.property("summary.version", buildScanSummaryVersion)
from(layout.projectDirectory.dir("components/licenses/gradle"))
from(layout.projectDirectory.file("components/licenses/NOTICE"))
from(layout.projectDirectory.dir("release").file("version.txt"))
rename("version.txt", "VERSION")
from(layout.projectDirectory.dir("components/scripts/gradle")) {
exclude("gradle-init-scripts")
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
filter { line: String -> line.replace("<SUMMARY_VERSION>", buildScanSummaryVersion) }
}
from(layout.projectDirectory.dir("components/scripts/gradle")) {
include("gradle-init-scripts/**")
into("lib/scripts/")
}
from(develocityInjectionResolvable) {
rename { "develocity-injection.gradle" }
into("lib/scripts/gradle-init-scripts")
}
from(layout.projectDirectory.dir("components/scripts")) {
include("README.md")
include("mapping.example")
include("network.settings")
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
filter { line: String -> line.replace("<SUMMARY_VERSION>", buildScanSummaryVersion) }
}
from(layout.projectDirectory.dir("components/scripts/lib")) {
include("**")
exclude("cli-parsers")
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
filter { line: String -> line.replace("<SUMMARY_VERSION>", buildScanSummaryVersion) }
into("lib/scripts/")
}
from(generateBashCliParsers.map { it.outputDir.file("lib/cli-parsers/gradle") }) {
into("lib/scripts/")
}
from(copyDevelocityComponents) {
into("lib/develocity/")
}
from(copyThirdPartyComponents) {
into("lib/third-party/")
}
into(layout.buildDirectory.dir("scripts/gradle"))
}
val copyMavenScripts by tasks.registering(Sync::class) {
group = "build"
description = "Copies the Maven source and the generated scripts to the output directory."
// local variable required for configuration cache compatibility
// https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:not_yet_implemented:accessing_top_level_at_execution
val releaseVersion = releaseVersion
val buildScanSummaryVersion = buildScanSummaryVersion
inputs.property("project.version", releaseVersion)
inputs.property("summary.version", buildScanSummaryVersion)
from(layout.projectDirectory.dir("components/licenses/maven"))
from(layout.projectDirectory.file("components/licenses/NOTICE"))
from(layout.projectDirectory.dir("release").file("version.txt"))
rename("version.txt", "VERSION")
from(layout.projectDirectory.dir("components/scripts/maven")) {
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
filter { line: String -> line.replace("<SUMMARY_VERSION>", buildScanSummaryVersion) }
}
from(layout.projectDirectory.dir("components/scripts/")) {
include("README.md")
include("mapping.example")
include("network.settings")
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
filter { line: String -> line.replace("<SUMMARY_VERSION>", buildScanSummaryVersion) }
}
from(layout.projectDirectory.dir("components/scripts/lib")) {
include("**")
exclude("cli-parsers")
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
filter { line: String -> line.replace("<SUMMARY_VERSION>", buildScanSummaryVersion) }
into("lib/scripts/")
}
from(generateBashCliParsers.map { it.outputDir.file("lib/cli-parsers/maven") }) {
into("lib/scripts/")
}
from(copyDevelocityComponents) {
into("lib/develocity/")
}
from(develocityMavenComponents) {
into("lib/develocity/")
}
from(copyThirdPartyComponents) {
into("lib/third-party/")
}
from(thirdPartyMavenComponents) {
into("lib/third-party/")
}
from(mavenComponents) {
into("lib/scripts/maven-libs/")
}
into(layout.buildDirectory.dir("scripts/maven"))
}
val copyLegacyGradleScripts by tasks.registering(Sync::class) {
group = "build"
description = "Copies the Gradle source and the generated scripts to the output directory."
from(copyGradleScripts) {
exclude("lib/scripts/config.sh")
}
from(copyGradleScripts) {
include("lib/scripts/config.sh")
filter { line: String -> line.replace("LEGACY_DISTRIBUTION=\"false\"", "LEGACY_DISTRIBUTION=\"true\"") }
}
into(layout.buildDirectory.dir("scripts/gradle-legacy"))
}
val copyLegacyMavenScripts by tasks.registering(Sync::class) {
group = "build"
description = "Copies the Maven source and the generated scripts to the output directory."
from(copyMavenScripts) {
exclude("lib/scripts/config.sh")
}
from(copyMavenScripts) {
include("lib/scripts/config.sh")
filter { line: String -> line.replace("LEGACY_DISTRIBUTION=\"false\"", "LEGACY_DISTRIBUTION=\"true\"") }
}
into(layout.buildDirectory.dir("scripts/maven-legacy"))
}
val assembleGradleScripts by tasks.registering(Zip::class) {
group = "build"
description = "Packages the Gradle experiment scripts in a zip archive."
archiveBaseName.set("develocity-gradle-build-validation")
archiveFileName.set(archiveBaseName.flatMap { a -> distributionVersion.map { v -> "$a-$v.zip" } })
from(copyGradleScripts)
into(archiveBaseName.get())
}
val assembleMavenScripts by tasks.registering(Zip::class) {
group = "build"
description = "Packages the Maven experiment scripts in a zip archive."
archiveBaseName.set("develocity-maven-build-validation")
archiveFileName.set(archiveBaseName.flatMap { a -> distributionVersion.map { v -> "$a-$v.zip" } })
from(copyMavenScripts)
into(archiveBaseName.get())
}
val assembleLegacyGradleScripts by tasks.registering(Zip::class) {
group = "build"
description = "Packages the Gradle experiment scripts in a zip archive."
archiveBaseName.set("gradle-enterprise-gradle-build-validation")
archiveFileName.set(archiveBaseName.flatMap { a -> distributionVersion.map { v -> "$a-$v.zip" } })
from(copyLegacyGradleScripts)
into(archiveBaseName.get())
}
val assembleLegacyMavenScripts by tasks.registering(Zip::class) {
group = "build"
description = "Packages the Maven experiment scripts in a zip archive."
archiveBaseName.set("gradle-enterprise-maven-build-validation")
archiveFileName.set(archiveBaseName.flatMap { a -> distributionVersion.map { v -> "$a-$v.zip" } })
from(copyLegacyMavenScripts)
into(archiveBaseName.get())
}
tasks.assemble {
dependsOn(assembleGradleScripts, assembleMavenScripts, assembleLegacyGradleScripts, assembleLegacyMavenScripts)
}
val shellcheckGradleScripts by tasks.registering(Shellcheck::class) {
group = "verification"
description = "Perform quality checks on Gradle build validation scripts using Shellcheck."
sourceFiles = copyGradleScripts.get().outputs.files.asFileTree.matching {
include("**/*.sh")
// scripts in lib/scripts/ are checked when Shellcheck checks the top-level scripts because the top-level scripts include (source) the scripts in lib/
exclude("lib/scripts/")
}
// scripts in lib/ are still inputs to this task (we want shellcheck to run if they change) even though we don't include them explicitly in sourceFiles
inputs.files(copyGradleScripts.get().outputs.files.asFileTree.matching {
include("lib/**/*.sh")
}).withPropertyName("libScripts")
.withPathSensitivity(PathSensitivity.RELATIVE)
workingDir = layout.buildDirectory.file("scripts/gradle").get().asFile
reports {
html.outputLocation.set(layout.buildDirectory.file("reports/shellcheck-gradle/shellcheck.html"))
xml.outputLocation.set(layout.buildDirectory.file("reports/shellcheck-gradle/shellcheck.xml"))
txt.outputLocation.set(layout.buildDirectory.file("reports/shellcheck-gradle/shellcheck.txt"))
}
}
val shellcheckMavenScripts by tasks.registering(Shellcheck::class) {
group = "verification"
description = "Perform quality checks on Maven build validation scripts using Shellcheck."
sourceFiles = copyMavenScripts.get().outputs.files.asFileTree.matching {
include("**/*.sh")
// scripts in lib/scripts/ are checked when Shellcheck checks the top-level scripts because the top-level scripts include (source) the scripts in lib/
exclude("lib/scripts/")
}
// scripts in lib/ are still inputs to this task (we want shellcheck to run if they change) even though we don't include them explicitly in sourceFiles
inputs.files(copyMavenScripts.get().outputs.files.asFileTree.matching {
include("lib/**/*.sh")
}).withPropertyName("libScripts")
.withPathSensitivity(PathSensitivity.RELATIVE)
workingDir = layout.buildDirectory.file("scripts/maven").get().asFile
reports {
html.outputLocation.set(layout.buildDirectory.file("reports/shellcheck-maven/shellcheck.html"))
xml.outputLocation.set(layout.buildDirectory.file("reports/shellcheck-maven/shellcheck.xml"))
txt.outputLocation.set(layout.buildDirectory.file("reports/shellcheck-maven/shellcheck.txt"))
}
}
tasks.check {
dependsOn(shellcheckGradleScripts, shellcheckMavenScripts)
}
val generateChecksums by tasks.registering(Checksum::class) {
group = "distribution"
description = "Generates checksums for the distribution zip files."
inputFiles.setFrom(assembleGradleScripts, assembleMavenScripts, assembleLegacyGradleScripts, assembleLegacyMavenScripts)
outputDirectory.set(layout.buildDirectory.dir("distributions/checksums").get().asFile)
checksumAlgorithm.set(Checksum.Algorithm.SHA512)
}
githubRelease {
token((findProperty("github.access.token") ?: System.getenv("GITHUB_ACCESS_TOKEN") ?: "").toString())
owner.set("gradle")
repo.set("develocity-build-validation-scripts")
targetCommitish.set("main")
releaseName.set(gitHubReleaseName())
tagName.set(gitReleaseTag())
prerelease.set(isDevelopmentRelease)
overwrite.set(isDevelopmentRelease)
generateReleaseNotes.set(false)
body.set(releaseNotes)
releaseAssets(assembleGradleScripts, assembleMavenScripts, assembleLegacyGradleScripts, assembleLegacyMavenScripts, generateChecksums.map { it.outputs.files.asFileTree })
}
val createReleaseTag by tasks.registering(CreateGitTag::class) {
// Ensure tag is created only after a successful build
mustRunAfter("build")
tagName.set(githubRelease.tagName.map { it.toString() })
overwriteExisting.set(isDevelopmentRelease)
}
tasks.githubRelease {
dependsOn(createReleaseTag)
}
fun gitHubReleaseName(): Provider<String> {
return releaseVersion.map { if (isDevelopmentRelease) "Development release" else it }
}
fun gitReleaseTag(): Provider<String> {
return releaseVersion.map { if (isDevelopmentRelease) "development-latest" else "v$it" }
}
fun distributionVersion(): Provider<String> {
return releaseVersion.map { if (isDevelopmentRelease) "dev" else it }
}
fun releaseVersion(): Provider<String> {
val versionFile = layout.projectDirectory.file("release/version.txt")
return providers.fileContents(versionFile).asText.map { it.trim() }
}
fun releaseNotes(): Provider<String> {
val releaseNotesFile = layout.projectDirectory.file("release/changes.md")
return providers.fileContents(releaseNotesFile).asText.map { it.trim() }
}