Skip to content

Commit a2dd8d4

Browse files
feat: enhance PR workflows with trusted PR check and permission adjustments
1 parent c0b9f00 commit a2dd8d4

2 files changed

Lines changed: 22 additions & 23 deletions

File tree

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

Lines changed: 5 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
@@ -59,7 +63,6 @@
5963
permissions:
6064
# contents write is needed to create Nightly Releases.
6165
contents: write
62-
# issues: write
6366
pull-requests: write
6467

6568
outputs:
@@ -118,6 +121,7 @@
118121
cache: ${{ (!(inputs.is_PR && inputs.PR_NUMBER) && github.ref == 'refs/heads/main' && 'npm') || '' }}
119122

120123
- name: Add keystore and build.json from secrets
124+
if: ${{ !inputs.is_PR || inputs.is_trusted_pr }}
121125
run: |
122126
echo "${{ secrets.KEYSTORE_CONTENT }}" | base64 -d > ${{ env.STORE_FILE_PATH }}
123127
echo "${{ secrets.BUILD_JSON_CONTENT }}" | base64 -d > ${{ env.BUILD_JSON_PATH }}
@@ -265,18 +269,6 @@
265269
[Compare Changes](https://github.com/${{ github.repository }}/compare/${{ env.TAG_COMMIT }}...${{ github.sha }})
266270
267271
${{ 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 }})
280272
281273
282274
community-release-notifier:

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

Lines changed: 17 additions & 10 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: |
@@ -78,20 +76,29 @@ jobs:
7876
with:
7977
is_PR: true
8078
PR_NUMBER: ${{ github.event.pull_request.number }}
79+
is_trusted_pr: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
8180
skip_tagging_and_releases: true
8281

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

94100
- name: Update Last Comment by bot (if Workflow Triggering failed)
101+
if: ${{ needs.trigger_builder.result != 'success' && github.event.pull_request.number }}
95102
uses: marocchino/sticky-pull-request-comment@v3
96103
with:
97104
hide_and_recreate: true
@@ -102,4 +109,4 @@ jobs:
102109
status: **${{ needs.trigger_builder.result || 'failure'}}**
103110
104111
---
105-
For Owners: Please [Click here to view that github actions](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})
112+
Please [Click here to view that github actions](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})

0 commit comments

Comments
 (0)