From d3e9eb1a42cc1d9a2c2725a0366dc671a6995bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kautler?= Date: Wed, 19 Apr 2023 02:03:08 +0200 Subject: [PATCH] Update after_n_builds in codecov.yml dynamically from matrix size --- .github/workflows/branches-and-prs.main.kts | 8 +++++++- .github/workflows/common.main.kts | 7 +++++++ .github/workflows/release.main.kts | 8 +++++++- codecov.yml | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/branches-and-prs.main.kts b/.github/workflows/branches-and-prs.main.kts index 0c3cb0608e..ab96a21d39 100755 --- a/.github/workflows/branches-and-prs.main.kts +++ b/.github/workflows/branches-and-prs.main.kts @@ -69,12 +69,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( diff --git a/.github/workflows/common.main.kts b/.github/workflows/common.main.kts index 6bbb90052d..e3d775f8de 100755 --- a/.github/workflows/common.main.kts +++ b/.github/workflows/common.main.kts @@ -55,6 +55,13 @@ data class Matrix( val exclude: (Element.() -> Boolean)? = null, val includes: List? = 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) } diff --git a/.github/workflows/release.main.kts b/.github/workflows/release.main.kts index 94c4b200e9..decac21791 100755 --- a/.github/workflows/release.main.kts +++ b/.github/workflows/release.main.kts @@ -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( diff --git a/codecov.yml b/codecov.yml index 250c97597b..599046d6e8 100644 --- a/codecov.yml +++ b/codecov.yml @@ -3,4 +3,4 @@ codecov: comment: layout: "reach, diff, flags, files" - after_n_builds: 16 + after_n_builds: 18