Skip to content

Commit 0b0d4af

Browse files
committed
fix: checkout first, scope artifact download to subdirectory, skip bots on remove job
- Move checkout before artifact download so project files are established in the workspace before any untrusted artifact data lands, preventing potential file overwrites - Add path: artifact to download-artifact so the JSON file is scoped to a subdirectory instead of the workspace root; update readFileSync path accordingly - Add bot-skip condition to the remove job using workflow_run.triggering_actor.login so the job exits early for bot actors even if an artifact somehow exists Signed-off-by: Mounil Kanakhara <mounilkankhara@gmail.com>
1 parent bf256cc commit 0b0d4af

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

.github/workflows/on-review.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,20 @@ jobs:
6161
runs-on: hl-sdk-py-lin-md
6262
if: |
6363
github.event_name == 'workflow_run' &&
64-
github.event.workflow_run.conclusion == 'success'
64+
github.event.workflow_run.conclusion == 'success' &&
65+
!contains(github.event.workflow_run.triggering_actor.login, '[bot]')
6566
6667
steps:
6768
- name: Harden Runner
6869
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
6970
with:
7071
egress-policy: audit
7172

73+
- name: Checkout repository
74+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
75+
with:
76+
persist-credentials: false
77+
7278
- name: Check for review artifact
7379
id: check
7480
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
@@ -81,7 +87,7 @@ jobs:
8187
run_id: context.payload.workflow_run.id
8288
});
8389
const found = data.artifacts.some(a => a.name === name && !a.expired);
84-
if (!found) core.notice('Review artifact not found; capture job was likely skipped for a bot actor. Nothing to do.');
90+
if (!found) core.notice('Review artifact not found; capture job was likely skipped. Nothing to do.');
8591
core.setOutput('found', String(found));
8692
8793
- name: Download review metadata
@@ -91,20 +97,15 @@ jobs:
9197
name: review-data-${{ github.event.workflow_run.id }}
9298
run-id: ${{ github.event.workflow_run.id }}
9399
github-token: ${{ secrets.GITHUB_TOKEN }}
94-
95-
- name: Checkout repository
96-
if: steps.check.outputs.found == 'true'
97-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
98-
with:
99-
persist-credentials: false
100+
path: artifact
100101

101102
- name: Run Remove Reviewer from Assignees
102103
if: steps.check.outputs.found == 'true'
103104
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
104105
with:
105106
script: |
106107
const fs = require('fs');
107-
const raw = JSON.parse(fs.readFileSync('review.json', 'utf8'));
108+
const raw = JSON.parse(fs.readFileSync('artifact/review.json', 'utf8'));
108109
const reviewer = typeof raw.reviewer === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(raw.reviewer)
109110
? raw.reviewer : null;
110111
const prNumber = Number.isInteger(raw.pr_number) && raw.pr_number > 0

0 commit comments

Comments
 (0)