-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
303 lines (266 loc) · 11.6 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
@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.4.6"
id("com.github.breadmoirai.github-release") version "2.4.1"
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")
}
}
mavenCentral()
}
val isDevelopmentRelease = !hasProperty("finalRelease")
val releaseVersion = releaseVersion()
val releaseNotes = releaseNotes()
val distributionVersion = distributionVersion()
allprojects {
version = releaseVersion.get()
}
val argbash by configurations.creating
val commonComponents by configurations.creating
val mavenComponents by configurations.creating
dependencies {
argbash("argbash:argbash:2.10.0@zip")
commonComponents(project(path = ":fetch-build-scan-data-cmdline-tool", configuration = "shadow"))
mavenComponents(project(":configure-gradle-enterprise-maven-extension"))
mavenComponents("com.gradle:gradle-enterprise-maven-extension:1.16.0")
mavenComponents("com.gradle:common-custom-user-data-maven-extension:1.12.2")
}
shellcheck {
additionalArguments = "-a -x"
shellcheckVersion = "v0.8.0"
}
val unpackArgbash by tasks.registering(Copy::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(Copy::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
inputs.property("project.version", releaseVersion)
from(layout.projectDirectory.file("LICENSE"))
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()) }
}
from(layout.projectDirectory.dir("components/scripts/gradle")) {
include("gradle-init-scripts/**")
into("lib/")
}
from(layout.projectDirectory.dir("components/scripts")) {
include("README.md")
include("mapping.example")
include("network.settings")
include("lib/**")
exclude("lib/cli-parsers")
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
}
from(generateBashCliParsers.map { it.outputDir.file("lib/cli-parsers/gradle") }) {
into("lib/")
}
from(commonComponents) {
into("lib/build-scan-clients/")
}
into(layout.buildDirectory.dir("scripts/gradle"))
}
val copyMavenScripts by tasks.registering(Copy::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
inputs.property("project.version", releaseVersion)
from(layout.projectDirectory.file("LICENSE"))
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()) }
}
from(layout.projectDirectory.dir("components/scripts/")) {
include("README.md")
include("mapping.example")
include("network.settings")
include("lib/**")
exclude("lib/cli-parsers")
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
}
from(generateBashCliParsers.map { it.outputDir.file("lib/cli-parsers/maven") }) {
into("lib/")
}
from(commonComponents) {
into("lib/build-scan-clients/")
}
from(mavenComponents) {
into("lib/maven-libs/")
}
into(layout.buildDirectory.dir("scripts/maven"))
}
val assembleGradleScripts 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(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("gradle-enterprise-maven-build-validation")
archiveFileName.set(archiveBaseName.flatMap { a -> distributionVersion.map { v -> "$a-$v.zip" } })
from(copyMavenScripts)
into(archiveBaseName.get())
}
tasks.assemble {
dependsOn(assembleGradleScripts, assembleMavenScripts)
}
val consumableGradleScripts by configurations.creating {
isCanBeConsumed = true
isCanBeResolved = false
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named("gradle-build-validation-scripts"))
}
val consumableMavenScripts by configurations.creating {
isCanBeConsumed = true
isCanBeResolved = false
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named("maven-build-validation-scripts"))
}
artifacts {
add(consumableGradleScripts.name, assembleGradleScripts)
add(consumableMavenScripts.name, assembleMavenScripts)
}
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/ are checked when Shellcheck checks the top-level scripts because the top-level scripts include (source) the scripts in lib/
exclude("lib/")
}
// 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/ are checked when Shellcheck checks the top-level scripts because the top-level scripts include (source) the scripts in lib/
exclude("lib/")
}
// 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)
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("gradle-enterprise-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, 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() }
}