Skip to content

Commit 2932675

Browse files
committed
add resume-ci label
1 parent 2fd4c01 commit 2932675

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

.github/workflows/auto-resume-ci.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Auto Start CI
2+
3+
on:
4+
schedule:
5+
# Runs every five minutes (fastest the scheduler can run). Five minutes is
6+
# optimistic, it can take longer to run.
7+
# To understand why `schedule` is used instead of other events, refer to
8+
# ./doc/contributing/commit-queue.md
9+
- cron: '*/5 * * * *'
10+
11+
concurrency: ${{ github.workflow }}
12+
13+
env:
14+
NODE_VERSION: lts/*
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
get-prs-for-ci:
21+
permissions:
22+
pull-requests: read
23+
if: github.repository == 'nodejs/node'
24+
runs-on: ubuntu-latest
25+
outputs:
26+
numbers: ${{ steps.get_prs_for_ci.outputs.numbers }}
27+
steps:
28+
- name: Get Pull Requests
29+
id: get_prs_for_ci
30+
run: >
31+
gh pr list \
32+
--repo ${{ github.repository }} \
33+
--label 'resume-ci' \
34+
--json 'number' \
35+
-t '::set-output name=numbers::{{ range . }}{{ .number }} {{ end }}' \
36+
--limit 100
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
start-ci:
40+
permissions:
41+
contents: read
42+
pull-requests: write
43+
needs: get-prs-for-ci
44+
if: needs.get-prs-for-ci.outputs.numbers != ''
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v3
48+
with:
49+
persist-credentials: false
50+
51+
- name: Install Node.js
52+
uses: actions/setup-node@v3
53+
with:
54+
node-version: ${{ env.NODE_VERSION }}
55+
56+
- name: Install node-core-utils
57+
run: npm install -g node-core-utils
58+
59+
- name: Setup node-core-utils
60+
run: |
61+
ncu-config set username ${{ secrets.JENKINS_USER }}
62+
ncu-config set token none
63+
ncu-config set jenkins_token ${{ secrets.JENKINS_TOKEN }}
64+
ncu-config set owner "${{ github.repository_owner }}"
65+
ncu-config set repo "$(echo ${{ github.repository }} | cut -d/ -f2)"
66+
67+
- name: Resume the CI Runs
68+
run: ./tools/actions/resume-ci.sh ${{ needs.get-prs-for-ci.outputs.numbers }}
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

doc/contributing/commit-queue.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ From a high-level, the Commit Queue works as follow:
2020
1. Collaborators will add `commit-queue` label to pull requests ready to land
2121
2. Every five minutes the queue will do the following for each pull request
2222
with the label:
23-
1. Check if the PR also has a `request-ci` label (if it has, skip this PR
23+
1. Check if the PR also has a `request-ci` or `resume-ci` label (if it has, skip this PR
2424
since it's pending a CI run)
2525
2. Check if the last Jenkins CI is finished running (if it is not, skip this
2626
PR)
@@ -98,7 +98,7 @@ that into a list of PR ids we can pass as arguments to
9898

9999
The script will iterate over the pull requests. `ncu-ci` is used to check if
100100
the last CI is still pending, and calls to the GitHub API are used to check if
101-
the PR is waiting for CI to start (`request-ci` label). The PR is skipped if CI
101+
the PR is waiting for CI to start (`request-ci` pr `resume-ci` label). The PR is skipped if CI
102102
is pending. No other CI validation is done here since `git node land` will fail
103103
if the last CI failed.
104104

tools/actions/commit-queue.sh

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ for pr in "$@"; do
3838
echo "pr ${pr} skipped, waiting for CI to start"
3939
continue
4040
fi
41+
if jq -e 'map(.name) | index("resume-ci")' < labels.json; then
42+
echo "pr ${pr} skipped, waiting for CI to start"
43+
continue
44+
fi
4145

4246
# Skip PR if CI is still running
4347
if gh pr checks "$pr" | grep -q "\spending\s"; then

tools/actions/resume-ci.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
set -xe
4+
5+
RESUME_CI_LABEL="resume-ci"
6+
RESUME_CI_FAILED_LABEL="resume-ci-failed"
7+
8+
for pr in "$@"; do
9+
gh pr edit "$pr" --remove-label "$RESUME_CI_LABEL"
10+
11+
ci_started=yes
12+
rm -f output;
13+
ncu-ci resume "$pr" >output 2>&1 || ci_started=no
14+
cat output
15+
16+
if [ "$ci_started" = "no" ]; then
17+
# Do we need to reset?
18+
gh pr edit "$pr" --add-label "$RESUME_CI_FAILED_LABEL"
19+
20+
jq -n --arg content "<details><summary>Couldn't resume CI</summary><pre>$(cat output || true)</pre></details>" > output.json
21+
22+
gh pr comment "$pr" --body-file output.json
23+
24+
rm output.json;
25+
fi
26+
done;

0 commit comments

Comments
 (0)