Skip to content

Commit fdbdce7

Browse files
authored
Make the preprocessing tasks for workflow files cacheable (#2157)
1 parent 5d220ca commit fdbdce7

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

.github/workflows/branches-and-prs.main.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ workflow(
8484
with(__FILE__.parentFile.resolve("../codecov.yml")) {
8585
readText()
8686
.replace("after_n_builds:.*+$".toRegex(), "after_n_builds: ${matrix.size}")
87-
.let(::writeText)
87+
.let {
88+
parentFile
89+
.resolve("../build/")
90+
.apply { mkdirs() }
91+
.resolve("codecov_branches-and-prs.yml")
92+
.writeText(it)
93+
}
8894
}
8995
job(
9096
id = "build-and-verify",

.github/workflows/release.main.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ workflow(
5555
with(__FILE__.parentFile.resolve("../codecov.yml")) {
5656
readText()
5757
.replace("after_n_builds:.*+$".toRegex(), "after_n_builds: ${matrix.size}")
58-
.let(::writeText)
58+
.let {
59+
parentFile
60+
.resolve("../build/")
61+
.apply { mkdirs() }
62+
.resolve("codecov_release.yml")
63+
.writeText(it)
64+
}
5965
}
6066
val buildAndVerify = job(
6167
id = "build-and-verify",

build-logic/preprocess-workflows/src/main/groovy/org/spockframework/gradle/PreprocessGithubWorkflow.groovy

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,28 @@ import org.gradle.api.provider.Property
88
import org.gradle.api.provider.Provider
99
import org.gradle.api.tasks.*
1010
import org.gradle.jvm.toolchain.JavaLauncher
11+
import org.gradle.work.NormalizeLineEndings
1112
import org.gradle.workers.WorkerExecutor
1213

1314
import javax.inject.Inject
1415

1516
@CompileStatic
17+
@CacheableTask
1618
abstract class PreprocessGithubWorkflow extends DefaultTask {
1719
@InputFile
20+
@NormalizeLineEndings
21+
@PathSensitive(PathSensitivity.RELATIVE)
1822
abstract RegularFileProperty getWorkflowScript()
1923

2024
@InputFiles
25+
@NormalizeLineEndings
26+
@PathSensitive(PathSensitivity.RELATIVE)
2127
abstract ConfigurableFileCollection getImportedFiles()
2228

23-
@InputFiles
29+
@Classpath
2430
abstract ConfigurableFileCollection getKotlinCompilerClasspath()
2531

26-
@InputFiles
32+
@Classpath
2733
abstract ConfigurableFileCollection getMainKtsClasspath()
2834

2935
@Nested

build-logic/preprocess-workflows/src/main/groovy/org/spockframework/gradle/PreprocessWorkflowsPlugin.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import groovy.transform.CompileStatic
2020
import org.gradle.api.Plugin
2121
import org.gradle.api.Project
2222
import org.gradle.api.artifacts.VersionCatalogsExtension
23+
import org.gradle.api.tasks.Delete
2324
import org.gradle.jvm.toolchain.JavaLanguageVersion
2425
import org.gradle.jvm.toolchain.JavaToolchainService
2526

@@ -62,6 +63,12 @@ class PreprocessWorkflowsPlugin implements Plugin<Project> {
6263
it.languageVersion.set(JavaLanguageVersion.of(17))
6364
})
6465
}
66+
def deleteWorkflowYaml = project.tasks.register("delete${pascalCasedWorkflowName}WorkflowYaml", Delete) {
67+
it.delete(preprocessWorkflow.flatMap { it.workflowFile })
68+
}
69+
preprocessWorkflow.configure {
70+
it.dependsOn(deleteWorkflowYaml)
71+
}
6572
project.pluginManager.withPlugin('io.spring.nohttp') {
6673
// iff both tasks are run, workflow files should be generated before checkstyle check
6774
project.tasks.named('checkstyleNohttp') {

build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,40 @@ def configureGroovydoc(TaskProvider groovydoc) {
404404
include "spock/**"
405405
}
406406
}
407+
408+
def preprocessBranchesAndPrsWorkflowCodecovOutput = layout.buildDirectory.file('codecov_branches-and-prs.yml')
409+
def preprocessReleaseWorkflowCodecovOutput = layout.buildDirectory.file('codecov_release.yml')
410+
411+
def copyCodecovConfig = tasks.register('copyCodecovConfig') {
412+
doLast {
413+
copy {
414+
from(
415+
[
416+
preprocessBranchesAndPrsWorkflowCodecovOutput,
417+
preprocessReleaseWorkflowCodecovOutput
418+
].max {it.get().asFile.lastModified() })
419+
into('.github')
420+
rename { 'codecov.yml' }
421+
}
422+
}
423+
}
424+
425+
tasks.preprocessBranchesAndPrsWorkflow {
426+
inputs
427+
.file('.github/codecov.yml')
428+
.normalizeLineEndings()
429+
.withPathSensitivity(PathSensitivity.RELATIVE)
430+
.withPropertyName('codecovConfig')
431+
outputs.file(preprocessBranchesAndPrsWorkflowCodecovOutput).withPropertyName('codecovConfig')
432+
finalizedBy(copyCodecovConfig)
433+
}
434+
435+
tasks.preprocessReleaseWorkflow {
436+
inputs
437+
.file('.github/codecov.yml')
438+
.normalizeLineEndings()
439+
.withPathSensitivity(PathSensitivity.RELATIVE)
440+
.withPropertyName('codecovConfig')
441+
outputs.file(preprocessReleaseWorkflowCodecovOutput).withPropertyName('codecovConfig')
442+
finalizedBy(copyCodecovConfig)
443+
}

0 commit comments

Comments
 (0)