Skip to content

Commit

Permalink
Merge pull request #1956 from pinterest/publication-logging3
Browse files Browse the repository at this point in the history
Add --no-build-cache to release workflow + refactor + add additional logging
  • Loading branch information
paul-dingemans authored Apr 20, 2023
2 parents 9942a0e + 952c8b6 commit 180127f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
gradle-home-cache-cleanup: true
- name: Build executable and publish to Maven
run: ./gradlew clean shadowJarExecutable publishMavenPublicationToMavenCentralRepository --no-daemon --no-parallel --no-configuration-cache
run: ./gradlew clean shadowJarExecutable publishMavenPublicationToMavenCentralRepository --no-daemon --no-parallel --no-configuration-cache --no-build-cache
env:
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
Expand Down
3 changes: 3 additions & 0 deletions build-logic/src/main/kotlin/ktlint-publication.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ signing {

// This property allows OS package maintainers to disable signing
val enableSigning = providers.gradleProperty("ktlint.publication.signing.enable").orNull != "false"

logger.lifecycle("Before sign in ktlint-publication: ${publishing.publications["maven"]}")
sign(publishing.publications["maven"])
logger.lifecycle("After sign in ktlint-publication: ${publishing.publications["maven"]}")
isRequired = enableSigning && !version.toString().endsWith("SNAPSHOT")
}

Expand Down
7 changes: 6 additions & 1 deletion ktlint-bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ val excludeList =
)

dependencies {
logger.lifecycle("Creating dependencies for ktlint-bom")
constraints {
project.rootProject.subprojects.forEach { subproject ->
if (subproject.name !in excludeList) {
if (subproject.name in excludeList) {
logger.lifecycle("Ignore dependency on $subproject")
} else {
logger.lifecycle("Add api dependency on $subproject to ktlint-bom")
api(subproject)
}
}
}
logger.lifecycle("Finished creating dependencies for ktlint-bom")
}
103 changes: 57 additions & 46 deletions ktlint-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,53 @@ val shadowJarExecutable by tasks.registering(DefaultTask::class) {
description = "Creates self-executable file, that runs generated shadow jar"
group = "Distribution"

inputs.files(
dependsOn(tasks.shadowJar)

// Find the "ktlint-cli-<version>-all.jar" file
val ktlintCliAllJarFile =
tasks
.shadowJar
.also { logger.lifecycle("Set input files on shadowJarExecutable:") }
.map {
it
.outputs
.also { logger.lifecycle("TasksOutputInternal contains ${it.files.count()} fileCollections") }
.files
.also { logger.lifecycle(it.joinToString(prefix = "Files [${it.asPath}]: ", separator = ", ") { it.path }) }
},
)
outputs.files("$buildDir/run/ktlint")
.orNull
?.outputs
?.files
?.singleFile
?: throw GradleException("Can not locate the jar file for building the self-executable ktlint-cli")
logger.lifecycle("ktlint-cli: Base jar to build self-executable file: ${ktlintCliAllJarFile.absolutePath}")
inputs.files(ktlintCliAllJarFile)

// Output is the self-executable file
val selfExecutableKtlintPath = "$buildDir/run/ktlint"
outputs.files(selfExecutableKtlintPath)
if (!version.toString().endsWith("SNAPSHOT")) {
// And for releases also the signature file
outputs.files("$buildDir/run/ktlint.asc")
}

doLast {
val execFile = outputs.files.first()
execFile.appendText(
"""
#!/bin/sh
logger.lifecycle("Creating the self-executable ktlint-cli")
File(selfExecutableKtlintPath).apply {
appendText(
"""
#!/bin/sh
# From this SO answer: https://stackoverflow.com/a/56243046
# From this SO answer: https://stackoverflow.com/a/56243046
# First we get the major Java version as an integer, e.g. 8, 11, 16. It has special handling for the leading 1 of older java
# versions, e.g. 1.8 = Java 8
JV=$(java -version 2>&1 | sed -E -n 's/.* version "([^.-]*).*".*/\1/p')
# First we get the major Java version as an integer, e.g. 8, 11, 16. It has special handling for the leading 1 of older java
# versions, e.g. 1.8 = Java 8
JV=$(java -version 2>&1 | sed -E -n 's/.* version "([^.-]*).*".*/\1/p')
# Add --add-opens for java version 16 and above
X=$( [ "${"$"}JV" -ge "16" ] && echo "--add-opens java.base/java.lang=ALL-UNNAMED" || echo "")
# Add --add-opens for java version 16 and above
X=$( [ "${"$"}JV" -ge "16" ] && echo "--add-opens java.base/java.lang=ALL-UNNAMED" || echo "")
exec java ${"$"}X -Xmx512m -jar "$0" "$@"
exec java ${"$"}X -Xmx512m -jar "$0" "$@"
""".trimIndent(),
)
""".trimIndent(),
)

execFile.appendBytes(inputs.files.singleFile.readBytes())
execFile.setExecutable(true, false)
appendBytes(ktlintCliAllJarFile.readBytes())
setExecutable(true, false)
}
logger.lifecycle("Finished creating the self-executable ktlint-cli")
}
}

