|
| 1 | +# Android release: on a v* tag, build the stably-signed APK with tag-derived |
| 2 | +# versionName/versionCode and publish the GitHub Release for the tag with the |
| 3 | +# APK attached. Ungated — runs to completion automatically on tag push. |
| 4 | +# |
| 5 | +# Secrets (repo-level, public-by-design build credentials; lessons.md §37): |
| 6 | +# SUPABASE_URL, SUPABASE_ANON_KEY, GOOGLE_SERVER_CLIENT_ID |
| 7 | +# |
| 8 | +# Release creation uses the default GITHUB_TOKEN (contents: write) — no PAT, |
| 9 | +# and a Release is not a push to main, so the main-pr-gate ruleset is untouched. |
| 10 | +# This workflow triggers on tags only — never pull_request — so it cannot enter |
| 11 | +# the required-check set (contract-surfaces.md §7). |
| 12 | +name: Android release |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + tags: ["v*"] |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + android-release: |
| 23 | + name: Build APK + publish Release |
| 24 | + runs-on: ubuntu-latest |
| 25 | + timeout-minutes: 30 |
| 26 | + defaults: |
| 27 | + run: |
| 28 | + working-directory: SmartChessboard |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v5 |
| 32 | + |
| 33 | + - name: Set up JDK 21 |
| 34 | + uses: actions/setup-java@v5 |
| 35 | + with: |
| 36 | + distribution: temurin |
| 37 | + java-version: "21" |
| 38 | + |
| 39 | + - name: Set up Gradle |
| 40 | + uses: gradle/actions/setup-gradle@v4 |
| 41 | + |
| 42 | + # versionName = tag minus the leading "v" (pre-release suffix kept); |
| 43 | + # versionCode = MAJOR*10000 + MINOR*100 + PATCH from the core semver |
| 44 | + # (suffix stripped). Constraint: MINOR and PATCH must stay < 100 so the |
| 45 | + # code is monotonic across releases. Two pre-releases of the same core |
| 46 | + # version share a versionCode — acceptable for RC testing. |
| 47 | + - name: Derive version from tag |
| 48 | + id: version |
| 49 | + run: | |
| 50 | + TAG="${GITHUB_REF_NAME}" |
| 51 | + NAME="${TAG#v}" |
| 52 | + CORE="${NAME%%-*}" |
| 53 | + IFS=. read -r MAJOR MINOR PATCH <<< "$CORE" |
| 54 | + for part in "$MAJOR" "$MINOR" "$PATCH"; do |
| 55 | + case "$part" in |
| 56 | + ''|*[!0-9]*) echo "::error::Tag '$TAG' is not v<MAJOR>.<MINOR>.<PATCH>[-suffix]"; exit 1 ;; |
| 57 | + esac |
| 58 | + done |
| 59 | + if [ "$MINOR" -ge 100 ] || [ "$PATCH" -ge 100 ]; then |
| 60 | + echo "::error::MINOR and PATCH must be < 100 for the versionCode scheme"; exit 1 |
| 61 | + fi |
| 62 | + CODE=$((MAJOR * 10000 + MINOR * 100 + PATCH)) |
| 63 | + echo "APP_VERSION_NAME=$NAME" >> "$GITHUB_ENV" |
| 64 | + echo "APP_VERSION_CODE=$CODE" >> "$GITHUB_ENV" |
| 65 | + echo "versionName=$NAME versionCode=$CODE" |
| 66 | +
|
| 67 | + # Functional release APK: Supabase/Google creds injected via BuildKonfig; |
| 68 | + # signing uses the committed debug.keystore (stable signature → releases |
| 69 | + # install update-in-place). |
| 70 | + - name: Assemble release APK |
| 71 | + run: > |
| 72 | + ./gradlew :androidApp:assembleDebug --console=plain |
| 73 | + -PappVersionName="$APP_VERSION_NAME" |
| 74 | + -PappVersionCode="$APP_VERSION_CODE" |
| 75 | + -PSUPABASE_URL='${{ secrets.SUPABASE_URL }}' |
| 76 | + -PSUPABASE_ANON_KEY='${{ secrets.SUPABASE_ANON_KEY }}' |
| 77 | + -PGOOGLE_SERVER_CLIENT_ID='${{ secrets.GOOGLE_SERVER_CLIENT_ID }}' |
| 78 | +
|
| 79 | + - name: Publish GitHub Release with APK |
| 80 | + uses: softprops/action-gh-release@v2 |
| 81 | + with: |
| 82 | + tag_name: ${{ github.ref_name }} |
| 83 | + generate_release_notes: true |
| 84 | + files: SmartChessboard/androidApp/build/outputs/apk/debug/*.apk |
| 85 | + fail_on_unmatched_files: true |
0 commit comments