|
1 | 1 | name: PR Subscriber
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - pull_request: |
| 4 | + workflow_run: |
| 5 | + workflows: ["PR Receive Label"] |
5 | 6 | types:
|
6 |
| - - labeled |
| 7 | + - completed |
7 | 8 |
|
8 | 9 | permissions:
|
9 | 10 | contents: read
|
10 | 11 |
|
11 | 12 | jobs:
|
12 | 13 | auto-subscribe:
|
13 | 14 | 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' |
15 | 19 | 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 | + |
16 | 45 | - name: Setup Automation Script
|
17 | 46 | 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 |
20 | 49 | chmod a+x github-automation.py
|
21 | 50 | pip install -r requirements.txt
|
22 | 51 |
|
23 | 52 | - name: Update watchers
|
24 | 53 | # 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 }} |
27 | 54 | run: |
|
| 55 | + PR_NUMBER=`cat NR` |
| 56 | + LABEL_NAME=`cat LABEL` |
28 | 57 | ./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