From 1ab1520c6072b480023547e3e63e5b58dff5c8ca Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 27 Jan 2024 13:57:58 +0530 Subject: [PATCH] feat(build): add support for Tramline builds --- .github/workflows/tramline-release.yml | 43 +++++++++++++++++++ .../gradle/versioning/VersioningPlugin.kt | 34 +++++++++------ 2 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/tramline-release.yml diff --git a/.github/workflows/tramline-release.yml b/.github/workflows/tramline-release.yml new file mode 100644 index 00000000..1e0a62d0 --- /dev/null +++ b/.github/workflows/tramline-release.yml @@ -0,0 +1,43 @@ +name: Android release build + +on: + workflow_dispatch: + inputs: + versionName: + description: 'User-facing release version name' + required: true + default: "" + versionCode: + description: 'versionCode or build number' + required: true + default: '' + +jobs: + signed-build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Set up JDK + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 + with: + distribution: temurin + java-version: 18 + + - name: Build release app + uses: gradle/gradle-build-action@a8f75513eafdebd8141bd1cd4e30fcd194af8dfa # v2.12.0 + env: + SENTRY_DSN: ${{ secrets.SENTRY_DSN }} + ORG_GRADLE_PROJECT_VERSION_NAME: ${{ github.event.inputs.versionName }} + ORG_GRADLE_PROJECT_VERSION_CODE: ${{ github.event.inputs.versionCode }} + with: + arguments: --no-configuration-cache --stacktrace collectReleaseBundle + gradle-home-cache-cleanup: true + cache-read-only: ${{ github.ref != 'refs/heads/main' }} + + - name: Upload app bundle + uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0 + with: + name: release-aab + path: android/build/outputs/bundle/release/android-release.aab diff --git a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningPlugin.kt b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningPlugin.kt index f8756737..cd3499e6 100644 --- a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningPlugin.kt +++ b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningPlugin.kt @@ -37,13 +37,23 @@ class VersioningPlugin : Plugin { val contents = providers.fileContents(propFile).asText val versionProps = Properties().also { it.load(contents.get().byteInputStream()) } val versionName = - requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) { - "version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property" - } + providers + .gradleProperty("VERSION_NAME") + .orElse( + requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) { + "version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property" + } + ) val versionCode = - requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_CODE).toInt()) { - "version.properties must contain a '$VERSIONING_PROP_VERSION_CODE' property" - } + providers + .gradleProperty("VERSION_CODE") + .orElse( + requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_CODE)) { + "version.properties must contain a '$VERSIONING_PROP_VERSION_CODE' property" + } + ) + .map(String::toInt) + project.plugins.withType { androidAppPluginApplied.set(true) extensions.configure { @@ -57,30 +67,30 @@ class VersioningPlugin : Plugin { } } } - val version = Version.parse(versionName) + val version = versionName.map(Version::parse) tasks.register("clearPreRelease") { description = "Remove the pre-release suffix from the version" - semverString.set(version.toStableVersion().toString()) + semverString.set(version.get().toStableVersion().toString()) propertyFile.set(propFile) } tasks.register("bumpMajor") { description = "Increment the major version" - semverString.set(version.nextMajorVersion().toString()) + semverString.set(version.get().nextMajorVersion().toString()) propertyFile.set(propFile) } tasks.register("bumpMinor") { description = "Increment the minor version" - semverString.set(version.nextMinorVersion().toString()) + semverString.set(version.get().nextMinorVersion().toString()) propertyFile.set(propFile) } tasks.register("bumpPatch") { description = "Increment the patch version" - semverString.set(version.nextPatchVersion().toString()) + semverString.set(version.get().nextPatchVersion().toString()) propertyFile.set(propFile) } tasks.register("bumpSnapshot") { description = "Increment the minor version and add the `SNAPSHOT` suffix" - semverString.set(version.nextMinorVersion("SNAPSHOT").toString()) + semverString.set(version.get().nextMinorVersion("SNAPSHOT").toString()) propertyFile.set(propFile) } afterEvaluate {