Skip to content

Commit da29eea

Browse files
leofangchainer-ci
authored andcommitted
Merge pull request #10190 from leofang/ci/pfnci-followups
CI: PFN/FlexCI follow-ups on top of #10058
1 parent 82dea1c commit da29eea

9 files changed

Lines changed: 199 additions & 260 deletions

File tree

‎.github/workflows/backport.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ jobs:
3232
run: |
3333
pip install pygithub
3434
35+
# TODO(leofang): the backport bot (cupy/backport) copies the source PR's
36+
# labels onto the backport PR, so ci:triggered leaks over and immediately
37+
# triggers CI on the fresh backport PR. Strip it from the source PR here,
38+
# before the bot reads the labels (same workflow, so no race with
39+
# ci-trigger.yml). Move this elsewhere when this workflow is retired.
40+
- name: Strip ci:triggered before backporting
41+
env:
42+
GH_TOKEN: ${{ secrets.BACKPORT_TOKEN }}
43+
run: |
44+
gh api --method DELETE \
45+
"repos/${{ github.repository }}/issues/${{ github.event.number }}/labels/ci:triggered" || true
46+
3547
- name: Run Backport
3648
env:
3749
GH_TOKEN: ${{secrets.BACKPORT_TOKEN}}

‎.github/workflows/ci-trigger.yml‎

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
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
@@ -44,6 +50,7 @@ jobs:
4450
run: |
4551
set -euo pipefail
4652
ok=false
53+
skip_mode=false
4754
pr_number=""
4855
head_sha=""
4956
base_ref=""
@@ -52,6 +59,21 @@ jobs:
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'

‎.github/workflows/ci.yml‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ on:
3333
- "hotfix-*"
3434

3535
concurrency:
36-
# Labeled builds share ci-build-<PR> with ci-trigger.yml's hygiene runs: a
37-
# second /test supersedes the first build, and any push cancels it. Push
38-
# runs get a per-commit group (i.e. effectively none): a burst of merges
39-
# must not cancel intermediate runs, each of which carries its own FlexCI
40-
# dispatch.
41-
group: ${{ github.event_name == 'pull_request' && format('ci-build-{0}', github.event.pull_request.number) || format('ci-push-{0}', github.sha) }}
42-
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
36+
# Only the ci:triggered build shares ci-build-<PR> (with ci-trigger.yml's
37+
# hygiene runs): a second /test supersedes the first build, and a push to the
38+
# PR cancels it via hygiene. Every labeled event runs this workflow (GitHub
39+
# can't filter `labeled` by name), so any OTHER label must land in a unique,
40+
# throwaway group -- otherwise it would enter ci-build-<PR> and cancel the
41+
# in-flight vouched build before the guard no-ops it (concurrency is evaluated
42+
# at queue time, ahead of the guard job). Push runs get a per-commit group
43+
# (i.e. effectively none): a burst of merges must not cancel intermediate
44+
# runs, each of which carries its own FlexCI dispatch.
45+
group: ${{ github.event_name == 'push' && format('ci-push-{0}', github.sha) || github.event.label.name == 'ci:triggered' && format('ci-build-{0}', github.event.pull_request.number) || format('ci-noop-{0}', github.run_id) }}
46+
cancel-in-progress: ${{ github.event.label.name == 'ci:triggered' }}
4347

4448
# Least privilege: read-only by default; jobs that need more grant it
4549
# per-job below (only dispatch-flexci writes, via flexci_dispatcher.py).

‎.github/workflows/flexci.yml‎

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,11 @@ name: "FlexCI"
88
# untrusted pull_request runs from a trusted context.
99
#
1010
# Post-merge dispatch does NOT go through the workflow_run leg: it lives in
11-
# ci.yml's push leg (single trusted run, plain `needs:` ordering). The
12-
# TEMPORARY legacy job below covers merges into bases that have not yet been
13-
# backported the new push workflow.
11+
# ci.yml's push leg (single trusted run, plain `needs:` ordering).
1412
on:
1513
workflow_run:
1614
workflows: ["CI"]
1715
types: [completed]
18-
# TEMPORARY (inert once every active release base carries the new push
19-
# workflow -- delete at leisure after that): legacy post-merge dispatch
20-
# for bases whose branches do not yet carry it. pull_request_target runs
21-
# the default branch's copy of this file (GitHub, 2025-12-08), so this
22-
# works regardless of the base branch's contents.
23-
pull_request_target:
24-
types: [closed]
2516

