Skip to content

Commit 1ed7108

Browse files
committed
workflows: Reconfigure pr-subscriber action so that it can access secrets
Secrets are not available for workflows triggered by PRs, so we need to split the pr-subscriber action into two separate actions. The first will listen for new labels on PRs and the second will add a comment with the team mention. See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
1 parent 1d0d57e commit 1ed7108

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
2+
3+
name: PR Receive Label
4+
on:
5+
pull_request:
6+
types:
7+
- labeled
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
pr-subscriber:
14+
runs-on: ubuntu-latest
15+
if: github.repository == 'llvm/llvm-project'
16+
steps:
17+
- name: Store PR Information
18+
run: |
19+
mkdir -p ./pr
20+
echo ${{ github.event.number }} > ./pr/NR
21+
echo ${{ github.event.label.name }} > ./pr/LABEL
22+
23+
- uses: actions/upload-artifact@v3
24+
with:
25+
name: pr
26+
path: pr/

.github/workflows/pr-subscriber.yml

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,61 @@
11
name: PR Subscriber
22

33
on:
4-
pull_request:
4+
workflow_run:
5+
workflows: ["PR Receive Label"]
56
types:
6-
- labeled
7+
- completed
78

89
permissions:
910
contents: read
1011

1112
jobs:
1213
auto-subscribe:
1314
runs-on: ubuntu-latest
14-
if: github.repository == 'llvm/llvm-project'
15+
if: >
16+
github.repository == 'llvm/llvm-project' &&
17+
github.event.workflow_run.event == 'pull_request' &&
18+
github.event.workflow_run.conclusion == 'success'
1519
steps:
20+
# From: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
21+
# Updated version here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
22+
- name: 'Download artifact'
23+
uses: actions/github-script@v6
24+
with:
25+
script: |
26+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
run_id: context.payload.workflow_run.id,
30+
});
31+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
32+
return artifact.name == "pr"
33+
})[0];
34+
var download = await github.rest.actions.downloadArtifact({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
artifact_id: matchArtifact.id,
38+
archive_format: 'zip',
39+
});
40+
var fs = require('fs');
41+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
42+
43+
- run: unzip pr.zip
44+
1645
- name: Setup Automation Script
1746
run: |
18-
curl -O -L https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$GITHUB_SHA/llvm/utils/git/github-automation.py
19-
curl -O -L https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$GITHUB_SHA/llvm/utils/git/requirements.txt
47+
curl -O -L https://raw.githubusercontent.com/$GITHUB_REPOSITORY/main/llvm/utils/git/github-automation.py
48+
curl -O -L https://raw.githubusercontent.com/$GITHUB_REPOSITORY/main/llvm/utils/git/requirements.txt
2049
chmod a+x github-automation.py
2150
pip install -r requirements.txt
2251
2352
- name: Update watchers
2453
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
25-
env:
26-
LABEL_NAME: ${{ github.event.label.name }}
2754
run: |
55+
PR_NUMBER=`cat NR`
56+
LABEL_NAME=`cat LABEL`
2857
./github-automation.py \
29-
--token '${{ secrets.ISSUE_SUBSCRIBER_TOKEN }}' \
30-
pr-subscriber \
31-
--issue-number '${{ github.event.pull_request.number }}' \
32-
--label-name "$LABEL_NAME"
58+
--token '${{ secrets.ISSUE_SUBSCRIBER_TOKEN }}' \
59+
pr-subscriber \
60+
--issue-number "$PR_NUMBER" \
61+
--label-name "$LABEL_NAME"

0 commit comments

Comments
 (0)