diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 940410a56..c3141f019 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -137,6 +137,7 @@ jobs: - name: Run Unit Tests run: > ./gradlew + :build-logic:plugins:koverXmlReport :pillarbox-analytics:koverXmlReportDebug :pillarbox-cast:koverXmlReportDebug :pillarbox-core-business:koverXmlReportDebug diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1cbde9d16..8737b0b9a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,8 @@ on: push: # Pattern matched against refs/tags tags: - - '[0-9]+.[0-9].[0-9]' - - '[0-9]+.[0-9].[0-9]-[0-9a-zA-Z]+' + - '[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+-[0-9a-zA-Z]+' jobs: build: runs-on: ubuntu-latest @@ -19,7 +19,7 @@ jobs: - name: Check if pre release tag id: check-tag run: | - if [[ "${GITHUB_REF_NAME}" =~ [0-9]+.[0-9].[0-9]-[0-9a-zA-Z]+ ]]; then + if [[ "${GITHUB_REF_NAME}" =~ ^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}-[0-9a-zA-Z]+$ ]]; then echo "prerelease=true" >> $GITHUB_OUTPUT fi - name: Print release tag @@ -52,7 +52,7 @@ jobs: - name: Create Github release uses: ncipollo/release-action@v1 with: - draft: true - prerelease: steps.check-tag.outputs.prerelease == 'true' - skipIfReleaseExists: true - generateReleaseNotes: true + draft: true + prerelease: steps.check-tag.outputs.prerelease == 'true' + skipIfReleaseExists: true + generateReleaseNotes: true diff --git a/build-logic/plugins/build.gradle.kts b/build-logic/plugins/build.gradle.kts index 51ccdc43c..a9b74157b 100644 --- a/build-logic/plugins/build.gradle.kts +++ b/build-logic/plugins/build.gradle.kts @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { `kotlin-dsl` + alias(libs.plugins.kotlinx.kover) } group = "ch.srgssr.pillarbox.gradle" @@ -26,6 +27,8 @@ dependencies { compileOnly(libs.android.gradle.api) compileOnly(libs.kotlinx.kover.gradle) compileOnly(libs.kotlin.gradle.plugin) + + testImplementation(libs.kotlin.test) } tasks { diff --git a/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidApplicationPlugin.kt b/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidApplicationPlugin.kt index 878c5cd92..b73e6b091 100644 --- a/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidApplicationPlugin.kt +++ b/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidApplicationPlugin.kt @@ -35,8 +35,8 @@ class PillarboxAndroidApplicationPlugin : Plugin { defaultConfig { applicationId = namespace targetSdk = AppConfig.targetSdk - versionCode = VersionConfig.versionCode() - versionName = VersionConfig.versionName() + versionCode = VersionConfig().versionCode() + versionName = VersionConfig().versionName() vectorDrawables.useSupportLibrary = true } diff --git a/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidLibraryPublishingPlugin.kt b/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidLibraryPublishingPlugin.kt index 14dd7e60e..7da6cbd81 100644 --- a/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidLibraryPublishingPlugin.kt +++ b/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidLibraryPublishingPlugin.kt @@ -43,7 +43,7 @@ class PillarboxAndroidLibraryPublishingPlugin : Plugin { extensions.configure { defaultConfig { group = "ch.srgssr.pillarbox" - version = VersionConfig.versionName() + version = VersionConfig().versionName() } publishing { diff --git a/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/internal/VersionConfig.kt b/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/internal/VersionConfig.kt index 194224028..7f627cb68 100644 --- a/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/internal/VersionConfig.kt +++ b/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/internal/VersionConfig.kt @@ -8,21 +8,21 @@ package ch.srgssr.pillarbox.gradle.internal * VersionConfig will build * - VersionName for Pillarbox Demo * - Version for Libraries + * + * @param envVersionName Environment variable set by workflow. */ -internal object VersionConfig { - /** - * Environment variable set by workflow. - */ - private val ENV_VERSION_NAME: String? = System.getenv("VERSION_NAME") - private val versionOnlyRegex = "[0-9]+.[0-9].[0-9]".toRegex() +internal class VersionConfig( + private val envVersionName: String? = System.getenv("VERSION_NAME"), +) { + private val versionOnlyRegex = "^[0-9]{1,2}\\.[0-9]{1,2}\\.[0-9]{1,2}$".toRegex() /** * Version name * - * @return "Local" if [ENV_VERSION_NAME] no set. + * @return "Local" if [envVersionName] no set. */ internal fun versionName(): String { - return ENV_VERSION_NAME ?: "Local" + return envVersionName ?: "Local" } /** @@ -31,7 +31,7 @@ internal object VersionConfig { * 0.0.0, 0.0.99, 0.1.0, 0.99.99 */ internal fun versionCode(): Int { - return ENV_VERSION_NAME + return envVersionName ?.let { versionOnlyRegex.find(it)?.value } ?.let { val versions = it.split(".").map { value -> value.toInt() } diff --git a/build-logic/plugins/src/test/java/ch/srgssr/pillarbox/gradle/internal/VersionConfigTest.kt b/build-logic/plugins/src/test/java/ch/srgssr/pillarbox/gradle/internal/VersionConfigTest.kt new file mode 100644 index 000000000..318f4c9fd --- /dev/null +++ b/build-logic/plugins/src/test/java/ch/srgssr/pillarbox/gradle/internal/VersionConfigTest.kt @@ -0,0 +1,64 @@ +/* + * Copyright (c) SRG SSR. All rights reserved. + * License information is available from the LICENSE file. + */ +package ch.srgssr.pillarbox.gradle.internal + +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import org.junit.runners.Parameterized.Parameters +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals + +@RunWith(Parameterized::class) +class VersionConfigTest( + private val envVersionName: String?, + private val versionName: String, + private val versionCode: Int, +) { + private lateinit var versionConfig: VersionConfig + + @BeforeTest + fun setUp() { + versionConfig = VersionConfig(envVersionName) + } + + @Test + fun `version name`() { + assertEquals(versionName, versionConfig.versionName()) + } + + @Test + fun `version code`() { + assertEquals(versionCode, versionConfig.versionCode()) + } + + companion object { + @JvmStatic + @Parameters(name = "{index}: envVersionName={0}, versionName={1}, versionCode={2}") + fun parameters(): Iterable { + return listOf( + // Invalid envVersionName + arrayOf(null, "Local", 9999), + arrayOf("", "", 9999), + arrayOf("Foo", "Foo", 9999), + + // Invalid version format + arrayOf("1.2", "1.2", 9999), + arrayOf("1a2b3", "1a2b3", 9999), + arrayOf("1.2.3.4", "1.2.3.4", 9999), + arrayOf("111.2.3", "111.2.3", 9999), + arrayOf("1.222.3", "1.222.3", 9999), + arrayOf("1.2.333", "1.2.333", 9999), + + // Valid version format + arrayOf("0.0.0", "0.0.0", 0), + arrayOf("1.2.3", "1.2.3", 10203), + arrayOf("12.34.56", "12.34.56", 123456), + arrayOf("01.02.03", "01.02.03", 10203), + arrayOf("99.99.99", "99.99.99", 999999), + ) + } + } +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts index 1cc98eb7a..e0a72f6bf 100644 --- a/build-logic/settings.gradle.kts +++ b/build-logic/settings.gradle.kts @@ -3,6 +3,14 @@ * License information is available from the LICENSE file. */ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} + dependencyResolutionManagement { repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS