Skip to content

Commit

Permalink
Update after_n_builds in codecov.yml dynamically from matrix size
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Aug 12, 2024
1 parent 9de2ede commit c3a6678
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/branches-and-prs.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@ workflow(
)
}

val matrix = Matrix.full
with(__FILE__.parentFile.resolve("../../codecov.yml")) {
readText()
.replace("after_n_builds:.*+$".toRegex(), "after_n_builds: ${matrix.size}")
.let(::writeText)
}
job(
id = "build-and-verify",
name = "Build and Verify",
runsOn = RunnerType.Custom(expr(Matrix.operatingSystem)),
strategy = Strategy(
matrix = Matrix.full
matrix = matrix
)
) {
uses(
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/common.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ data class Matrix(
val exclude: (Element.() -> Boolean)? = null,
val includes: List<Element>? = null
) {
val size by lazy {
originalElements
.filterNot(exclude ?: { true })
.size +
(includes?.size ?: 0)
}

private val originalElements by lazy {
(operatingSystems ?: listOf(null))
.map { Element(operatingSystem = it) }
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/release.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ workflow(
val SONATYPE_OSS_PASSWORD by secrets
val SIGNING_GPG_PASSWORD by secrets

val matrix = Matrix.full
with(__FILE__.parentFile.resolve("../../codecov.yml")) {
readText()
.replace("after_n_builds:.*+$".toRegex(), "after_n_builds: ${matrix.size}")
.let(::writeText)
}
val buildAndVerify = job(
id = "build-and-verify",
name = "Build and Verify",
runsOn = RunnerType.Custom(expr(Matrix.operatingSystem)),
condition = "${github.repository} == 'spockframework/spock'",
strategy = Strategy(
matrix = Matrix.full
matrix = matrix
)
) {
uses(
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ codecov:

comment:
layout: "reach, diff, flags, files"
after_n_builds: 16
after_n_builds: 18

0 comments on commit c3a6678

Please sign in to comment.