Auto-build APK and publish a GitHub release on every push to main #1
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 | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-and-release: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Java 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "17" | |
| - name: Set up Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: "3.44.0" | |
| channel: stable | |
| cache: true | |
| - name: Resolve Dart/Flutter dependencies | |
| run: flutter pub get | |
| # The drift / riverpod generators are needed because *.g.dart files | |
| # are gitignored and not committed. | |
| - name: Run code generators | |
| run: dart run build_runner build --delete-conflicting-outputs | |
| - name: Build release APK | |
| run: flutter build apk --release | |
| - name: Compute release identifiers | |
| id: meta | |
| run: | | |
| base=$(grep '^version:' pubspec.yaml | awk '{print $2}' | cut -d'+' -f1) | |
| tag="v${base}-build.${{ github.run_number }}" | |
| name="mappy ${base} (build ${{ github.run_number }})" | |
| echo "tag=${tag}" >> "$GITHUB_OUTPUT" | |
| echo "name=${name}" >> "$GITHUB_OUTPUT" | |
| - name: Rename APK with version tag | |
| id: apk | |
| run: | | |
| src=build/app/outputs/flutter-apk/app-release.apk | |
| dst="build/app/outputs/flutter-apk/mappy-${{ steps.meta.outputs.tag }}.apk" | |
| mv "$src" "$dst" | |
| sha=$(sha256sum "$dst" | awk '{print $1}') | |
| echo "path=${dst}" >> "$GITHUB_OUTPUT" | |
| echo "sha256=${sha}" >> "$GITHUB_OUTPUT" | |
| - name: Upload APK as workflow artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mappy-${{ steps.meta.outputs.tag }} | |
| path: ${{ steps.apk.outputs.path }} | |
| if-no-files-found: error | |
| retention-days: 30 | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.meta.outputs.tag }} | |
| name: ${{ steps.meta.outputs.name }} | |
| generate_release_notes: true | |
| # Public releases are downloadable without auth on public repos. | |
| make_latest: "true" | |
| body: | | |
| Auto-built APK for commit ${{ github.sha }}. | |
| **Install:** Download the `.apk` below on an Android device and open | |
| it. You may need to allow "Install unknown apps" for your browser. | |
| **Signing:** This build is signed with Flutter's debug keystore. | |
| It will install fine but is not Play-Store-ready. | |
| **SHA-256:** `${{ steps.apk.outputs.sha256 }}` | |
| files: ${{ steps.apk.outputs.path }} |