diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f7d29c052..3319e7eac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,6 +50,7 @@ jobs: with: ref: ${{ github.event.inputs.branch }} submodules: 'recursive' + fetch-depth: 0 - name: Cache Gradle packages uses: actions/cache@v4 @@ -82,8 +83,20 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Calculate Version Code with Git Commit Count and Offset + id: calculate_version_code + run: | + GIT_COMMIT_COUNT=$(git rev-list --count HEAD) + OFFSET=30630 # to ensure versionCode is above 30630 + VERSION_CODE=$((GIT_COMMIT_COUNT + OFFSET)) + echo "Calculated versionCode: $VERSION_CODE (from $GIT_COMMIT_COUNT commits + $OFFSET offset)" + echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV + - name: Build F-Droid release run: ./gradlew assembleFdroidRelease + env: + VERSION_CODE: ${{ env.VERSION_CODE }} - name: Upload F-Droid APK artifact (for release job) uses: actions/upload-artifact@v4 @@ -108,6 +121,7 @@ jobs: with: ref: ${{ github.event.inputs.branch }} submodules: 'recursive' + fetch-depth: 0 - name: Cache Gradle packages uses: actions/cache@v4 @@ -143,8 +157,19 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Calculate Version Code with Git Commit Count and Offset + id: calculate_version_code + run: | + GIT_COMMIT_COUNT=$(git rev-list --count HEAD) + OFFSET=30630 # to ensure versionCode is above 30630 + VERSION_CODE=$((GIT_COMMIT_COUNT + OFFSET)) + echo "Calculated versionCode: $VERSION_CODE (from $GIT_COMMIT_COUNT commits + $OFFSET offset)" + echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV + - name: Build Play Store release run: ./gradlew bundleGoogleRelease assembleGoogleRelease + env: + VERSION_CODE: ${{ env.VERSION_CODE }} - name: Upload Play Store AAB artifact (for release job) uses: actions/upload-artifact@v4 diff --git a/.github/workflows/reusable-android-build.yml b/.github/workflows/reusable-android-build.yml index 9ec316512..880ff2797 100644 --- a/.github/workflows/reusable-android-build.yml +++ b/.github/workflows/reusable-android-build.yml @@ -20,6 +20,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: + fetch-depth: 0 submodules: 'recursive' - name: Validate Gradle wrapper uses: gradle/actions/wrapper-validation@v4 @@ -55,8 +56,20 @@ jobs: build-scan-terms-of-use-url: 'https://gradle.com/terms-of-service' build-scan-terms-of-use-agree: 'yes' add-job-summary: always + + - name: Calculate Version Code with Git Commit Count and Offset + id: calculate_version_code + run: | + GIT_COMMIT_COUNT=$(git rev-list --count HEAD) + OFFSET=30630 # to ensure versionCode is above 30630 (our last manual versionCode) + VERSION_CODE=$((GIT_COMMIT_COUNT + OFFSET)) + echo "Calculated versionCode: $VERSION_CODE (from $GIT_COMMIT_COUNT commits + $OFFSET offset)" + echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV + - name: Run Detekt, Build, Lint, and Local Tests run: ./gradlew detekt lintFdroidDebug lintGoogleDebug assembleDebug testFdroidDebug testGoogleDebug --configuration-cache --scan + env: + VERSION_CODE: ${{ env.VERSION_CODE }} - name: Upload F-Droid debug artifact if: ${{ inputs.upload_artifacts }} uses: actions/upload-artifact@v4 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 400e2a425..30d95d908 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -52,8 +52,8 @@ android { applicationId = Configs.APPLICATION_ID minSdk = Configs.MIN_SDK_VERSION targetSdk = Configs.TARGET_SDK - versionCode = - Configs.VERSION_CODE // format is Mmmss (where M is 1+the numeric major number) + versionCode = System.getenv("VERSION_CODE")?.toIntOrNull() + ?: 1 versionName = Configs.VERSION_NAME testInstrumentationRunner = "com.geeksville.mesh.TestRunner" buildConfigField("String", "MIN_FW_VERSION", "\"${Configs.MIN_FW_VERSION}\"") diff --git a/buildSrc/src/main/kotlin/Configs.kt b/buildSrc/src/main/kotlin/Configs.kt index 6b7349f00..623abd174 100644 --- a/buildSrc/src/main/kotlin/Configs.kt +++ b/buildSrc/src/main/kotlin/Configs.kt @@ -20,7 +20,6 @@ object Configs { const val MIN_SDK_VERSION = 26 const val TARGET_SDK = 36 const val COMPILE_SDK = 36 - const val VERSION_CODE = 30630 // format is Mmmss (where M is 1+the numeric major number) const val VERSION_NAME = "2.6.30" const val MIN_FW_VERSION = "2.5.14" // Minimum device firmware version supported by this app const val ABS_MIN_FW_VERSION = "2.3.15" // Minimum device firmware version supported by this app