Skip to content

Commit 88cc16c

Browse files
chore(CI): enhance PR workflows with trusted PR check and permission adjustments (#2464)
* feat: enhance PR workflows with trusted PR check and permission adjustments * feat: specify secrets for trigger_builder in on-demand preview release workflow * feat: add required secrets for keystore and build JSON in nightly build workflow * add: check for keystore & build.json cleanup
1 parent c0b9f00 commit 88cc16c

2 files changed

Lines changed: 33 additions & 24 deletions

File tree

‎.github/workflows/nightly-build.yml‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
default: false
1616
type: boolean
1717
description: If a Pull Request has triggered it.
18+
is_trusted_pr:
19+
default: false
20+
type: boolean
21+
description: If a Pull Request is from the same repository, and not a forked one.
1822
PR_NUMBER:
1923
required: true
2024
type: number
@@ -24,6 +28,13 @@
2428
default: true
2529
type: boolean
2630
description: Skips Tagging & releases, since workflow_call isn't available for github.event_name, default is true
31+
secrets:
32+
KEYSTORE_CONTENT:
33+
required: true
34+
description: Base64 encoded keystore file content
35+
BUILD_JSON_CONTENT:
36+
required: true
37+
description: Base64 encoded build.json file content
2738
outputs:
2839
job_result:
2940
description: "Build job result"
@@ -59,7 +70,6 @@
5970
permissions:
6071
# contents write is needed to create Nightly Releases.
6172
contents: write
62-
# issues: write
6373
pull-requests: write
6474

6575
outputs:
@@ -118,6 +128,7 @@
118128
cache: ${{ (!(inputs.is_PR && inputs.PR_NUMBER) && github.ref == 'refs/heads/main' && 'npm') || '' }}
119129

120130
- name: Add keystore and build.json from secrets
131+
if: ${{ !inputs.is_PR || inputs.is_trusted_pr }}
121132
run: |
122133
echo "${{ secrets.KEYSTORE_CONTENT }}" | base64 -d > ${{ env.STORE_FILE_PATH }}
123134
echo "${{ secrets.BUILD_JSON_CONTENT }}" | base64 -d > ${{ env.BUILD_JSON_PATH }}
@@ -200,6 +211,7 @@
200211
path: ${{ env.FDROID_APK_PATH }}
201212

202213
- name: remove keystore and build.json
214+
if: ${{ !inputs.is_PR || inputs.is_trusted_pr }}
203215
run: |
204216
rm $STORE_FILE_PATH $BUILD_JSON_PATH
205217
echo "Keystore and build.json removed successfully."
@@ -265,18 +277,6 @@
265277
[Compare Changes](https://github.com/${{ github.repository }}/compare/${{ env.TAG_COMMIT }}...${{ github.sha }})
266278
267279
${{ env.RELEASE_NOTES }}
268-
269-
- name: Update Last Comment by bot (If ran in PR)
270-
if: inputs.is_PR
271-
uses: marocchino/sticky-pull-request-comment@v3
272-
with:
273-
hide_and_recreate: true
274-
hide_classify: "OUTDATED"
275-
header: on-demand-build-status
276-
message: |
277-
Preview Release for this, has been built.
278-
279-
[Click here to view that github actions build](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})
280280
281281
282282
community-release-notifier:

‎.github/workflows/on-demand-preview-releases-PR.yml‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
# defined at workflow-level as the workflow, Requires these permissions to function.
1111
permissions:
12-
contents: write
12+
contents: read
1313
pull-requests: write
1414
# All Pull Requests are issues, but not all issues are Pull Requests (like GitHub says 🙃)
1515
issues: write
@@ -39,8 +39,6 @@ jobs:
3939
clean: false
4040
fetch-depth: 0
4141
persist-credentials: false
42-
# Checkout pull request HEAD commit instead of merge commit
43-
ref: ${{ github.event.pull_request.head.sha }}
4442

4543
- name: Remove Manually added PR Label
4644
if: |
@@ -73,25 +71,36 @@ jobs:
7371

7472
trigger_builder:
7573
needs: job_trigger
76-
secrets: inherit
74+
secrets:
75+
KEYSTORE_CONTENT: ${{ secrets.KEYSTORE_CONTENT }}
76+
BUILD_JSON_CONTENT: ${{ secrets.BUILD_JSON_CONTENT }}
7777
uses: Acode-Foundation/acode/.github/workflows/nightly-build.yml@main
7878
with:
7979
is_PR: true
8080
PR_NUMBER: ${{ github.event.pull_request.number }}
81+
is_trusted_pr: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
8182
skip_tagging_and_releases: true
8283

8384
update_Last_Comment:
8485
needs: [job_trigger,trigger_builder]
8586
runs-on: ubuntu-latest
86-
if: ${{ github.repository_owner == 'Acode-Foundation' && always() && contains(fromJSON('["failure","cancelled"]'), needs.trigger_builder.result) }}
87+
if: ${{ github.repository_owner == 'Acode-Foundation' && always() && contains(fromJSON('["failure","cancelled", "success"]'), needs.trigger_builder.result) }}
8788
steps:
88-
# - name: Checkout code
89-
# uses: actions/checkout@v4
90-
# with:
91-
# clean: false
92-
# fetch-depth: 0
89+
90+
- name: Update Last Comment by bot (If Workflow Triggering succeeded)
91+
if: ${{ needs.trigger_builder.result == 'success' && github.event.pull_request.number }}
92+
uses: marocchino/sticky-pull-request-comment@v3
93+
with:
94+
hide_and_recreate: true
95+
hide_classify: "OUTDATED"
96+
header: on-demand-build-status
97+
message: |
98+
Preview Release for this, has been built.
99+
100+
[Click here to view that github actions build](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})
93101

94102
- name: Update Last Comment by bot (if Workflow Triggering failed)
103+
if: ${{ needs.trigger_builder.result != 'success' && github.event.pull_request.number }}
95104
uses: marocchino/sticky-pull-request-comment@v3
96105
with:
97106
hide_and_recreate: true
@@ -102,4 +111,4 @@ jobs:
102111
status: **${{ needs.trigger_builder.result || 'failure'}}**
103112
104113
---
105-
For Owners: Please [Click here to view that github actions](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})
114+
Please [Click here to view that github actions](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})

0 commit comments

Comments
 (0)