Skip to content

Commit dfb4dfa

Browse files
authored
fix(ci): grant pull-requests write to comment-gateway feedback jobs (#2720)
1 parent cc92260 commit dfb4dfa

7 files changed

Lines changed: 537 additions & 107 deletions

File tree

‎.github/workflows/comment-ci-command.yml‎

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ jobs:
8383
# Actions-capability commands: /rerun-failed-ci and /rerun-test <test-file>.
8484
actions-command:
8585
needs: handle-command
86-
outputs:
87-
workflow_run_url: ${{ steps.run-command.outputs.workflow_run_url }}
8886
if: needs.handle-command.outputs.capability == 'actions'
8987
concurrency:
9088
group: comment-ci-actions-${{ github.event.issue.number }}
@@ -108,7 +106,6 @@ jobs:
108106
sparse-checkout-cone-mode: false
109107

110108
- name: Authorize and run the actions command
111-
id: run-command
112109
env:
113110
CI_COMMAND_API_TOKEN: ${{ github.token }}
114111
CI_COMMAND_POLICY_PATH: .github/workflows/policies/comment-command-access.json
@@ -119,9 +116,13 @@ jobs:
119116
if: >-
120117
needs.actions-command.result == 'success' &&
121118
needs.handle-command.outputs.success_reaction == '+1'
119+
# The reaction lands on a pull-request comment, and GitHub gates
120+
# issues-API calls whose target issue is a PR on pull-requests scope,
121+
# so issues: write alone returns 403.
122122
permissions:
123123
contents: read
124124
issues: write
125+
pull-requests: write
125126
runs-on: ubuntu-latest
126127
timeout-minutes: 5
127128
steps:
@@ -138,29 +139,3 @@ jobs:
138139
CI_COMMAND_API_TOKEN: ${{ github.token }}
139140
CI_COMMAND_ACKNOWLEDGE: "true"
140141
run: python3 .github/workflows/scripts/comment_ci_command.py
141-
142-
reply-command:
143-
needs: actions-command
144-
if: >-
145-
needs.actions-command.result == 'success' &&
146-
needs.actions-command.outputs.workflow_run_url != ''
147-
permissions:
148-
contents: read
149-
issues: write
150-
runs-on: ubuntu-latest
151-
timeout-minutes: 5
152-
steps:
153-
- name: Check out the trusted handler
154-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
155-
with:
156-
ref: ${{ github.sha }}
157-
persist-credentials: false
158-
sparse-checkout: .github/workflows/scripts/comment_ci_command.py
159-
sparse-checkout-cone-mode: false
160-
161-
- name: Reply with the workflow run
162-
env:
163-
CI_COMMAND_API_TOKEN: ${{ github.token }}
164-
CI_COMMAND_REPLY: "true"
165-
CI_COMMAND_WORKFLOW_RUN_URL: ${{ needs.actions-command.outputs.workflow_run_url }}
166-
run: python3 .github/workflows/scripts/comment_ci_command.py

‎.github/workflows/run-ci-file.yml‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,38 @@ concurrency:
4747
queue: max
4848

4949
jobs:
50+
# The run owns its own status comment: it is the only party that knows when
51+
# execution starts, how long it takes, and how it ends. Announcing here
52+
# (rather than from the gateway's reply) also covers direct dispatches.
53+
announce-file-run:
54+
runs-on: ubuntu-latest
55+
timeout-minutes: 5
56+
outputs:
57+
comment_id: ${{ steps.announce.outputs.comment_id }}
58+
permissions:
59+
contents: read
60+
issues: write
61+
pull-requests: write
62+
steps:
63+
- name: Check out the trusted reporter
64+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
65+
with:
66+
persist-credentials: false
67+
sparse-checkout: .github/workflows/scripts/comment_ci_command.py
68+
sparse-checkout-cone-mode: false
69+
70+
- name: Announce the file run on its pull request
71+
id: announce
72+
env:
73+
CI_COMMAND_API_TOKEN: ${{ github.token }}
74+
CI_COMMAND_FILE_RUN_STATUS: announce
75+
FILE_RUN_PULL_NUMBER: ${{ inputs.pull_number }}
76+
FILE_RUN_TEST_FILE: ${{ inputs.test_file }}
77+
FILE_RUN_RUN_ID: ${{ github.run_id }}
78+
run: python3 .github/workflows/scripts/comment_ci_command.py
79+
5080
resolve-file-run:
81+
needs: announce-file-run
5182
runs-on: ubuntu-latest
5283
timeout-minutes: 10
5384
outputs:
@@ -134,3 +165,37 @@ jobs:
134165
pytest '${{ inputs.test_file }}' -v -x
135166
secrets:
136167
HF_TOKEN: ${{ needs.resolve-file-run.outputs.head_is_fork != 'true' && secrets.HF_TOKEN || '' }}
168+
169+
# No `if` beyond always(): a resolver failure, a cancelled run, and a failing
170+
# test must all reach the pull request, or a silent run reads as a pass.
171+
report-file-run:
172+
needs: [announce-file-run, resolve-file-run, run-cuda-file, run-cpu-file]
173+
if: always()
174+
permissions:
175+
actions: read
176+
contents: read
177+
issues: write
178+
pull-requests: write
179+
runs-on: ubuntu-latest
180+
timeout-minutes: 5
181+
steps:
182+
- name: Check out the trusted reporter
183+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
184+
with:
185+
persist-credentials: false
186+
sparse-checkout: .github/workflows/scripts/comment_ci_command.py
187+
sparse-checkout-cone-mode: false
188+
189+
- name: Report the file run's result on its pull request
190+
env:
191+
CI_COMMAND_API_TOKEN: ${{ github.token }}
192+
CI_COMMAND_FILE_RUN_STATUS: report
193+
FILE_RUN_COMMENT_ID: ${{ needs.announce-file-run.outputs.comment_id }}
194+
FILE_RUN_PULL_NUMBER: ${{ inputs.pull_number }}
195+
FILE_RUN_TEST_FILE: ${{ inputs.test_file }}
196+
FILE_RUN_RUN_ID: ${{ github.run_id }}
197+
FILE_RUN_SUITE: ${{ needs.resolve-file-run.outputs.suite }}
198+
FILE_RUN_RESOLVE_RESULT: ${{ needs.resolve-file-run.result }}
199+
FILE_RUN_CUDA_RESULT: ${{ needs.run-cuda-file.result }}
200+
FILE_RUN_CPU_RESULT: ${{ needs.run-cpu-file.result }}
201+
run: python3 .github/workflows/scripts/comment_ci_command.py

0 commit comments

Comments
 (0)