Release Android APK #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Android APK | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: Version change for this release (prefer patch/minor; major is a breaking jump) | |
| required: true | |
| type: choice | |
| default: patch | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - none | |
| # "none" = keep current app.json version (already bumped locally) | |
| notes: | |
| description: Optional release notes for users (shown on the GitHub Release page). Leave blank to use auto notes from commits. | |
| required: false | |
| type: string | |
| default: '' | |
| concurrency: | |
| group: release-android | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 90 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Node | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 22 | |
| cache: npm | |
| - name: Setup Java | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v4 | |
| - name: Accept Android licenses | |
| run: yes | sdkmanager --licenses >/dev/null || true | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Bump version | |
| if: inputs.bump != 'none' | |
| run: node scripts/bump-version.cjs "${{ inputs.bump }}" | |
| - name: Resolve version | |
| id: meta | |
| run: | | |
| VERSION=$(node -p "require('./app.json').expo.version") | |
| CODE=$(node -p "require('./app.json').expo.android.versionCode") | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "version_code=$CODE" >> "$GITHUB_OUTPUT" | |
| echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Resolved v$VERSION (versionCode $CODE)" | |
| - name: Prebuild Android project | |
| env: | |
| CI: 1 | |
| NODE_ENV: production | |
| run: npx expo prebuild -p android | |
| - name: Build release APK | |
| working-directory: android | |
| env: | |
| NODE_ENV: production | |
| run: ./gradlew assembleRelease --no-daemon | |
| - name: Package APK artifact | |
| run: | | |
| mkdir -p dist | |
| cp android/app/build/outputs/apk/release/app-release.apk dist/Canal-Study.apk | |
| ls -lh dist/Canal-Study.apk | |
| - name: Write release notes file | |
| env: | |
| MANUAL_NOTES: ${{ inputs.notes }} | |
| run: | | |
| { | |
| if [ -n "$MANUAL_NOTES" ]; then | |
| printf '%s\n\n' "$MANUAL_NOTES" | |
| fi | |
| echo "### Install" | |
| echo "Download **Canal-Study.apk** below and install it on your Android device." | |
| echo "" | |
| echo "Version **${{ steps.meta.outputs.version }}** (versionCode ${{ steps.meta.outputs.version_code }})." | |
| } > dist/release-notes.md | |
| cat dist/release-notes.md | |
| - name: Commit version bump and create tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add app.json package.json | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Release Canal Study v${{ steps.meta.outputs.version }}" | |
| git push origin HEAD:${{ github.ref_name }} | |
| fi | |
| if git rev-parse "${{ steps.meta.outputs.tag }}" >/dev/null 2>&1; then | |
| echo "Tag ${{ steps.meta.outputs.tag }} already exists" | |
| else | |
| git tag "${{ steps.meta.outputs.tag }}" | |
| git push origin "${{ steps.meta.outputs.tag }}" | |
| fi | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| tag_name: ${{ steps.meta.outputs.tag }} | |
| name: Canal Study ${{ steps.meta.outputs.tag }} | |
| body_path: dist/release-notes.md | |
| generate_release_notes: true | |
| files: dist/Canal-Study.apk | |
| fail_on_unmatched_files: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |