Merge dev into 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: Android Snapshot | |
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: app | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: "temurin" | |
| java-version: "17" | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v3 | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build web assets | |
| run: pnpm build | |
| - name: Sync Android | |
| run: pnpm sync:android | |
| - name: Build APK | |
| run: | | |
| chmod +x android/gradlew | |
| cd android | |
| ./gradlew assembleDebug | |
| - name: Upload APK artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: android-apk | |
| path: app/android/app/build/outputs/apk/debug/app-debug.apk | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download APK artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: android-apk | |
| - name: Update latest snapshot tag | |
| run: | | |
| git tag -f latest-snapshot "${GITHUB_SHA}" | |
| git push -f origin latest-snapshot | |
| - name: Prepare release | |
| id: release | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const tag = "latest-snapshot"; | |
| const notes = `Snapshot build from ${context.sha.substring(0, 7)} (${new Date().toISOString().slice(0, 10)})`; | |
| let release; | |
| try { | |
| release = await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag | |
| }); | |
| } catch (error) { | |
| if (error.status !== 404) throw error; | |
| } | |
| if (!release) { | |
| release = await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: tag, | |
| name: "Latest Snapshot", | |
| body: notes, | |
| prerelease: true | |
| }); | |
| } else { | |
| const assets = await github.paginate(github.rest.repos.listReleaseAssets, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: release.data.id | |
| }); | |
| for (const asset of assets) { | |
| await github.rest.repos.deleteReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| asset_id: asset.id | |
| }); | |
| } | |
| await github.rest.repos.updateRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: release.data.id, | |
| name: "Latest Snapshot", | |
| body: notes, | |
| prerelease: true | |
| }); | |
| } | |
| core.setOutput("upload_url", release.data.upload_url); | |
| - name: Upload release asset | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.release.outputs.upload_url }} | |
| asset_path: app-debug.apk | |
| asset_name: app-debug.apk | |
| asset_content_type: application/vnd.android.package-archive |