diff --git a/.github/workflows/build-submit-android.yml b/.github/workflows/build-submit-android.yml index b26b13b710..1a86dce731 100644 --- a/.github/workflows/build-submit-android.yml +++ b/.github/workflows/build-submit-android.yml @@ -23,6 +23,9 @@ jobs: concurrency: group: android-build cancel-in-progress: false + outputs: + package-version: ${{ steps.get-build-info.outputs.PACKAGE_VERSION }} + apk-artifact-name: build-${{ steps.timestamp.outputs.time }}.apk steps: - name: Check for EXPO_TOKEN run: > @@ -177,3 +180,62 @@ jobs: env: GITHUB_SHA: ${{ github.sha }} run: echo $GITHUB_SHA > most-recent-testflight-commit.txt + + # Releases are cut from tags named after the version (e.g. "1.124.0"), so when a production + # build is dispatched against such a tag we attach the APK to the matching release. This runs + # as a separate job so that `contents: write` is isolated here and the build job stays read-only. + attachToRelease: + name: Attach APK to GitHub Release + runs-on: ubuntu-latest + needs: [build] + if: ${{ inputs.profile == 'production' && github.ref_type == 'tag' && github.repository == 'bluesky-social/social-app' }} + permissions: + contents: write + steps: + # We only attach to a release that already exists — never create one. + - name: 🔎 Check for matching GitHub Release + id: release-check + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + run: | + status=$(curl -sS -o /dev/null -w '%{http_code}' \ + -H "Authorization: Bearer $GH_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}") + if [ "$status" = "200" ]; then + echo "Found GitHub Release for tag $TAG" + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "No GitHub Release found for tag $TAG (HTTP $status); skipping APK attachment." + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + + - name: ⬇️ Download APK artifact + if: ${{ steps.release-check.outputs.exists == 'true' }} + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 + with: + name: ${{ needs.build.outputs.apk-artifact-name }} + + - name: 🏷️ Rename APK for release + if: ${{ steps.release-check.outputs.exists == 'true' }} + run: cp build.apk "Bluesky-${{ needs.build.outputs.package-version }}.apk" + + - name: 📎 Attach APK to GitHub Release + id: attach + if: ${{ steps.release-check.outputs.exists == 'true' }} + uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0 + with: + tag_name: ${{ github.ref_name }} + files: Bluesky-${{ needs.build.outputs.package-version }}.apk + fail_on_unmatched_files: true + + - name: 🔔 Notify Slack of Release Attachment + if: ${{ steps.release-check.outputs.exists == 'true' }} + uses: slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c # v3.0.3 + with: + webhook: ${{ secrets.SLACK_CLIENT_ALERT_WEBHOOK }} + webhook-type: incoming-webhook + payload-templated: true + payload: | + {"text": "Android APK attached to GitHub Release ${{ github.ref_name }}!\n```Asset: Bluesky-${{ needs.build.outputs.package-version }}.apk\nRelease: ${{ steps.attach.outputs.url }}```"}