Skip to content

Commit

Permalink
Improve Codecov settings (#1629)
Browse files Browse the repository at this point in the history
- Fail the CI build if the Codecov uploading failed.
- Show more detailed information in the Codecov comment.
- Do not update the Codecov comment 13 times, but post it after all 14
reports were uploaded.
- Ignore dates in coverage reports to not get "upload expired" because
the report was taken from remote build cache.
  • Loading branch information
Vampire authored Dec 28, 2024
1 parent 0a4b151 commit 230ad60
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 18 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/branches-and-prs.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ workflow(
MergeGroup()
),
sourceFile = __FILE__,
targetFileName = "${__FILE__.name.substringBeforeLast(".main.kts")}.yml",
// https://stackoverflow.com/a/72408109/16358266
concurrency = Concurrency(
group = "${expr { github.workflow }}-${expr("${github.eventPullRequest.pull_request.number} || ${github.ref}")}",
Expand Down Expand Up @@ -76,12 +75,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 Expand Up @@ -111,7 +116,9 @@ workflow(
)
uses(
name = "Upload to Codecov.io",
action = CodecovAction()
action = CodecovAction(
failCiIfError = true
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
uses: 'actions/checkout@v4'
- id: 'step-1'
name: 'Execute script'
run: 'rm ''.github/workflows/branches-and-prs.yml'' && ''.github/workflows/branches-and-prs.main.kts'''
run: 'rm ''.github/workflows/branches-and-prs.yaml'' && ''.github/workflows/branches-and-prs.main.kts'''
- id: 'step-2'
name: 'Consistency check'
run: 'git diff --exit-code ''.github/workflows/branches-and-prs.yml'''
run: 'git diff --exit-code ''.github/workflows/branches-and-prs.yaml'''
check_all_workflow_yaml_consistency:
name: 'Check all Workflow YAML Consistency'
runs-on: 'ubuntu-latest'
Expand Down Expand Up @@ -112,3 +112,5 @@ jobs:
- id: 'step-3'
name: 'Upload to Codecov.io'
uses: 'codecov/codecov-action@v5'
with:
fail_ci_if_error: 'true'
1 change: 0 additions & 1 deletion .github/workflows/codeql-analysis.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ workflow(
)
),
sourceFile = __FILE__,
targetFileName = "${__FILE__.name.substringBeforeLast(".main.kts")}.yml",
// https://stackoverflow.com/a/72408109/16358266
concurrency = Concurrency(
group = "${expr { github.workflow }}-${expr("${github.eventPullRequest.pull_request.number} || ${github.ref}")}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
uses: 'actions/checkout@v4'
- id: 'step-1'
name: 'Execute script'
run: 'rm ''.github/workflows/codeql-analysis.yml'' && ''.github/workflows/codeql-analysis.main.kts'''
run: 'rm ''.github/workflows/codeql-analysis.yaml'' && ''.github/workflows/codeql-analysis.main.kts'''
- id: 'step-2'
name: 'Consistency check'
run: 'git diff --exit-code ''.github/workflows/codeql-analysis.yml'''
run: 'git diff --exit-code ''.github/workflows/codeql-analysis.yaml'''
codeql-build:
name: 'CodeQL-Build'
runs-on: 'ubuntu-latest'
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
1 change: 0 additions & 1 deletion .github/workflows/docs-pr.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ workflow(
MergeGroup()
),
sourceFile = __FILE__,
targetFileName = "${__FILE__.name.substringBeforeLast(".main.kts")}.yml",
// https://stackoverflow.com/a/72408109/16358266
concurrency = Concurrency(
group = "${expr { github.workflow }}-${expr("${github.eventPullRequest.pull_request.number} || ${github.ref}")}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
uses: 'actions/checkout@v4'
- id: 'step-1'
name: 'Execute script'
run: 'rm ''.github/workflows/docs-pr.yml'' && ''.github/workflows/docs-pr.main.kts'''
run: 'rm ''.github/workflows/docs-pr.yaml'' && ''.github/workflows/docs-pr.main.kts'''
- id: 'step-2'
name: 'Consistency check'
run: 'git diff --exit-code ''.github/workflows/docs-pr.yml'''
run: 'git diff --exit-code ''.github/workflows/docs-pr.yaml'''
docs-and-javadoc:
name: 'Docs and JavaDoc'
runs-on: 'ubuntu-latest'
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/release.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,26 @@ workflow(
tags = listOf("spock-*")
)
),
sourceFile = __FILE__,
targetFileName = "${__FILE__.name.substringBeforeLast(".main.kts")}.yml"
sourceFile = __FILE__
) {
val GITHUB_TOKEN by secrets
val SONATYPE_OSS_USER by secrets
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 Expand Up @@ -87,7 +92,9 @@ workflow(
)
uses(
name = "Upload to Codecov.io",
action = CodecovAction()
action = CodecovAction(
failCiIfError = true
)
)
}
val releaseSpock = job(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
uses: 'actions/checkout@v4'
- id: 'step-1'
name: 'Execute script'
run: 'rm ''.github/workflows/release.yml'' && ''.github/workflows/release.main.kts'''
run: 'rm ''.github/workflows/release.yaml'' && ''.github/workflows/release.main.kts'''
- id: 'step-2'
name: 'Consistency check'
run: 'git diff --exit-code ''.github/workflows/release.yml'''
run: 'git diff --exit-code ''.github/workflows/release.yaml'''
build-and-verify:
name: 'Build and Verify'
runs-on: '${{ matrix.os }}'
Expand Down Expand Up @@ -95,6 +95,8 @@ jobs:
- id: 'step-4'
name: 'Upload to Codecov.io'
uses: 'codecov/codecov-action@v5'
with:
fail_ci_if_error: 'true'
release-spock:
name: 'Release Spock'
runs-on: '${{ matrix.os }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PreprocessWorkflowsPlugin implements Plugin<Project> {
.files(getImportedFiles(project.file(workflowScript)))
.withPropertyName("importedFiles")
it.outputs
.file(new File(workflowScript.parent, "${workflowName}.yml"))
.file(new File(workflowScript.parent, "${workflowName}.yaml"))
.withPropertyName('workflowFile')

it.javaLauncher.set project.extensions.getByType(JavaToolchainService).launcherFor {
Expand Down
6 changes: 6 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
codecov:
max_report_age: off

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

0 comments on commit 230ad60

Please sign in to comment.