diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 65853e7..1dd25ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -86,9 +86,12 @@ jobs: # Build and sign APK ("-x test" argument is used to skip tests) # add fdroid flavor for apk upload - name: Build Fdroid Release APK - if: ${{ inputs.release_type != '' && inputs.release_type != 'nightly' }} + if: ${{ inputs.release_type != '' && inputs.release_type == 'release' }} run: ./gradlew :app:assembleFdroidRelease -x test + - name: Build Fdroid Prerelease APK + if: ${{ inputs.release_type != '' && inputs.release_type == 'prerelease' }} + run: ./gradlew :app:assembleFdroidPrerelease -x test - name: Build Fdroid Nightly APK if: ${{ inputs.release_type == '' || inputs.release_type == 'nightly' }} @@ -96,11 +99,13 @@ jobs: - if: ${{ inputs.release_type == '' || inputs.release_type == 'nightly' }} run: echo "APK_PATH=$(find . -regex '^.*/build/outputs/apk/fdroid/nightly/.*\.apk$' -type f | head -1)" >> $GITHUB_ENV - - if: ${{ inputs.release_type != '' && inputs.release_type != 'nightly' }} + - if: ${{ inputs.release_type != '' && inputs.release_type == 'release' }} run: echo "APK_PATH=$(find . -regex '^.*/build/outputs/apk/fdroid/release/.*\.apk$' -type f | head -1)" >> $GITHUB_ENV + - if: ${{ inputs.release_type != '' && inputs.release_type == 'prerelease' }} + run: echo "APK_PATH=$(find . -regex '^.*/build/outputs/apk/fdroid/prerelease/.*\.apk$' -type f | head -1)" >> $GITHUB_ENV - name: Get version code - if: ${{ inputs.release_type == 'release' || inputs.release_type == 'prerelease' }} + if: ${{ inputs.release_type == 'release' }} run: | version_code=$(grep "VERSION_CODE" buildSrc/src/main/kotlin/Constants.kt | awk '{print $5}' | tr -d '\n') echo "VERSION_CODE=$version_code" >> $GITHUB_ENV @@ -126,31 +131,30 @@ jobs: event-type: fdroid-update - name: Set version release notes - if: ${{ inputs.release_type == 'release' || inputs.release_type == 'prerelease' }} + if: ${{ inputs.release_type == 'release' }} run: | RELEASE_NOTES="$(cat ${{ github.workspace }}/fastlane/metadata/android/en-US/changelogs/${{ env.VERSION_CODE }}.txt)" echo "RELEASE_NOTES<> $GITHUB_ENV echo "$RELEASE_NOTES" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - - name: On nightly release + - name: On nightly release notes if: ${{ contains(env.TAG_NAME, 'nightly') }} run: | echo "RELEASE_NOTES=Nightly build for the latest development version of the app." >> $GITHUB_ENV gh release delete nightly --yes || true + - name: On prerelease release notes + if: ${{ inputs.release_type == 'prerelease' }} + run: | + echo "RELEASE_NOTES=Testing version of app for specific feature." >> $GITHUB_ENV + # Setup TAG_NAME, which is used as a general "name" - if: github.event_name == 'workflow_dispatch' run: echo "TAG_NAME=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV - if: github.event_name == 'schedule' run: echo "TAG_NAME=nightly" >> $GITHUB_ENV - - name: On nightly release - if: ${{ contains(env.TAG_NAME, 'nightly') }} - run: | - echo "RELEASE_NOTES=Nightly build of the latest development version of the android client." >> $GITHUB_ENV - gh release delete nightly --yes || true - - name: Get checksum id: checksum run: echo "checksum=$(apksigner verify -print-certs ${{ env.APK_PATH }} | grep -Po "(?<=SHA-256 digest:) .*" | tr -d "[:blank:]")" >> $GITHUB_OUTPUT @@ -164,7 +168,7 @@ jobs: with: body: | ${{ env.RELEASE_NOTES }} - + SHA256 fingerprint: ```${{ steps.checksum.outputs.checksum }}``` tag_name: ${{ env.TAG_NAME }} diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 127f0d5..39e983b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -60,6 +60,10 @@ android { } debug { isDebuggable = true } + create(Constants.PRERELEASE) { + initWith(buildTypes.getByName(Constants.RELEASE)) + } + create(Constants.NIGHTLY) { initWith(buildTypes.getByName(Constants.RELEASE)) } @@ -184,19 +188,21 @@ dependencies { } fun determineVersionCode(): Int { - return if (isNightlyBuild()) { - Constants.VERSION_CODE + - Constants.NIGHTLY_CODE - } else { - Constants.VERSION_CODE + return with(getBuildTaskName().lowercase()) { + when { + contains(Constants.NIGHTLY) -> Constants.VERSION_CODE + Constants.NIGHTLY_CODE + contains(Constants.PRERELEASE) -> Constants.VERSION_CODE + Constants.PRERELEASE_CODE + else -> Constants.VERSION_CODE + } } } fun determineVersionName(): String { - return if (isNightlyBuild()) { - Constants.VERSION_NAME + - "-${grgitService.service.get().grgit.head().abbreviatedId}" - } else { - Constants.VERSION_NAME + return with(getBuildTaskName().lowercase()) { + when { + contains(Constants.NIGHTLY) || contains(Constants.PRERELEASE) -> Constants.VERSION_NAME + + "-${grgitService.service.get().grgit.head().abbreviatedId}" + else -> Constants.VERSION_NAME + } } } diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt index 2c3b2b0..527fdfa 100644 --- a/buildSrc/src/main/kotlin/Constants.kt +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -1,5 +1,5 @@ object Constants { - const val VERSION_NAME = "3.4.8" + const val VERSION_NAME = "3.4.8" const val JVM_TARGET = "17" const val VERSION_CODE = 34800 const val TARGET_SDK = 34 @@ -14,8 +14,10 @@ object Constants { const val RELEASE = "release" const val NIGHTLY = "nightly" + const val PRERELEASE = "prerelease" const val DEBUG = "debug" const val TYPE = "type" const val NIGHTLY_CODE = 42 + const val PRERELEASE_CODE = 99 } diff --git a/buildSrc/src/main/kotlin/Extensions.kt b/buildSrc/src/main/kotlin/Extensions.kt index a2a476f..2f9c58e 100644 --- a/buildSrc/src/main/kotlin/Extensions.kt +++ b/buildSrc/src/main/kotlin/Extensions.kt @@ -23,10 +23,10 @@ fun Project.getCurrentFlavor(): String { return flavor } -fun Project.isNightlyBuild(): Boolean { +fun Project.getBuildTaskName(): String { val taskRequestsStr = gradle.startParameter.taskRequests[0].toString() - return taskRequestsStr.lowercase().contains(Constants.NIGHTLY).also { - project.logger.lifecycle("Nightly build: $it") + return taskRequestsStr.also { + project.logger.lifecycle("Build task: $it") } }