Skip to content

Commit 8ba6bc6

Browse files
committed
Update to fix error of token
1 parent 5da4a8d commit 8ba6bc6

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

.github/workflows/auto-swap-labels.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,74 @@
22

33
name: Auto Swap Labels
44
on:
5-
pull_request_review:
6-
types: [submitted]
75
pull_request_target:
86
types: [ready_for_review, synchronize]
97
branches:
108
- main
9+
workflow_run:
10+
workflows: ["Review Trigger"]
11+
types: [completed]
1112

1213
permissions:
1314
pull-requests: write
1415
contents: read
16+
actions: read
1517

1618
jobs:
1719
check-approval:
1820
runs-on: ubuntu-latest
1921
if: >-
2022
github.repository == 'NVIDIA/Megatron-LM' &&
21-
github.event.pull_request.base.ref == 'main' &&
2223
(
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')
2529
)
2630
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+
2755
- name: Check out repository code
56+
if: steps.pr.outputs.number
2857
uses: actions/checkout@v4
2958

3059
- name: Set up Python
60+
if: steps.pr.outputs.number
3161
uses: actions/setup-python@v5
3262
with:
3363
python-version: "3.10"
3464

3565
- name: Install dependencies
66+
if: steps.pr.outputs.number
3667
run: |
3768
pip install --no-cache-dir PyGithub slack-sdk
3869
3970
- name: Run Auto Swap Labels
71+
if: steps.pr.outputs.number
4072
run: |
4173
export GH_TOKEN=${{ secrets.PAT }}
42-
export PR_NUMBER=${{ github.event.pull_request.number }}
74+
export PR_NUMBER=${{ steps.pr.outputs.number }}
4375
python tests/test_utils/python_scripts/swap_pr_labels.py
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# Lightweight workflow that triggers on review approval, otherwise there is no access to right secret.
4+
# No secrets needed — just signals auto-swap-labels.yml via workflow_run.
5+
6+
name: Review Trigger
7+
8+
on:
9+
pull_request_review:
10+
types: [submitted]
11+
12+
jobs:
13+
signal:
14+
runs-on: ubuntu-latest
15+
if: >-
16+
github.event.review.state == 'approved' &&
17+
github.event.pull_request.base.ref == 'main' &&
18+
github.repository == 'NVIDIA/Megatron-LM'
19+
steps:
20+
- name: Save PR number
21+
run: |
22+
mkdir -p pr
23+
echo "${{ github.event.pull_request.number }}" > pr/number
24+
- name: Upload PR number
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: pr-number
28+
path: pr/

0 commit comments

Comments
 (0)