diff --git a/.github/actions/prepare-release/action.yml b/.github/actions/prepare-release/action.yml new file mode 100644 index 0000000..5b841a6 --- /dev/null +++ b/.github/actions/prepare-release/action.yml @@ -0,0 +1,27 @@ +name: 'Prepare Release' +description: 'Overrides appVersionCode with the workflow run number plus an offset for all later Gradle calls in the job' +inputs: + versioncode_offset: + description: 'Offset for version code' + required: false + default: '0' +outputs: + version_code: + description: 'The version code that was set' + value: ${{ steps.calculate.outputs.final_version }} +runs: + using: "composite" + steps: + - name: Calculate Version Code + id: calculate + shell: bash + run: | + # Use $(( )) for bash arithmetic + TOTAL_VERSION=$(( ${{ inputs.versioncode_offset }} + ${{ github.run_number }} )) + echo "final_version=$TOTAL_VERSION" >> $GITHUB_OUTPUT + + # Gradle reads ORG_GRADLE_PROJECT_* as project properties, which take precedence over gradle.properties. + # This also applies to Gradle calls started by Xcode. + - name: Update Version Code + shell: bash + run: echo "ORG_GRADLE_PROJECT_appVersionCode=${{ steps.calculate.outputs.final_version }}" >> "$GITHUB_ENV" diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml index b2601d9..6e2b308 100644 --- a/.github/workflows/android-release.yml +++ b/.github/workflows/android-release.yml @@ -27,6 +27,10 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v6 + # Uses the run number as version code, so every build can be installed over the previous one + - name: Prepare release + uses: ./.github/actions/prepare-release + - name: Resolve app version metadata id: app_meta shell: bash @@ -89,8 +93,6 @@ jobs: ./gradlew \ :androidApp:assembleRelease \ :androidApp:bundleRelease \ - -Papp.versionNameOverride=${{ steps.app_meta.outputs.version_name }} \ - -Papp.versionCodeOverride=${{ steps.app_meta.outputs.version_code }} \ --stacktrace - name: List generated release outputs @@ -129,8 +131,6 @@ jobs: echo "$FIREBASE_CREDENTIALS" > "$RUNNER_TEMP/firebase-credentials.json" export GOOGLE_APPLICATION_CREDENTIALS="$RUNNER_TEMP/firebase-credentials.json" ./gradlew :androidApp:appDistributionUploadRelease \ - -Papp.versionNameOverride=${{ steps.app_meta.outputs.version_name }} \ - -Papp.versionCodeOverride=${{ steps.app_meta.outputs.version_code }} \ --stacktrace | tee "$RUNNER_TEMP/firebase-upload.log" RELEASE_URL=$(grep -o 'https://console.firebase.google.com/[^ ]*' "$RUNNER_TEMP/firebase-upload.log" | head -n 1 || true) diff --git a/.github/workflows/ios-release.yml b/.github/workflows/ios-release.yml index 614d3f1..508175a 100644 --- a/.github/workflows/ios-release.yml +++ b/.github/workflows/ios-release.yml @@ -48,6 +48,10 @@ jobs: with: xcode-version: ${{ env.XCODE_VERSION }} + # Uses the run number as version code (build number), so every build can be uploaded to TestFlight + - name: Prepare release + uses: ./.github/actions/prepare-release + - name: Resolve app version metadata id: app_meta shell: bash @@ -61,6 +65,7 @@ jobs: echo "version_name=$VERSION_NAME" >> "$GITHUB_OUTPUT" echo "version_code=$VERSION_CODE" >> "$GITHUB_OUTPUT" + echo "Version name: $VERSION_NAME, version code: $VERSION_CODE" - name: Cache Swift Package Manager dependencies uses: actions/cache@v5