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 19, 2023
1 parent abe246d commit 81ef0a3
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 59 deletions.
85 changes: 52 additions & 33 deletions .github/workflows/branches-and-prs.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:0.41.0")

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 @@ -75,6 +76,24 @@ workflow(

val variants = listOf("2.5", "3.0", "4.0")
val javaVersions = listOf("8", "11", "17")
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()
)
}
job(
id = "build-and-verify",
name = "Build and Verify",
Expand All @@ -86,24 +105,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 All @@ -124,22 +127,38 @@ workflow(
val SPOCK_BUILD_CACHE_USERNAME by Contexts.secrets
val SPOCK_BUILD_CACHE_PASSWORD by Contexts.secrets
val GRADLE_ENTERPRISE_ACCESS_KEY by Contexts.secrets
// uses(
// name = "Build Spock",
// action = GradleBuildActionV2(
// arguments = listOf(
// "--no-parallel",
// "--stacktrace",
// "ghActionsBuild",
// """"-Dvariant=${expr("matrix.variant")}"""",
// """"-DjavaVersion=${expr("matrix.java")}""""
// ).joinToString(" ")
// ),
// // secrets are not injected for pull requests
// env = linkedMapOf(
// "ORG_GRADLE_PROJECT_spockBuildCacheUsername" to expr(SPOCK_BUILD_CACHE_USERNAME),
// "ORG_GRADLE_PROJECT_spockBuildCachePassword" to expr(SPOCK_BUILD_CACHE_PASSWORD),
// "GRADLE_ENTERPRISE_ACCESS_KEY" to expr(GRADLE_ENTERPRISE_ACCESS_KEY)
// )
// )
val matrixSize = (variants.size * javaVersions.size) - matrixExcludes.size + matrixIncludes.size
uses(
name = "Build Spock",
action = GradleBuildActionV2(
arguments = listOf(
"--no-parallel",
"--stacktrace",
"ghActionsBuild",
""""-Dvariant=${expr("matrix.variant")}"""",
""""-DjavaVersion=${expr("matrix.java")}""""
).joinToString(" ")
),
// secrets are not injected for pull requests
env = linkedMapOf(
"ORG_GRADLE_PROJECT_spockBuildCacheUsername" to expr(SPOCK_BUILD_CACHE_USERNAME),
"ORG_GRADLE_PROJECT_spockBuildCachePassword" to expr(SPOCK_BUILD_CACHE_PASSWORD),
"GRADLE_ENTERPRISE_ACCESS_KEY" to expr(GRADLE_ENTERPRISE_ACCESS_KEY)
name = "Update after_n_builds in codecov.yml",
action = GithubScriptV6(
script = """
let fs = require('fs');
core.notice('determined matrix size: $matrixSize')
let codecovYml = fs.readFileSync('codecov.yml', 'utf8')
core.notice('codecovYml before: ' + codecovYml)
codecovYml = codecovYml.replace('after_n_builds:', 'after_n_builds:: $matrixSize')
core.notice('codecovYml between: ' + codecovYml)
fs.writeFileSync('codecov.yml', codecovYml)
core.notice('codecovYml after: ' + fs.readFileSync('codecov.yml'))
""".trimIndent()
)
)
uses(
Expand Down
18 changes: 11 additions & 7 deletions .github/workflows/branches-and-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ jobs:
with:
additional-java-version: ${{ matrix.java }}
- id: step-2
name: Build Spock
uses: gradle/gradle-build-action@v2
name: Update after_n_builds in codecov.yml
uses: actions/github-script@v6
with:
arguments: --no-parallel --stacktrace ghActionsBuild "-Dvariant=${{ matrix.variant }}" "-DjavaVersion=${{ matrix.java }}"
env:
ORG_GRADLE_PROJECT_spockBuildCacheUsername: ${{ secrets.SPOCK_BUILD_CACHE_USERNAME }}
ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }}
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
script: |-
let fs = require('fs');
core.notice('determined matrix size: 14')
let codecovYml = fs.readFileSync('codecov.yml', 'utf8')
core.notice('codecovYml before: ' + codecovYml)
codecovYml = codecovYml.replace('after_n_builds:', 'after_n_builds:: 14')
core.notice('codecovYml between: ' + codecovYml)
fs.writeFileSync('codecov.yml', codecovYml)
core.notice('codecovYml after: ' + fs.readFileSync('codecov.yml'))
- id: step-3
name: Upload to Codecov.io
uses: codecov/codecov-action@v3
Expand Down
51 changes: 33 additions & 18 deletions .github/workflows/release.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

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 @@ -53,6 +54,24 @@ workflow(

val variants = listOf("2.5", "3.0", "4.0")
val javaVersions = listOf("8", "11", "17")
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 buildAndVerify = job(
id = "build-and-verify",
name = "Build and Verify",
Expand All @@ -65,24 +84,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 Expand Up @@ -122,6 +125,18 @@ workflow(
name = "Stop Daemon",
command = "./gradlew --stop"
)
val matrixSize = (variants.size * javaVersions.size) - matrixExcludes.size + matrixIncludes.size
uses(
name = "Update after_n_builds in codecov.yml",
action = GithubScriptV6(
script = """
let fs = require('fs');
let codecovYml = fs.readFileSync('codecov.yml')
codecovYml = codecovYml.replace('after_n_builds:', 'after_n_builds: $matrixSize')
fs.writeFileSync('codecov.yml', codecovYml)
""".trimIndent()
)
)
uses(
name = "Upload to Codecov.io",
action = CodecovActionV3(
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ jobs:
name: Stop Daemon
run: ./gradlew --stop
- id: step-4
name: Update after_n_builds in codecov.yml
uses: actions/github-script@v6
with:
script: |-
let fs = require('fs');
let codecovYml = fs.readFileSync('codecov.yml')
codecovYml = codecovYml.replace('after_n_builds:', 'after_n_builds: 14')
fs.writeFileSync('codecov.yml', codecovYml)
- id: step-5
name: Upload to Codecov.io
uses: codecov/codecov-action@v3
with:
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: 14
after_n_builds:

0 comments on commit 81ef0a3

Please sign in to comment.