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 c060507
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 37 deletions.
51 changes: 33 additions & 18 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 Down Expand Up @@ -142,6 +145,18 @@ workflow(
"GRADLE_ENTERPRISE_ACCESS_KEY" to expr(GRADLE_ENTERPRISE_ACCESS_KEY)
)
)
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', 'utf8')
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/branches-and-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ jobs:
ORG_GRADLE_PROJECT_spockBuildCachePassword: ${{ secrets.SPOCK_BUILD_CACHE_PASSWORD }}
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
- id: step-3
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', 'utf8')
codecovYml = codecovYml.replace('after_n_builds:', 'after_n_builds: 14')
fs.writeFileSync('codecov.yml', codecovYml)
- id: step-4
name: Upload to Codecov.io
uses: codecov/codecov-action@v3
with:
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', 'utf8')
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', 'utf8')
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 c060507

Please sign in to comment.