Skip to content

Commit bd111f3

Browse files
authored
tools: add resume-ci label handling
Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #65945 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 964e668 commit bd111f3

3 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎.github/workflows/auto-start-ci.yml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This action uses the following secrets:
22
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3-
# JENKINS_TOKEN: Jenkins token, to be used to start CI
3+
# JENKINS_TOKEN: Jenkins token, to be used to start or resume CI
44
name: Auto Start CI
55

66
on:
@@ -30,14 +30,14 @@ jobs:
3030
steps:
3131
- name: Get Pull Requests
3232
id: get_prs_for_ci
33-
run: >
34-
echo "numbers=$(gh pr list \
33+
run: |
34+
numbers=$(gh pr list \
3535
--repo "$GITHUB_REPOSITORY" \
36-
--label 'request-ci' \
3736
--json 'number' \
38-
--search 'review:approved' \
37+
--search 'review:approved label:request-ci,resume-ci' \
3938
-t '{{ range . }}{{ .number }} {{ end }}' \
40-
--limit 5)" >> "$GITHUB_OUTPUT"
39+
--limit 5)
40+
echo "numbers=$numbers" >> "$GITHUB_OUTPUT"
4141
env:
4242
GH_TOKEN: ${{ github.token }}
4343
start-ci:
@@ -70,7 +70,7 @@ jobs:
7070
GH_TOKEN: ${{ github.token }}
7171
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
7272

73-
- name: Start the CI
73+
- name: Start or resume the CI
7474
run: |
7575
read -r -a numbers <<< "$PULL_REQUESTS"
7676
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \

‎doc/contributing/collaborator-guide.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,21 @@ Once this label is added, `github-actions bot` will start
391391
the `node-test-pull-request` automatically. If the `github-actions bot`
392392
is unable to start the job, it will update the label with `request-ci-failed`.
393393

394+
To resume an existing CI run, add the `resume-ci` label to the pull request.
395+
As with `request-ci`, the pull request must have an approving review. The bot
396+
removes `resume-ci` when processing the request. If it cannot resume the job, it
397+
adds `resume-ci-failed` and posts the command output with a link to the workflow
398+
run.
399+
400+
Do not combine `request-ci` and `resume-ci`. If both labels are present, the bot
401+
removes both, adds `request-ci-failed` and `resume-ci-failed`, and reports the
402+
conflict once without starting or resuming CI.
403+
404+
The job must be failed or aborted and resumable, and its CI-approved commit must
405+
still match the pull request's HEAD. Resuming is refused when available failure
406+
diagnostics reference files changed by the pull request. Use `request-ci` when a
407+
fresh CI run is needed instead.
408+
394409
### Internal vs. public API
395410

396411
All functionality in the official Node.js documentation is part of the public
@@ -1011,6 +1026,8 @@ If you cannot find who to cc for a file, `git shortlog -n -s <file>` can help.
10111026
* `never-stale`: Issues and pull requests exempt from automatic stale handling
10121027
* `request-ci`: When this label is added to a PR, CI will be started
10131028
automatically. See [Starting a Jenkins CI job](#starting-a-jenkins-ci-job)
1029+
* `resume-ci`: When this label is added to a PR, the latest linked CI run will be
1030+
resumed if eligible. See [Starting a Jenkins CI job](#starting-a-jenkins-ci-job)
10141031
* `stale`: Issues and pull requests with no activity for 90 days. See
10151032
[Stale issues and pull requests](#stale-issues-and-pull-requests)
10161033
* `tsc-agenda`: Open issues and pull requests with this label will be added to

‎tools/actions/start-ci.sh‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
set -xe
44

5-
REQUEST_CI_LABEL="request-ci"
6-
REQUEST_CI_FAILED_LABEL="request-ci-failed"
75
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
86

97
escape_code_block_or_line() {
@@ -21,16 +19,39 @@ escape_code_block_or_line() {
2119
}
2220

2321
for pr in "$@"; do
24-
gh -R "$GITHUB_REPOSITORY" pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
22+
request_labels=$(gh -R "$GITHUB_REPOSITORY" pr view "$pr" --json labels \
23+
--jq '[.labels[].name | select(. == "request-ci" or . == "resume-ci")] | sort | join(",")')
24+
case "$request_labels" in
25+
request-ci)
26+
action=start
27+
failed_labels=request-ci-failed
28+
;;
29+
resume-ci)
30+
action=resume
31+
failed_labels=resume-ci-failed
32+
;;
33+
request-ci,resume-ci)
34+
action='start or resume'
35+
failed_labels=request-ci-failed,resume-ci-failed
36+
;;
37+
*) continue ;;
38+
esac
39+
gh -R "$GITHUB_REPOSITORY" pr edit "$pr" --remove-label "$request_labels"
2540

26-
ci_started=yes
41+
ci_succeeded=yes
2742
rm -f output;
28-
ncu-ci run --check-for-duplicates "$pr" >output 2>&1 || ci_started=no
43+
if [ "$request_labels" = "request-ci,resume-ci" ]; then
44+
echo 'Refusing to start or resume CI while both request-ci and resume-ci labels are present' >output
45+
ci_succeeded=no
46+
elif [ "$action" = "resume" ]; then
47+
ncu-ci resume "$pr" >output 2>&1 || ci_succeeded=no
48+
else
49+
ncu-ci run --check-for-duplicates "$pr" >output 2>&1 || ci_succeeded=no
50+
fi
2951
cat output
3052

31-
if [ "$ci_started" = "no" ]; then
32-
# Do we need to reset?
33-
gh -R "$GITHUB_REPOSITORY" pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
53+
if [ "$ci_succeeded" = "no" ]; then
54+
gh -R "$GITHUB_REPOSITORY" pr edit "$pr" --add-label "$failed_labels"
3455

3556
reported_failure=$(grep -e '✘' -e '✖' -e '⚠' -e 'ℹ' output | tail -n 10)
3657
if [ -z "$reported_failure" ]; then
@@ -42,7 +63,7 @@ for pr in "$@"; do
4263
failure_body=$(escape_code_block_or_line "$reported_failure")
4364
raw_output=$(cat output)
4465

45-
body="### Failed to start CI
66+
body="### Failed to $action CI
4667
4768
$failure_body
4869

0 commit comments

Comments
 (0)