3636 concurrency :
3737 group : ci-trigger-${{ github.event.issue.number }}
3838 cancel-in-progress : false
39+ outputs :
40+ ok : ${{ steps.guard.outputs.ok }}
41+ skip_mode : ${{ steps.guard.outputs.skip_mode }}
42+ pr_number : ${{ steps.guard.outputs.pr_number }}
43+ head_sha : ${{ steps.guard.outputs.head_sha }}
44+ base_ref : ${{ steps.guard.outputs.base_ref }}
3945 steps :
4046 - name : Validate the /test request
4147 id : guard
4450 run : |
4551 set -euo pipefail
4652 ok=false
53+ skip_mode=false
4754 pr_number=""
4855 head_sha=""
4956 base_ref=""
5259 elif ! jq -r '.comment.body' "$GITHUB_EVENT_PATH" | grep -qE '^/test[[:space:]]+[^[:space:]]'; then
5360 echo "Comment does not start with '/test <target>'; skipping"
5461 else
62+ # A /test skip | force-skip needs no wheel build -- the dispatcher
63+ # just posts "skipped" (force-skip: override) statuses. Flag it so
64+ # the build leg is short-circuited (see the dispatch-skip job); a
65+ # real /test <target> falls through to the label bounce and builds.
66+ # Read the FIRST /test line only, matching what the dispatcher acts
67+ # on (flexci_dispatcher.extract_requested_tags returns the first
68+ # match): otherwise a comment like "/test cuda120" then "/test skip"
69+ # would bypass the build while the dispatcher forwards cuda120 with
70+ # no wheel. A first line that is not exactly skip/force-skip leaves
71+ # skip_mode false -> build-then-skip, the safe fallback.
72+ first_test="$(jq -r '.comment.body' "$GITHUB_EVENT_PATH" \
73+ | grep -m1 -E '^/test[[:space:]]+[^[:space:]]' || true)"
74+ if [[ "${first_test}" =~ ^/test[[:space:]]+(skip|force-skip)[[:space:]]*$ ]]; then
75+ skip_mode=true
76+ fi
5577 assoc="$(jq -r '.comment.author_association' "$GITHUB_EVENT_PATH")"
5678 if [[ "$assoc" != "OWNER" && "$assoc" != "MEMBER" ]]; then
5779 echo "::warning::Comment author_association=$assoc is not OWNER/MEMBER; skipping"
@@ -69,11 +91,18 @@ jobs:
6991 fi
7092 {
7193 echo "ok=${ok}"
94+ echo "skip_mode=${skip_mode}"
7295 echo "pr_number=${pr_number}"
7396 echo "head_sha=${head_sha}"
7497 echo "base_ref=${base_ref}"
7598 } >> "$GITHUB_OUTPUT"
7699
100+ # Recorded for BOTH paths: the build path (flexci.yml dispatches it
101+ # post-build) and skip. Skip uploads too so its request overwrites a
102+ # prior /test <target>'s (same dispatch-request-<pr>-<sha> name,
103+ # overwrite: true) -- then if that target's build already finished,
104+ # flexci.yml picks this skip request as newest and skips instead of
105+ # dispatching the stale target.
77106 - name : Save the dispatch request payload
78107 if : steps.guard.outputs.ok == 'true'
79108 env :
@@ -104,14 +133,14 @@ jobs:
104133 # secret CI_TRIGGER_APP_PRIVATE_KEY.
105134 - name : Mint CI-trigger App token
106135 id : app-token
107- if : steps.guard.outputs.ok == 'true'
136+ if : steps.guard.outputs.ok == 'true' && steps.guard.outputs.skip_mode != 'true'
108137 uses : actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
109138 with :
110139 app-id : ${{ vars.CI_TRIGGER_APP_ID }}
111140 private-key : ${{ secrets.CI_TRIGGER_APP_PRIVATE_KEY }}
112141
113142 - name : Bounce the ci:triggered label
114- if : steps.guard.outputs.ok == 'true'
143+ if : steps.guard.outputs.ok == 'true' && steps.guard.outputs.skip_mode != 'true'
115144 env :
116145 GH_TOKEN : ${{ steps.app-token.outputs.token }}
117146 PR_NUMBER : ${{ steps.guard.outputs.pr_number }}
@@ -133,13 +162,115 @@ jobs:
133162 "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" \
134163 -f "labels[]=ci:triggered" >/dev/null
135164
165+ # Leg 1b of the /test flow: a /test skip | force-skip needs no wheel, so
166+ # short-circuit the build -- run the dispatcher HERE to post the "skipped"
167+ # (or force-skip override) statuses, and deliberately do NOT bounce
168+ # ci:triggered, so ci.yml never builds. This restores the old FlexCI, where
169+ # skip was instant. A real /test <target> instead bounces the label above
170+ # and its wheel is built then dispatched post-build in flexci.yml.
171+ dispatch-skip :
172+ name : Post skipped statuses (no build)
173+ needs : test-request
174+ if : |
175+ github.repository_owner == 'cupy' &&
176+ needs.test-request.outputs.ok == 'true' &&
177+ needs.test-request.outputs.skip_mode == 'true'
178+ runs-on : ubuntu-latest
179+ # Join ci.yml's build concurrency group: a /test skip issued while an
180+ # earlier /test <target> is still building cancels that in-flight build,
181+ # and a cancelled build has conclusion != success, so flexci.yml never
182+ # dispatches the superseded target. (The label-bounce path gets this for
183+ # free -- its rebuild enters the same group; the skip path must opt in.)
184+ concurrency :
185+ group : ci-build-${{ github.event.issue.number }}
186+ cancel-in-progress : true
187+ # A separate job (not a step in test-request) so it gets its own
188+ # statuses/PR-write token without the app-scoped ci-trigger environment.
189+ permissions :
190+ contents : read # checkout the dispatcher + config.tags.json
191+ statuses : write # flexci_dispatcher.py writes commit statuses
192+ pull-requests : write # dispatcher reads PR head + posts force-skip note
193+ steps :
194+ - name : Pin to the vouched head and base
195+ id : pin
196+ env :
197+ GH_TOKEN : ${{ github.token }}
198+ PR_NUMBER : ${{ needs.test-request.outputs.pr_number }}
199+ VOUCHED_HEAD : ${{ needs.test-request.outputs.head_sha }}
200+ VOUCHED_BASE : ${{ needs.test-request.outputs.base_ref }}
201+ run : |
202+ set -euo pipefail
203+ # Head+base pin, mirroring flexci.yml's dispatch job: post skipped
204+ # statuses only if the PR still points at the head AND base the /test
205+ # comment vouched. The dispatcher writes statuses to the PR's *current*
206+ # head, so a push (new head) or a retarget (new base) landing between
207+ # the comment and this job would otherwise stamp skipped (green)
208+ # statuses onto an unvouched commit or under the wrong base.
209+ pr_json="$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}")"
210+ current_head="$(jq -r '.head.sha' <<< "${pr_json}")"
211+ current_base="$(jq -r '.base.ref' <<< "${pr_json}")"
212+ if [[ "${current_head}" != "${VOUCHED_HEAD}" ]]; then
213+ echo "::warning::PR #${PR_NUMBER} moved (${VOUCHED_HEAD} -> ${current_head}) since /test skip; re-issue the command."
214+ echo "moved=true" >> "$GITHUB_OUTPUT"
215+ elif [[ "${current_base}" != "${VOUCHED_BASE}" ]]; then
216+ echo "::warning::PR #${PR_NUMBER} was retargeted (${VOUCHED_BASE} -> ${current_base}) since /test skip; re-issue the command."
217+ echo "moved=true" >> "$GITHUB_OUTPUT"
218+ else
219+ echo "moved=false" >> "$GITHUB_OUTPUT"
220+ fi
221+
222+ - name : Checkout (dispatcher + project map, trusted default branch)
223+ if : steps.pin.outputs.moved != 'true'
224+ uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
225+
226+ - name : Setup Python
227+ if : steps.pin.outputs.moved != 'true'
228+ uses : actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
229+ with :
230+ python-version : ' 3.13'
231+
232+ - name : Setup Environment
233+ if : steps.pin.outputs.moved != 'true'
234+ run : pip install pygithub
235+
236+ - name : Post skipped statuses (no dispatch, no build)
237+ if : steps.pin.outputs.moved != 'true'
238+ env :
239+ GITHUB_TOKEN : ${{ github.token }}
240+ # Unused on the skip path (nothing is forwarded to FlexCI), but the
241+ # dispatcher reads it at startup, so pass it to match the flexci.yml
242+ # invocation. Repo-level secret (flexci.yml consumes it with no
243+ # environment), so this environment-less job can read it too.
244+ FLEXCI_WEBHOOK_SECRET : ${{ secrets.FLEXCI_WEBHOOK_SECRET }}
245+ run : |
246+ set -euo pipefail
247+ # Same issue_comment payload the guard vetted; for skip/force-skip
248+ # the dispatcher posts statuses and forwards nothing. config.tags.json
249+ # is the trusted default-branch copy -- a PR must not get to redefine
250+ # which contexts are marked skipped.
251+ ./.github/workflows/scripts/flexci_dispatcher.py \
252+ --event issue_comment \
253+ --webhook "${GITHUB_EVENT_PATH}" \
254+ --projects .pfnci/config.tags.json \
255+ --external-tag jenkins \
256+ --external-tag rocm
257+
136258 # Hygiene: a push to the PR (synchronize) or a reopen clears a stale
137259 # ci:triggered label, so its presence keeps meaning "the current head was
138260 # vouched". On synchronize, merely ENTERING the shared ci-build-<PR>
139261 # concurrency group (also used by ci.yml's labeled build runs; concurrency
140262 # groups are repo-scoped strings shared across workflows) cancels any
141263 # in-flight build for the superseded head. This runs the default branch's
142264 # workflow copy with a writable token and checks out no PR code.
265+ #
266+ # This deliberately does NOT fire on close/merge: a merged PR's ci:triggered
267+ # is stripped in backport.yml (before the backport bot copies the source
268+ # labels), not here -- doing it here would race the backport workflow, which
269+ # runs on the same pull_request_target: closed event.
270+ # TODO(leofang): when backporting is retired and backport.yml is removed,
271+ # nothing races this hygiene job on close anymore -- at that point move the
272+ # ci:triggered cleanup here: add `closed` to the pull_request_target trigger
273+ # above and clear the label on merge in this job.
143274 hygiene :
144275 name : Clear stale label
145276 if : github.repository_owner == 'cupy' && github.event_name == 'pull_request_target'
0 commit comments