Skip to content

Reading of the release version and description is configuration cache compatible #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 35 additions & 31 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ repositories {
mavenCentral()
}

val appVersion = layout.projectDirectory.file("release/version.txt").asFile.readText().trim()
val releaseVersion = releaseVersion()
val releaseNotes = releaseNotes()

allprojects {
version = appVersion
version = releaseVersion.get()
}

val argbash by configurations.creating
Expand Down Expand Up @@ -93,16 +95,18 @@ val copyGradleScripts by tasks.registering(Copy::class) {
group = "build"
description = "Copies the Gradle source and generated scripts to output directory."

val projectVersion = appVersion // local variable required for configuration cache compatibility
inputs.property("project.version", projectVersion)
// 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>", projectVersion) }
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
}
from(layout.projectDirectory.dir("components/scripts/gradle")) {
include("gradle-init-scripts/**")
Expand All @@ -114,7 +118,7 @@ val copyGradleScripts by tasks.registering(Copy::class) {
include("network.settings")
include("lib/**")
exclude("lib/cli-parsers")
filter { line: String -> line.replace("<HEAD>", projectVersion) }
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
}
from(generateBashCliParsers.map { it.outputDir.file("lib/cli-parsers/gradle") }) {
into("lib/")
Expand All @@ -129,23 +133,25 @@ val copyMavenScripts by tasks.registering(Copy::class) {
group = "build"
description = "Copies the Maven source and generated scripts to output directory."

val projectVersion = appVersion // local variable required for configuration cache compatibility
inputs.property("project.version", projectVersion)
// 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>", projectVersion) }
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>", projectVersion) }
filter { line: String -> line.replace("<HEAD>", releaseVersion.get()) }
}
from(generateBashCliParsers.map { it.outputDir.file("lib/cli-parsers/maven") }) {
into("lib/")
Expand All @@ -169,7 +175,7 @@ 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.get()}-${distributionVersion()}.zip")
archiveFileName.set("${archiveBaseName.get()}-${distributionVersion().get()}.zip")
from(copyGradleScripts)
into(archiveBaseName.get())
}
Expand All @@ -178,7 +184,7 @@ 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.get()}-${distributionVersion()}.zip")
archiveFileName.set("${archiveBaseName.get()}-${distributionVersion().get()}.zip")
from(copyMavenScripts)
into(archiveBaseName.get())
}
Expand Down Expand Up @@ -253,7 +259,7 @@ githubRelease {
prerelease.set(isDevelopmentRelease)
overwrite.set(isDevelopmentRelease)
generateReleaseNotes.set(false)
body.set(layout.projectDirectory.file("release/changes.md").asFile.readText().trim())
body.set(releaseNotes)
releaseAssets(assembleGradleScripts, assembleMavenScripts, generateChecksums.map { it.outputs.files.asFileTree })
}

Expand All @@ -272,26 +278,24 @@ tasks.withType(Sign::class).configureEach {
notCompatibleWithConfigurationCache("$name task does not support configuration caching")
}

fun gitHubReleaseName(): String {
if (isDevelopmentRelease) {
return "Development Build"
} else {
return version.toString()
}
fun gitHubReleaseName(): Provider<String> {
return releaseVersion.map { if (isDevelopmentRelease) "Development release" else it }
}

fun gitReleaseTag(): String {
if (isDevelopmentRelease) {
return "development-latest"
} else {
return "v${version}"
}
fun gitReleaseTag(): Provider<String> {
return releaseVersion.map { if (isDevelopmentRelease) "development-latest" else "v$it" }
}

fun distributionVersion(): String {
if (isDevelopmentRelease) {
return "dev"
} else {
return version.toString()
}
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() }
}