Expand All @@ -97,19 +105,22 @@ tasks.register<Checksum>("shadowJarExecutableChecksum") {
// put the checksums in the same folder with the executable itself
outputDirectory.fileProvider(
shadowJarExecutable
.also { logger.lifecycle("Set output files on shadowJarExecutableChecksum:") }
.also { logger.lifecycle("registerChecksum - Set output files on shadowJarExecutableChecksum:") }
.map {
it
.outputs
.also { logger.lifecycle("TasksOutputInternal contains ${it.files.count()} fileCollections") }
.also { logger.lifecycle("registerChecksum - TasksOutputInternal contains ${it.files.count()} fileCollections") }
.files
.also { logger.lifecycle(it.joinToString(prefix = "Files [${it.asPath}]: ", separator = ", ") { it.path }) }
.files
.also { logger.lifecycle("File set contains ${it.count()} files") }
.also {
logger.lifecycle(
it.joinToString(prefix = "registerChecksum - Files [${it.asPath}]: ", separator = ", ") { it.path },
)
}.files
.also { logger.lifecycle("registerChecksum - File set contains ${it.count()} files") }
.first()
.also { logger.lifecycle("First file: ${it.path}") }
.also { logger.lifecycle("registerChecksum - First file: ${it.path}") }
.parentFile
.also { logger.lifecycle("Parent file: ${it.path}") }
.also { logger.lifecycle("registerChecksum - Parent file: ${it.path}") }
},
)
checksumAlgorithm.set(Checksum.Algorithm.MD5)
Expand All @@ -119,20 +130,20 @@ tasks.signMavenPublication {
dependsOn(shadowJarExecutable)
if (!version.toString().endsWith("SNAPSHOT")) {
// Just need to sign execFile.
sign(
val ktlintSelfExecutable =
shadowJarExecutable
.also { logger.lifecycle("Signing:") }
.map {
it
.outputs
.also { logger.lifecycle("TasksOutputInternal contains ${it.files.count()} fileCollections") }
.files
.also { logger.lifecycle(it.joinToString(prefix = "Files [${it.asPath}]: ", separator = ", ") { it.path }) }
.first()
.also { logger.lifecycle("First file: ${it.path}") }
}.get()
.also { logger.lifecycle("Result file to sign: ${it.path}") },
)
.orNull
?.outputs
?.files
?.files
?.filterNot {
// Ignore the signature file
it.path.endsWith(".asc")
}?.single()
?: throw GradleException("Can not locate the self-executable ktlint-cli to be signed")
logger.lifecycle("Before sign of ${ktlintSelfExecutable.path} in signMavenPublication")
sign(ktlintSelfExecutable)
logger.lifecycle("After sign of ${ktlintSelfExecutable.path} in signMavenPublication")
}
}

Expand Down

0 comments on commit 180127f

Please sign in to comment.