2617
# Least privilege: read-only by default; each job below elevates explicitly.
2718
permissions:
@@ -177,95 +168,3 @@ jobs:
177168
--external-tag jenkins \
178169
--external-tag rocm
179170
done
180-
181-
# TEMPORARY legacy post-merge dispatch (see the trigger comment above).
182-
# Instead of hard-coding which bases still need it, the probe step checks
183-
# the merge commit's own tree for the new build+dispatch workflow: the
184-
# push run for this merge used exactly those files, so "file present"
185-
# means that run dispatches and this job must stay quiet. The handoff is
186-
# atomic -- the very backport merge that brings the workflow to a base is
187-
# already dispatched by its own push run -- so double dispatch and missed
188-
# dispatch are both impossible by construction.
189-
legacy-dispatch:
190-
name: Dispatch FlexCI (legacy, bases without the new push workflow)
191-
if: |
192-
github.repository_owner == 'cupy' &&
193-
github.event_name == 'pull_request_target' &&
194-
github.event.pull_request.merged &&
195-
!contains(github.event.pull_request.labels.*.name, 'skip-ci') &&
196-
github.event.pull_request.base.ref != github.event.repository.default_branch
197-
runs-on: ubuntu-22.04
198-
permissions:
199-
contents: read # probe reads ci.yml at merge SHA + checkout
200-
pull-requests: write # flexci_dispatcher.py force-skip comments
201-
statuses: write # flexci_dispatcher.py commit statuses
202-
steps:
203-
- name: Check whether this merge dispatches for itself
204-
id: probe
205-
env:
206-
GH_TOKEN: ${{ github.token }}
207-
MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
208-
BASE_REF: ${{ github.event.pull_request.base.ref }}
209-
run: |
210-
set -euo pipefail
211-
# The push run only exists at all for bases matched by ci.yml's
212-
# push branch filter (keep this case list in sync with it); for
213-
# any other base, carrying the file changes nothing. Unlike bash
214-
# globs, Actions branch patterns never cross '/', hence the first
215-
# arm.
216-
case "${BASE_REF}" in
217-
*/*)
218-
echo "legacy=true" >> "$GITHUB_OUTPUT"
219-
exit 0
220-
;;
221-
v*|hotfix-*) ;;
222-
*)
223-
echo "legacy=true" >> "$GITHUB_OUTPUT"
224-
exit 0
225-
;;
226-
esac
227-
# Tolerate exactly HTTP 404 ("no new workflow there" -> dispatch
228-
# legacy-style); any other failure must abort visibly rather than
229-
# guess in either direction.
230-
if out="$(gh api "repos/${GITHUB_REPOSITORY}/contents/.github/workflows/ci.yml?ref=${MERGE_SHA}" 2>&1)"; then
231-
echo "legacy=false" >> "$GITHUB_OUTPUT"
232-
elif grep -q "HTTP 404" <<< "${out}"; then
233-
echo "legacy=true" >> "$GITHUB_OUTPUT"
234-
else
235-
echo "${out}" >&2
236-
exit 1
237-
fi
238-
239-
- name: Checkout
240-
if: steps.probe.outputs.legacy == 'true'
241-
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
242-
with:
243-
ref: ${{ github.event.pull_request.merge_commit_sha }}
244-
# Deliberate security decision (checkout v7 refuses fork-PR code
245-
# under pull_request_target by default, merge_commit_sha included):
246-
# this job only runs for MERGED PRs, so the commit is reviewed code
247-
# already landed on the base branch.
248-
allow-unsafe-pr-checkout: true
249-
250-
- name: Setup Python
251-
if: steps.probe.outputs.legacy == 'true'
252-
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
253-
with:
254-
python-version: '3.13'
255-
256-
- name: Setup Environment
257-
if: steps.probe.outputs.legacy == 'true'
258-
run: pip install pygithub
259-
260-
- name: Dispatch
261-
if: steps.probe.outputs.legacy == 'true'
262-
env:
263-
GITHUB_TOKEN: ${{ github.token }}
264-
FLEXCI_WEBHOOK_SECRET: ${{ secrets.FLEXCI_WEBHOOK_SECRET }}
265-
run: |
266-
./.github/workflows/scripts/flexci_dispatcher.py \
267-
--event "${GITHUB_EVENT_NAME}" \
268-
--webhook "${GITHUB_EVENT_PATH}" \
269-
--projects ".pfnci/config.tags.json" \
270-
--external-tag jenkins \
271-
--external-tag rocm

‎.github/workflows/self-hosted-ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
) && (
2121
github.event.comment.author_association == 'OWNER' ||
2222
github.event.comment.author_association == 'MEMBER' ||
23-
contains('|gpinkert|', github.event.comment.user.login)
23+
contains('|gpinkert|', format('|{0}|', github.event.comment.user.login))
2424
) && (
2525
contains(github.event.comment.body, '/test ')
2626
)

0 commit comments

Comments
 (0)