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 Apr 28, 2023
1 parent ee3b470 commit af58edc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 36 deletions.
45 changes: 27 additions & 18 deletions .github/workflows/branches-and-prs.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import groovy.lang.Binding
import groovy.lang.GroovyShell
import io.github.typesafegithub.workflows.actions.actions.CheckoutV3
import io.github.typesafegithub.workflows.actions.actions.GithubScriptV6
import io.github.typesafegithub.workflows.actions.codecov.CodecovActionV3
import io.github.typesafegithub.workflows.actions.gradle.GradleBuildActionV2
import io.github.typesafegithub.workflows.domain.Concurrency
Expand Down Expand Up @@ -73,6 +74,30 @@ workflow(
}

val (javaVersions, variants) = getMatrixAxes()
val matrixExcludes = javaVersions
.filter { it.toInt() >= 17 }
.map { javaVersion ->
mapOf(
"os" to "ubuntu-latest",
"variant" to "2.5",
"java" to javaVersion
)
}
val matrixIncludes = listOf("windows-latest", "macos-latest")
.flatMap { os -> variants.map { os to it } }
.map { (os, variant) ->
mapOf(
"os" to os,
"variant" to variant,
"java" to javaVersions.first()
)
}
val matrixSize = (variants.size * javaVersions.size) - matrixExcludes.size + matrixIncludes.size
with(__FILE__.parentFile.resolve("../../codecov.yml")) {
readText()
.replace("after_n_builds:.*+$".toRegex(), "after_n_builds: $matrixSize")
.let(::writeText)
}
job(
id = "build-and-verify",
name = "Build and Verify",
Expand All @@ -84,24 +109,8 @@ workflow(
"os" to listOf("ubuntu-latest"),
"variant" to variants,
"java" to javaVersions,
"exclude" to javaVersions
.filter { it.toInt() >= 17 }
.map { javaVersion ->
mapOf(
"os" to "ubuntu-latest",
"variant" to "2.5",
"java" to javaVersion
)
},
"include" to listOf("windows-latest", "macos-latest")
.flatMap { os -> variants.map { os to it } }
.map { (os, variant) ->
mapOf(
"os" to os,
"variant" to variant,
"java" to javaVersions.first()
)
}
"exclude" to matrixExcludes,
"include" to matrixIncludes
)
)
)
Expand Down
45 changes: 27 additions & 18 deletions .github/workflows/release.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import groovy.lang.Binding
import groovy.lang.GroovyShell
import io.github.typesafegithub.workflows.actions.actions.CheckoutV3
import io.github.typesafegithub.workflows.actions.actions.CheckoutV3.FetchDepth
import io.github.typesafegithub.workflows.actions.actions.GithubScriptV6
import io.github.typesafegithub.workflows.actions.codecov.CodecovActionV3
import io.github.typesafegithub.workflows.actions.gradle.GradleBuildActionV2
import io.github.typesafegithub.workflows.domain.RunnerType
Expand Down Expand Up @@ -55,6 +56,30 @@ workflow(
val GRADLE_ENTERPRISE_ACCESS_KEY by Contexts.secrets

val (javaVersions, variants) = getMatrixAxes()
val matrixExcludes = javaVersions
.filter { it.toInt() >= 17 }
.map { javaVersion ->
mapOf(
"os" to "ubuntu-latest",
"variant" to "2.5",
"java" to javaVersion
)
}
val matrixIncludes = listOf("windows-latest", "macos-latest")
.flatMap { os -> variants.map { os to it } }
.map { (os, variant) ->
mapOf(
"os" to os,
"variant" to variant,
"java" to javaVersions.first()
)
}
val matrixSize = (variants.size * javaVersions.size) - matrixExcludes.size + matrixIncludes.size
with(__FILE__.parentFile.resolve("../../codecov.yml")) {
readText()
.replace("after_n_builds:.*+$".toRegex(), "after_n_builds: $matrixSize")
.let(::writeText)
}
val buildAndVerify = job(
id = "build-and-verify",
name = "Build and Verify",
Expand All @@ -67,24 +92,8 @@ workflow(
"os" to listOf("ubuntu-latest"),
"variant" to variants,
"java" to javaVersions,
"exclude" to javaVersions
.filter { it.toInt() >= 17 }
.map { javaVersion ->
mapOf(
"os" to "ubuntu-latest",
"variant" to "2.5",
"java" to javaVersion
)
},
"include" to listOf("windows-latest", "macos-latest")
.flatMap { os -> variants.map { os to it } }
.map { (os, variant) ->
mapOf(
"os" to os,
"variant" to variant,
"java" to javaVersions.first()
)
}
"exclude" to matrixExcludes,
"include" to matrixIncludes
)
)
)
Expand Down

0 comments on commit af58edc

Please sign in to comment.