|
| 1 | +name: Branch APK |
| 2 | + |
| 3 | +# On every push to a non-main branch, build a debug APK and replace the |
| 4 | +# rolling pre-release tagged `branch-<name>` with the freshly built artifact. |
| 5 | +# Testers always get the latest commit by visiting the same release URL. |
| 6 | +# |
| 7 | +# Pull-request runs build the APK as a workflow artifact (downloadable from |
| 8 | +# the Actions tab for ~90 days) but do not touch the release list, so PRs |
| 9 | +# from forks can't push tags. |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches-ignore: |
| 14 | + - main |
| 15 | + tags-ignore: |
| 16 | + - "**" |
| 17 | + pull_request: |
| 18 | + branches: |
| 19 | + - "**" |
| 20 | + workflow_dispatch: |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: write |
| 24 | + |
| 25 | +jobs: |
| 26 | + build: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 # full history so we can produce a "since main" log |
| 34 | + |
| 35 | + - name: Set up JDK 17 |
| 36 | + uses: actions/setup-java@v4 |
| 37 | + with: |
| 38 | + distribution: temurin |
| 39 | + java-version: "17" |
| 40 | + |
| 41 | + - name: Set up Gradle |
| 42 | + uses: gradle/actions/setup-gradle@v3 |
| 43 | + |
| 44 | + - name: Make gradlew executable |
| 45 | + run: chmod +x ./gradlew |
| 46 | + |
| 47 | + - name: Build debug APK |
| 48 | + run: ./gradlew :app:assembleDebug --no-daemon --stacktrace |
| 49 | + env: |
| 50 | + GRADLE_OPTS: -Xmx4g -Dorg.gradle.jvmargs=-Xmx4g |
| 51 | + |
| 52 | + - name: Compute build metadata |
| 53 | + id: meta |
| 54 | + if: github.event_name != 'pull_request' |
| 55 | + run: | |
| 56 | + BRANCH="${GITHUB_REF##*/}" |
| 57 | + SHORT_SHA="$(git rev-parse --short HEAD)" |
| 58 | + TAG="branch-${BRANCH}" |
| 59 | + APK_NAME="EUC-Planet-${BRANCH}-${SHORT_SHA}.apk" |
| 60 | +
|
| 61 | + # Pull the per-branch description if BRANCH.md exists, otherwise |
| 62 | + # fall back to a generic notice. This becomes the release body header. |
| 63 | + if [ -f BRANCH.md ]; then |
| 64 | + cp BRANCH.md /tmp/branch-notes.md |
| 65 | + else |
| 66 | + cat > /tmp/branch-notes.md <<EOF |
| 67 | + # ${BRANCH} |
| 68 | +
|
| 69 | + No \`BRANCH.md\` found at repo root. Add one to describe what this |
| 70 | + branch is for and who should test it. |
| 71 | + EOF |
| 72 | + fi |
| 73 | +
|
| 74 | + # Recent commits since branching from main, capped to keep the |
| 75 | + # release body readable on big branches. |
| 76 | + git log --pretty=format:'- %h %s' main..HEAD | head -50 > /tmp/commit-log.md || true |
| 77 | +
|
| 78 | + { |
| 79 | + echo "**Pre-release from branch \`${BRANCH}\`** — automatic build at \`${SHORT_SHA}\`." |
| 80 | + echo |
| 81 | + echo "This is a CI-built debug APK. It can't update an existing Play Store install in place — uninstall the Play version first to install this build." |
| 82 | + echo |
| 83 | + cat /tmp/branch-notes.md |
| 84 | + echo |
| 85 | + echo "## Recent commits" |
| 86 | + echo |
| 87 | + cat /tmp/commit-log.md |
| 88 | + } > /tmp/release-body.md |
| 89 | +
|
| 90 | + echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT" |
| 91 | + echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT" |
| 92 | + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 93 | + echo "apk_name=${APK_NAME}" >> "$GITHUB_OUTPUT" |
| 94 | +
|
| 95 | + - name: Rename APK for release |
| 96 | + if: github.event_name != 'pull_request' |
| 97 | + run: | |
| 98 | + cp app/build/outputs/apk/debug/app-debug.apk \ |
| 99 | + "/tmp/${{ steps.meta.outputs.apk_name }}" |
| 100 | +
|
| 101 | + - name: Upload APK as workflow artifact |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: app-debug-${{ github.run_id }} |
| 105 | + path: app/build/outputs/apk/debug/app-debug.apk |
| 106 | + retention-days: 90 |
| 107 | + |
| 108 | + - name: Strip prior APKs from rolling release |
| 109 | + if: github.event_name != 'pull_request' |
| 110 | + env: |
| 111 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + run: | |
| 113 | + # action-gh-release attaches new files but doesn't remove the previous |
| 114 | + # commit's APK; without this step the rolling pre-release accumulates |
| 115 | + # one APK per push. Delete every existing .apk on the tag before the |
| 116 | + # next step uploads the freshly built one. Tolerate the tag not |
| 117 | + # existing yet (first run on a brand-new branch). |
| 118 | + tag="${{ steps.meta.outputs.tag }}" |
| 119 | + if gh release view "$tag" >/dev/null 2>&1; then |
| 120 | + gh release view "$tag" --json assets \ |
| 121 | + --jq '.assets[] | select(.name | endswith(".apk")) | .name' \ |
| 122 | + | while read -r asset; do |
| 123 | + [ -n "$asset" ] && gh release delete-asset "$tag" "$asset" --yes || true |
| 124 | + done |
| 125 | + fi |
| 126 | +
|
| 127 | + - name: Replace rolling pre-release with new APK |
| 128 | + if: github.event_name != 'pull_request' |
| 129 | + uses: softprops/action-gh-release@v2 |
| 130 | + with: |
| 131 | + tag_name: ${{ steps.meta.outputs.tag }} |
| 132 | + name: ${{ steps.meta.outputs.tag }} (${{ steps.meta.outputs.short_sha }}) |
| 133 | + body_path: /tmp/release-body.md |
| 134 | + prerelease: true |
| 135 | + # Replace the existing tag/release on every push so testers can |
| 136 | + # always find the latest at the same URL. |
| 137 | + make_latest: "false" |
| 138 | + files: /tmp/${{ steps.meta.outputs.apk_name }} |
0 commit comments