|
2 | 2 |
|
3 | 3 | name: Auto Swap Labels |
4 | 4 | on: |
5 | | - pull_request_review: |
6 | | - types: [submitted] |
7 | 5 | pull_request_target: |
8 | 6 | types: [ready_for_review, synchronize] |
9 | 7 | branches: |
10 | 8 | - main |
| 9 | + workflow_run: |
| 10 | + workflows: ["Review Trigger"] |
| 11 | + types: [completed] |
11 | 12 |
|
12 | 13 | permissions: |
13 | 14 | pull-requests: write |
14 | 15 | contents: read |
| 16 | + actions: read |
15 | 17 |
|
16 | 18 | jobs: |
17 | 19 | check-approval: |
18 | 20 | runs-on: ubuntu-latest |
19 | 21 | if: >- |
20 | 22 | github.repository == 'NVIDIA/Megatron-LM' && |
21 | | - github.event.pull_request.base.ref == 'main' && |
22 | 23 | ( |
23 | | - (github.event_name == 'pull_request_review' && github.event.review.state == 'approved') || |
24 | | - (github.event_name == 'pull_request_target' && !github.event.pull_request.draft) |
| 24 | + (github.event_name == 'pull_request_target' && |
| 25 | + github.event.pull_request.base.ref == 'main' && |
| 26 | + !github.event.pull_request.draft) || |
| 27 | + (github.event_name == 'workflow_run' && |
| 28 | + github.event.workflow_run.conclusion == 'success') |
25 | 29 | ) |
26 | 30 | steps: |
| 31 | + - name: Get PR number from workflow_run |
| 32 | + id: get-pr |
| 33 | + if: github.event_name == 'workflow_run' |
| 34 | + continue-on-error: true |
| 35 | + uses: actions/download-artifact@v4 |
| 36 | + with: |
| 37 | + name: pr-number |
| 38 | + path: pr-number |
| 39 | + github-token: ${{ github.token }} |
| 40 | + run-id: ${{ github.event.workflow_run.id }} |
| 41 | + |
| 42 | + - name: Set PR number |
| 43 | + id: pr |
| 44 | + run: | |
| 45 | + if [ "${{ github.event_name }}" = "workflow_run" ]; then |
| 46 | + if [ "${{ steps.get-pr.outcome }}" != "success" ]; then |
| 47 | + echo "No approval artifact found — review was not an approval. Skipping." |
| 48 | + exit 0 |
| 49 | + fi |
| 50 | + echo "number=$(cat pr-number/number)" >> $GITHUB_OUTPUT |
| 51 | + else |
| 52 | + echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT |
| 53 | + fi |
| 54 | +
|
27 | 55 | - name: Check out repository code |
| 56 | + if: steps.pr.outputs.number |
28 | 57 | uses: actions/checkout@v4 |
29 | 58 |
|
30 | 59 | - name: Set up Python |
| 60 | + if: steps.pr.outputs.number |
31 | 61 | uses: actions/setup-python@v5 |
32 | 62 | with: |
33 | 63 | python-version: "3.10" |
34 | 64 |
|
35 | 65 | - name: Install dependencies |
| 66 | + if: steps.pr.outputs.number |
36 | 67 | run: | |
37 | 68 | pip install --no-cache-dir PyGithub slack-sdk |
38 | 69 |
|
39 | 70 | - name: Run Auto Swap Labels |
| 71 | + if: steps.pr.outputs.number |
40 | 72 | run: | |
41 | 73 | export GH_TOKEN=${{ secrets.PAT }} |
42 | | - export PR_NUMBER=${{ github.event.pull_request.number }} |
| 74 | + export PR_NUMBER=${{ steps.pr.outputs.number }} |
43 | 75 | python tests/test_utils/python_scripts/swap_pr_labels.py |
0 commit comments