diff --git a/.github/workflows/build_apk_job.yml b/.github/workflows/build_apk_job.yml index c0861cb0..df00d9a6 100644 --- a/.github/workflows/build_apk_job.yml +++ b/.github/workflows/build_apk_job.yml @@ -18,6 +18,16 @@ on: required: false type: string default: '' + release_build: + description: 'Whether this is a release build' + required: false + type: boolean + default: false + git_sha: + description: 'Git short SHA for APK filename' + required: false + type: string + default: '' env: KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} @@ -50,7 +60,7 @@ jobs: path: app/keystore - name: Build APK - run: bash ./gradlew :app:assembleRelease --stacktrace --no-daemon + run: bash ./gradlew :app:assembleRelease -PGIT_SHA=${{ inputs.git_sha }} -PRELEASE_BUILD=${{ inputs.release_build }} --stacktrace --no-daemon - name: Upload APK uses: actions/upload-artifact@v4 diff --git a/.github/workflows/build_release.yml b/.github/workflows/build_release.yml index f164435d..c26e1e31 100644 --- a/.github/workflows/build_release.yml +++ b/.github/workflows/build_release.yml @@ -22,8 +22,8 @@ jobs: id: extract run: | TAG="${GITHUB_REF_NAME}" - # Tag format: v2.2.0-70 - VERSION_NAME="${TAG%-*}" + VERSION_NAME="${TAG#v}" + VERSION_NAME="${VERSION_NAME%-*}" VERSION_CODE="${TAG##*-}" echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT @@ -34,6 +34,7 @@ jobs: with: version_name: ${{ needs.extract_version.outputs.version_name }} version_code: ${{ needs.extract_version.outputs.version_code }} + release_build: true secrets: inherit release: diff --git a/.github/workflows/build_staging.yml b/.github/workflows/build_staging.yml index efbaa598..fef1069e 100644 --- a/.github/workflows/build_staging.yml +++ b/.github/workflows/build_staging.yml @@ -17,20 +17,32 @@ jobs: outputs: version_name: ${{ steps.extract.outputs.version_name }} version_code: ${{ steps.extract.outputs.version_code }} + short_commit: ${{ steps.extract.outputs.short_commit }} steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 + fetch-tags: true - name: Extract version from latest tag id: extract run: | - LATEST_TAG=$(git describe --tags --abbrev=0) - VERSION_CODE="${LATEST_TAG##*-}" - VERSION_NAME="${GITHUB_SHA::7}" + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + SHORT_SHA="${GITHUB_SHA::7}" + + if [ -z "$LATEST_TAG" ]; then + VERSION_NAME="0.0.0-${SHORT_SHA}" + VERSION_CODE="1" + else + BASE_VERSION="${LATEST_TAG#v}" + BASE_VERSION="${BASE_VERSION%-*}" + VERSION_NAME="${BASE_VERSION}-${SHORT_SHA}" + VERSION_CODE="${LATEST_TAG##*-}" + fi echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT + echo "short_commit=$SHORT_SHA" >> $GITHUB_OUTPUT build: needs: extract_version @@ -39,6 +51,8 @@ jobs: checkout_keystore: ${{ github.event.pull_request.user.login == github.repository_owner }} version_name: ${{ needs.extract_version.outputs.version_name }} version_code: ${{ needs.extract_version.outputs.version_code }} + release_build: false + git_sha: ${{ needs.extract_version.outputs.short_commit }} secrets: inherit send: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c4e0e919..3fa311da 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,8 +15,7 @@ android { versionCode = providers .environmentVariable("VERSION_CODE") .orNull - ?.toIntOrNull() - ?: Int.MAX_VALUE + ?.toIntOrNull() ?: 1 versionName = providers .environmentVariable("VERSION_NAME") .getOrElse("unknown") @@ -29,7 +28,19 @@ android { applicationVariants.configureEach { outputs.configureEach { if (this is BaseVariantOutputImpl) { - outputFileName = "LogFox-${versionName}-${name}.apk" + val shortCommit = providers.gradleProperty("GIT_SHA") + .orElse(providers.environmentVariable("GIT_SHA")) + .orNull + ?.take(7) ?: "local" + + val releaseBuild = providers.gradleProperty("RELEASE_BUILD") + .orElse(providers.environmentVariable("RELEASE_BUILD")) + .orNull ?: "false" + + outputFileName = if (releaseBuild == "true" || versionName.contains(shortCommit)) + "LogFox-v${versionName}-release.apk" + else + "LogFox-v${versionName}-${shortCommit}-release.apk" } } }