44 push :
55 tags :
66 - ' v*'
7-
7+ pull_request :
8+ types : [labeled, synchronize] # 'synchronize' triggers on new commits
89
910jobs :
1011 build :
12+ # Runs if it's a tag push OR if the PR currently has the 'build-apk' label applied
13+ # for a same-repository PR where signing secrets and PR write permissions are available
14+ if : >
15+ github.event_name == 'push' ||
16+ (github.event_name == 'pull_request' &&
17+ github.event.pull_request.head.repo.full_name == github.repository &&
18+ contains(github.event.pull_request.labels.*.name, 'build-apk'))
1119 runs-on : ubuntu-latest
1220 permissions :
1321 contents : write
22+ pull-requests : write # Required to post the comment in the PR history
1423
1524 steps :
1625 - name : Checkout code
@@ -29,12 +38,10 @@ jobs:
2938 - name : Decode Keystore
3039 env :
3140 KEYSTORE_BASE64 : ${{ secrets.KEYSTORE_BASE64 }}
32- KEYSTORE_PROPERTIES : ${{ secrets.KEYSTORE_PROPERTIES }}
3341 run : |
3442 echo "$KEYSTORE_BASE64" | base64 --decode > release.keystore
3543
3644 # Create keystore.properties
37- # We point to ../release.keystore because this property is read by the :app module
3845 echo "storeFile=../release.keystore" > keystore.properties
3946 echo "keyAlias=${{ secrets.KEY_ALIAS }}" >> keystore.properties
4047 echo "storePassword=${{ secrets.STORE_PASSWORD }}" >> keystore.properties
@@ -43,13 +50,52 @@ jobs:
4350 - name : Build Release APK
4451 run : ./gradlew assembleRelease
4552
53+ - name : Determine APK Name
54+ id : apk-name
55+ run : |
56+ if [ "${{ github.event_name }}" = "pull_request" ]; then
57+ echo "filename=notate-pr-${{ github.event.pull_request.number }}.apk" >> $GITHUB_OUTPUT
58+ else
59+ echo "filename=notate-${{ github.ref_name }}.apk" >> $GITHUB_OUTPUT
60+ fi
61+
4662 - name : Rename APK
47- run : mv app/build/outputs/apk/release/app-release.apk notate- ${{ github.ref_name }}.apk
63+ run : mv app/build/outputs/apk/release/app-release.apk ${{ steps.apk-name.outputs.filename }}
4864
65+ # ---------------------------------------------------------
66+ # PATH A: TAG PUSH -> Create GitHub Release
67+ # ---------------------------------------------------------
4968 - name : Create Release
69+ if : github.event_name == 'push'
5070 uses : softprops/action-gh-release@v1
5171 with :
52- files : notate- ${{ github.ref_name }}.apk
72+ files : ${{ steps.apk-name.outputs.filename }}
5373 draft : true
5474 prerelease : false
5575 generate_release_notes : true
76+
77+ # ---------------------------------------------------------
78+ # PATH B: PULL REQUEST -> Upload Artifact & Comment
79+ # ---------------------------------------------------------
80+ - name : Upload APK as Artifact
81+ if : github.event_name == 'pull_request'
82+ id : upload-artifact
83+ uses : actions/upload-artifact@v4
84+ with :
85+ name : PR-Release-APK-${{ github.event.pull_request.number }}
86+ path : ${{ steps.apk-name.outputs.filename }}
87+ retention-days : 7
88+
89+ - name : Comment on PR with Artifact Link
90+ if : github.event_name == 'pull_request'
91+ uses : actions/github-script@v7
92+ env :
93+ ARTIFACT_URL : ${{ steps.upload-artifact.outputs.artifact-url }}
94+ with :
95+ script : |
96+ github.rest.issues.createComment({
97+ issue_number: context.issue.number,
98+ owner: context.repo.owner,
99+ repo: context.repo.repo,
100+ body: `✅ **APK Build Successful!**\n\nAn admin triggered a release build for this PR. You can download the generated APK here: [Download APK](${process.env.ARTIFACT_URL})`
101+ })
0 commit comments