Commit 41edd2f

Browse files
committed
tools: make env variables consistent in cron jobs
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65168 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ec956f2 commit 41edd2f

5 files changed

Lines changed: 36 additions & 195 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This action uses the following secrets:
2+
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3+
# JENKINS_TOKEN: Jenkins token, to be used to start CI
14
name: Auto Start CI
25

36
on:
@@ -36,11 +39,13 @@ jobs:
3639
-t '{{ range . }}{{ .number }} {{ end }}' \
3740
--limit 5)" >> "$GITHUB_OUTPUT"
3841
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ github.token }}
4043
start-ci:
4144
permissions:
45+
checks: read
4246
contents: read
4347
pull-requests: write
48+
statuses: read
4449
needs: get-prs-for-ci
4550
if: needs.get-prs-for-ci.outputs.numbers != ''
4651
runs-on: ubuntu-slim
@@ -59,16 +64,15 @@ jobs:
5964
ncu-config set token "$GH_TOKEN"
6065
ncu-config set jenkins_token "$JENKINS_TOKEN"
6166
ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
62-
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
67+
ncu-config set repo "${GITHUB_REPOSITORY#*/}"
6368
env:
6469
USERNAME: ${{ secrets.JENKINS_USER }}
65-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
70+
GH_TOKEN: ${{ github.token }}
6671
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6772

6873
- name: Start the CI
6974
run: |
7075
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
7176
| sh -s -- ${{ needs.get-prs-for-ci.outputs.numbers }}
7277
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GH_REPO: ${{ github.repository }}
78+
GH_TOKEN: ${{ github.token }}

‎.github/workflows/commit-queue.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
jq -r -s 'reduce .[] as $pr ([]; if index($pr) then . else . + [$pr] end) | join(" ")')
5353
echo "candidates=$candidates" >> "$GITHUB_OUTPUT"
5454
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
GH_TOKEN: ${{ github.token }}
5656
commitQueue:
5757
needs: get_candidate_prs
5858
if: needs.get_candidate_prs.outputs.candidates != ''
@@ -63,18 +63,14 @@ jobs:
6363
statuses: read
6464
runs-on: ubuntu-slim
6565
steps:
66-
# Install dependencies
6766
- name: Install Node.js
6867
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6968
with:
7069
node-version: ${{ env.NODE_VERSION }}
70+
7171
- name: Install @node-core/utils
7272
run: npm install -g @node-core/utils
7373

74-
- name: Set variables
75-
run: |
76-
echo "REPOSITORY=$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" >> "$GITHUB_ENV"
77-
7874
- name: Configure @node-core/utils
7975
run: |
8076
# Keep the config outside the workspace so checkout does not remove it.
@@ -83,7 +79,7 @@ jobs:
8379
ncu-config --global set username "$USERNAME"
8480
ncu-config --global set token "$GH_TOKEN"
8581
ncu-config --global set jenkins_token "$JENKINS_TOKEN"
86-
ncu-config --global set repo "${REPOSITORY}"
82+
ncu-config --global set repo "${GITHUB_REPOSITORY#*/}"
8783
ncu-config --global set owner "${GITHUB_REPOSITORY_OWNER}"
8884
env:
8985
USERNAME: ${{ secrets.JENKINS_USER }}
@@ -102,8 +98,6 @@ jobs:
10298
metadata="${RUNNER_TEMP}/metadata-${pr}.json"
10399
output="${RUNNER_TEMP}/metadata-${pr}.txt"
104100
if git node metadata "$pr" \
105-
--owner "$GITHUB_REPOSITORY_OWNER" \
106-
--repo "$REPOSITORY" \
107101
--readme "$readme" \
108102
--json > "$metadata" 2> "$output"; then
109103
metadata_status=0
@@ -171,7 +165,9 @@ jobs:
171165
- name: Start the Commit Queue
172166
if: steps.get_mergeable_prs.outputs.numbers != ''
173167
run: |
168+
git config --local user.email "github-bot@iojs.org"
169+
git config --local user.name "Node.js GitHub Bot"
174170
ncu-config set token "$GH_TOKEN"
175-
./tools/actions/commit-queue.sh "${GITHUB_REPOSITORY_OWNER}" "${REPOSITORY}" ${{ steps.get_mergeable_prs.outputs.numbers }}
171+
./tools/actions/commit-queue.sh ${{ steps.get_mergeable_prs.outputs.numbers }}
176172
env:
177173
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

‎doc/contributing/commit-queue.md‎

Lines changed: 8 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,24 @@ blocked on a deferrable condition, currently wait time, the queue leaves the
1111
label in place and retries later. Other failures continue to the existing
1212
landing and failure-reporting path.
1313

14-
This document gives an overview of how the Commit Queue works, as well as
15-
implementation details, reasoning for design choices, and current limitations.
16-
17-
## Overview
18-
19-
From a high-level, the Commit Queue works as follows:
20-
21-
1. Collaborators will add `commit-queue` label to pull requests they want the
22-
queue to land. The label can be added before the pull request has completed
23-
its wait time. Required approvals must already be in place, and any required
24-
CI must have completed successfully. The commit queue does not request CI on
25-
its own.
26-
2. On each scheduled run, the queue builds a candidate list from open pull
27-
requests with the `commit-queue` label and without the `blocked` label. A
28-
candidate must also either have been created at least two days earlier or
29-
have the `fast-track` label. Other labeled pull requests retain the label
30-
until they become old enough or are fast-tracked. The workflow uses a
31-
five-minute cron, but GitHub Actions scheduled workflows are not guaranteed
32-
to run exactly every five minutes. For each candidate, the queue will:
33-
1. In the landing job, install and configure `@node-core/utils`, then run a
34-
metadata-only readiness check without checking out the repository
35-
2. If the metadata check exits with a deferrable readiness code, meaning
36-
the PR is only blocked on wait time, keep the `commit-queue` label and
37-
skip this PR until a later queue run
38-
3. Run `git node land` for ready PRs and PRs with hard or mixed readiness
39-
failures, keeping the `commit-queue` label in place during the attempt
40-
4. If it fails:
41-
1. Replace the `commit-queue` label with the `commit-queue-failed` label
42-
2. Leave a comment on the PR with the output from `git node land`
43-
3. Abort the `git node land` session. If the abort succeeds, continue to
44-
the next PR; otherwise, stop the queue in an unknown state
45-
5. If it succeeds:
46-
1. Push or merge the changes into nodejs/node
47-
2. Leave a comment on the PR with `Landed in ...`
48-
3. Close the PR
49-
4. Remove the `commit-queue` label
50-
5. Go to next PR in the queue
51-
5214
To make the Commit Queue squash all the commits of a pull request into the
5315
first one, add the `commit-queue-squash` label.
5416
To make the Commit Queue land a pull request containing several commits, add the
5517
`commit-queue-rebase` label. When using this option, make sure
5618
that all commits are self-contained, meaning every commit should pass all tests.
5719

20+
The implementation is in `commit-queue.yml` and `commit-queue.sh`.
21+
5822
## Current limitations
5923

60-
The Commit Queue feature is still in early stages, and as such it might not
61-
work for more complex pull requests. These are the currently known limitations
62-
of the commit queue:
24+
These are the currently known limitations of the commit queue:
6325

6426
1. All commits in a pull request must either be following commit message
6527
guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6628
commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash)
67-
option
68-
2. A CI must have run and succeeded since the last change on the PR
69-
3. A collaborator must have approved the PR since the last change
70-
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored)
29+
option.
30+
2. A CI must have run and succeeded since the last change on the PR.
31+
3. A collaborator must have approved the PR since the last change.
32+
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored).
7133
5. The PR must target the `main` branch (PRs opened against other branches, such
72-
as backport PRs, are ignored)
73-
74-
## Implementation
75-
76-
The [action](../../.github/workflows/commit-queue.yml) runs on scheduled events.
77-
It uses a five-minute cron because that is the smallest interval accepted by
78-
GitHub Actions. Scheduled workflows are not guaranteed to run exactly at that
79-
cadence and might take longer between runs.
80-
81-
The workflow also uses a concurrency group so only one commit queue run can be
82-
active at a time. If a scheduled run starts while a previous run is still
83-
running, GitHub Actions keeps at most one pending run for the same concurrency
84-
group. A newer pending run replaces an older pending run.
85-
86-
Using the scheduler is preferable over using pull\_request\_target for two
87-
reasons:
88-
89-
1. if two Commit Queue Actions execution overlap, there's a high-risk that
90-
the last one to finish will fail because the local branch will be out of
91-
sync with the remote after the first Action pushes. `issue_comment` event
92-
has the same limitation.
93-
2.`pull_request_target` will only run if the Action exists on the base commit
94-
of a pull request, and it will run the Action version present on that
95-
commit, meaning we wouldn't be able to use it for already opened PRs
96-
without rebasing them first.
97-
98-
The workflow starts with a small candidate job that uses GitHub CLI to fetch
99-
open pull requests with the `commit-queue` label and without the `blocked`
100-
label. It fetches two buckets: pull requests created at least two days earlier
101-
and pull requests with the `fast-track` label. The job de-duplicates the
102-
buckets before passing the candidates to the landing job. Pull requests in
103-
neither bucket remain labeled but are not processed during that run.
104-
105-
If there are candidate PRs, the landing job installs and configures
106-
`@node-core/utils` once with a personal token and a Jenkins token from
107-
[@nodejs-github-bot](https://github.com/nodejs/github-bot). It then downloads
108-
the workflow commit's README without checking out the repository and runs
109-
`git node metadata --readme --json` for each candidate. This uses the same
110-
`@node-core/utils` PR readiness checks as `git node land`, but does not clone,
111-
fetch, or merge the PR. The filter consumes the structured metadata result
112-
and its exit code instead of matching human-readable output:
113-
114-
* exit code `0`: the PR is ready and is passed to
115-
[`commit-queue.sh`](../../tools/actions/commit-queue.sh)
116-
* exit codes `20`-`29`: the PR is not ready for a deferrable metadata reason,
117-
currently wait time, so it keeps the `commit-queue` label and is retried
118-
later
119-
* exit codes `40`-`49`: the PR has a hard or mixed metadata readiness failure
120-
and is passed to [`commit-queue.sh`](../../tools/actions/commit-queue.sh)
121-
122-
The `20`-`29` exit code range is reserved by `@node-core/utils` for deferrable
123-
metadata readiness states, and `40`-`49` is reserved for hard metadata failure
124-
states. Unknown filter failures fail the workflow before starting the landing
125-
script and leave PR labels unchanged so the queue can retry on a later
126-
scheduled run. PRs passed through with exit code `40`-`49` continue through
127-
`commit-queue.sh`. The workflow checks out the repository only when at least
128-
one PR remains after filtering. The script does not separately skip PRs with a
129-
`request-ci` label or pending GitHub checks. Instead, `git node land` performs
130-
the landing checks and the script reports any failure through the normal queue
131-
failure path.
132-
133-
> The personal token needs permission for public repositories and to read
134-
> profiles. It is used by `@node-core/utils` and by the landing job for
135-
> checkout, label and comment updates, merging, and pushing. Jenkins token is
136-
> required to check CI status.
137-
138-
`commit-queue.sh` receives the following positional arguments:
139-
140-
1. The repository owner
141-
2. The repository name
142-
3. Every positional argument starting at this one will be a pull request ID of
143-
a pull request with commit-queue set.
144-
145-
The script iterates over the pull requests. For each PR, it uses GitHub CLI to
146-
fetch the labels and select the multiple-commit policy, then runs
147-
`git node land`, forwarding stdout and stderr to a file. It does not perform a
148-
separate CI preflight; `git node land` performs the current readiness and CI
149-
validation.
150-
151-
The script keeps the `commit-queue` label in place while `git node land` is
152-
running. PRs that are only blocked on wait time should have already been
153-
filtered by the metadata check. A hard or mixed readiness failure is passed
154-
through so `git node land` can produce the failure output. If the landing
155-
attempt fails for that or any other reason, the job replaces the
156-
`commit-queue` label with `commit-queue-failed`, leaves a comment with the
157-
output, and then aborts the landing session. If the abort fails, the queue
158-
stops instead of continuing in an unknown state.
159-
160-
Fast-tracked PRs use the metadata check before checkout and the landing script.
161-
If the fast-track request has not yet received enough collaborator thumbs-up,
162-
the queue keeps the `commit-queue` label and retries until either the
163-
fast-track request is approved or the PR becomes landable through the regular
164-
wait-time rules. The commit queue does not create the fast-track request
165-
comment; that is handled when the `fast-track` label is added. If that comment
166-
is missing, the queue reports the failure instead of keeping the PR queued.
167-
168-
If no errors happen during `git node land`, the script either pushes the direct
169-
rebase landing to `main` or uses GitHub's squash merge API for single-commit and
170-
fixup landings. It then leaves a `Landed in ...` comment in the PR. GitHub
171-
closes PRs merged through the merge API automatically; for direct pushes, the
172-
script closes the PR. The script then removes the `commit-queue` label.
173-
Iteration continues until all PRs have done the steps above.
174-
175-
## Reverting broken commits
176-
177-
Reverting broken commits is done manually by collaborators, just like when
178-
commits are landed manually via `git node land`. An easy way to revert is a
179-
good feature for the project, but is not explicitly required for the Commit
180-
Queue to work because the Action lands PRs just like collaborators do today. If
181-
once we start using the Commit Queue we notice that the number of required
182-
reverts increases drastically, we can pause the queue until a Revert Queue is
183-
implemented, but until then we can enable the Commit Queue and then work on a
184-
Revert Queue as a follow-up.
34+
as backport PRs, are ignored).

‎tools/actions/commit-queue.sh‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
set -xe
44

5-
OWNER=$1
6-
REPOSITORY=$2
7-
shift 2
8-
95
UPSTREAM=origin
106
DEFAULT_BRANCH=main
117

128
COMMIT_QUEUE_LABEL="commit-queue"
139
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1410

11+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
12+
1513
commit_queue_failed() {
1614
pr=$1
1715

18-
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
16+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1917

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2218
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
2319
echo"$body"
2420

25-
gh pr comment "$pr" --body "$body"
21+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2622

2723
rm output
2824
}
2925

30-
# TODO(mmarchini): should this be set with whoever added the label for each PR?
31-
git config --local user.email "github-bot@iojs.org"
32-
git config --local user.name "Node.js GitHub Bot"
33-
3426
SHOULD_ABORT=
3527

3628
forprin"$@";do
37-
gh pr view "$pr" --json labels --jq ".labels"> labels.json
29+
gh -R "$GITHUB_REPOSITORY"pr view "$pr" --json labels --jq ".labels"> labels.json
3830

3931
if jq -e 'map(.name) | index("commit-queue-squash")'< labels.json;then
4032
MULTIPLE_COMMIT_POLICY="--fixupAll"
@@ -87,7 +79,7 @@ for pr in "$@"; do
8779
--arg body "${commit_body}" \
8880
--arg head "${commit_head}" \
8981
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}'|\
90-
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
82+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
9183
--jq 'if .merged then .sha else halt_error end'
9284
)";then
9385
commit_queue_failed "$pr"
@@ -97,12 +89,12 @@ for pr in "$@"; do
9789

9890
rm output
9991

100-
gh pr comment "$pr" --body "Landed in $commits"
92+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "Landed in $commits"
10193

102-
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
94+
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh -R "$GITHUB_REPOSITORY"pr close "$pr"
10395

10496
# Delete the commit queue label (but ignore errors, it's no big deal if a closed PR still has the label)
105-
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
97+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
10698
done
10799

108100
rm -f labels.json

‎tools/actions/start-ci.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ set -xe
44

55
REQUEST_CI_LABEL="request-ci"
66
REQUEST_CI_FAILED_LABEL="request-ci-failed"
7+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
78

89
forprin"$@";do
9-
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
1011

1112
ci_started=yes
1213
rm -f output;
@@ -15,14 +16,12 @@ for pr in "$@"; do
1516

1617
if [ "$ci_started"="no" ];then
1718
# Do we need to reset?
18-
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
1920

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2221
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
2322
echo"$body"
2423

25-
gh pr comment "$pr" --body "$body"
24+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2625

2726
rm output
2827
fi

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 41edd2f

Browse files
committed
tools: make env variables consistent in cron jobs
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65168 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ec956f2 commit 41edd2f

5 files changed

Lines changed: 36 additions & 195 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This action uses the following secrets:
2+
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3+
# JENKINS_TOKEN: Jenkins token, to be used to start CI
14
name: Auto Start CI
25

36
on:
@@ -36,11 +39,13 @@ jobs:
3639
-t '{{ range . }}{{ .number }} {{ end }}' \
3740
--limit 5)" >> "$GITHUB_OUTPUT"
3841
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ github.token }}
4043
start-ci:
4144
permissions:
45+
checks: read
4246
contents: read
4347
pull-requests: write
48+
statuses: read
4449
needs: get-prs-for-ci
4550
if: needs.get-prs-for-ci.outputs.numbers != ''
4651
runs-on: ubuntu-slim
@@ -59,16 +64,15 @@ jobs:
5964
ncu-config set token "$GH_TOKEN"
6065
ncu-config set jenkins_token "$JENKINS_TOKEN"
6166
ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
62-
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
67+
ncu-config set repo "${GITHUB_REPOSITORY#*/}"
6368
env:
6469
USERNAME: ${{ secrets.JENKINS_USER }}
65-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
70+
GH_TOKEN: ${{ github.token }}
6671
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6772

6873
- name: Start the CI
6974
run: |
7075
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
7176
| sh -s -- ${{ needs.get-prs-for-ci.outputs.numbers }}
7277
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GH_REPO: ${{ github.repository }}
78+
GH_TOKEN: ${{ github.token }}

‎.github/workflows/commit-queue.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
jq -r -s 'reduce .[] as $pr ([]; if index($pr) then . else . + [$pr] end) | join(" ")')
5353
echo "candidates=$candidates" >> "$GITHUB_OUTPUT"
5454
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
GH_TOKEN: ${{ github.token }}
5656
commitQueue:
5757
needs: get_candidate_prs
5858
if: needs.get_candidate_prs.outputs.candidates != ''
@@ -63,18 +63,14 @@ jobs:
6363
statuses: read
6464
runs-on: ubuntu-slim
6565
steps:
66-
# Install dependencies
6766
- name: Install Node.js
6867
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6968
with:
7069
node-version: ${{ env.NODE_VERSION }}
70+
7171
- name: Install @node-core/utils
7272
run: npm install -g @node-core/utils
7373

74-
- name: Set variables
75-
run: |
76-
echo "REPOSITORY=$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" >> "$GITHUB_ENV"
77-
7874
- name: Configure @node-core/utils
7975
run: |
8076
# Keep the config outside the workspace so checkout does not remove it.
@@ -83,7 +79,7 @@ jobs:
8379
ncu-config --global set username "$USERNAME"
8480
ncu-config --global set token "$GH_TOKEN"
8581
ncu-config --global set jenkins_token "$JENKINS_TOKEN"
86-
ncu-config --global set repo "${REPOSITORY}"
82+
ncu-config --global set repo "${GITHUB_REPOSITORY#*/}"
8783
ncu-config --global set owner "${GITHUB_REPOSITORY_OWNER}"
8884
env:
8985
USERNAME: ${{ secrets.JENKINS_USER }}
@@ -102,8 +98,6 @@ jobs:
10298
metadata="${RUNNER_TEMP}/metadata-${pr}.json"
10399
output="${RUNNER_TEMP}/metadata-${pr}.txt"
104100
if git node metadata "$pr" \
105-
--owner "$GITHUB_REPOSITORY_OWNER" \
106-
--repo "$REPOSITORY" \
107101
--readme "$readme" \
108102
--json > "$metadata" 2> "$output"; then
109103
metadata_status=0
@@ -171,7 +165,9 @@ jobs:
171165
- name: Start the Commit Queue
172166
if: steps.get_mergeable_prs.outputs.numbers != ''
173167
run: |
168+
git config --local user.email "github-bot@iojs.org"
169+
git config --local user.name "Node.js GitHub Bot"
174170
ncu-config set token "$GH_TOKEN"
175-
./tools/actions/commit-queue.sh "${GITHUB_REPOSITORY_OWNER}" "${REPOSITORY}" ${{ steps.get_mergeable_prs.outputs.numbers }}
171+
./tools/actions/commit-queue.sh ${{ steps.get_mergeable_prs.outputs.numbers }}
176172
env:
177173
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

‎doc/contributing/commit-queue.md‎

Lines changed: 8 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,24 @@ blocked on a deferrable condition, currently wait time, the queue leaves the
1111
label in place and retries later. Other failures continue to the existing
1212
landing and failure-reporting path.
1313

14-
This document gives an overview of how the Commit Queue works, as well as
15-
implementation details, reasoning for design choices, and current limitations.
16-
17-
## Overview
18-
19-
From a high-level, the Commit Queue works as follows:
20-
21-
1. Collaborators will add `commit-queue` label to pull requests they want the
22-
queue to land. The label can be added before the pull request has completed
23-
its wait time. Required approvals must already be in place, and any required
24-
CI must have completed successfully. The commit queue does not request CI on
25-
its own.
26-
2. On each scheduled run, the queue builds a candidate list from open pull
27-
requests with the `commit-queue` label and without the `blocked` label. A
28-
candidate must also either have been created at least two days earlier or
29-
have the `fast-track` label. Other labeled pull requests retain the label
30-
until they become old enough or are fast-tracked. The workflow uses a
31-
five-minute cron, but GitHub Actions scheduled workflows are not guaranteed
32-
to run exactly every five minutes. For each candidate, the queue will:
33-
1. In the landing job, install and configure `@node-core/utils`, then run a
34-
metadata-only readiness check without checking out the repository
35-
2. If the metadata check exits with a deferrable readiness code, meaning
36-
the PR is only blocked on wait time, keep the `commit-queue` label and
37-
skip this PR until a later queue run
38-
3. Run `git node land` for ready PRs and PRs with hard or mixed readiness
39-
failures, keeping the `commit-queue` label in place during the attempt
40-
4. If it fails:
41-
1. Replace the `commit-queue` label with the `commit-queue-failed` label
42-
2. Leave a comment on the PR with the output from `git node land`
43-
3. Abort the `git node land` session. If the abort succeeds, continue to
44-
the next PR; otherwise, stop the queue in an unknown state
45-
5. If it succeeds:
46-
1. Push or merge the changes into nodejs/node
47-
2. Leave a comment on the PR with `Landed in ...`
48-
3. Close the PR
49-
4. Remove the `commit-queue` label
50-
5. Go to next PR in the queue
51-
5214
To make the Commit Queue squash all the commits of a pull request into the
5315
first one, add the `commit-queue-squash` label.
5416
To make the Commit Queue land a pull request containing several commits, add the
5517
`commit-queue-rebase` label. When using this option, make sure
5618
that all commits are self-contained, meaning every commit should pass all tests.
5719

20+
The implementation is in `commit-queue.yml` and `commit-queue.sh`.
21+
5822
## Current limitations
5923

60-
The Commit Queue feature is still in early stages, and as such it might not
61-
work for more complex pull requests. These are the currently known limitations
62-
of the commit queue:
24+
These are the currently known limitations of the commit queue:
6325

6426
1. All commits in a pull request must either be following commit message
6527
guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6628
commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash)
67-
option
68-
2. A CI must have run and succeeded since the last change on the PR
69-
3. A collaborator must have approved the PR since the last change
70-
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored)
29+
option.
30+
2. A CI must have run and succeeded since the last change on the PR.
31+
3. A collaborator must have approved the PR since the last change.
32+
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored).
7133
5. The PR must target the `main` branch (PRs opened against other branches, such
72-
as backport PRs, are ignored)
73-
74-
## Implementation
75-
76-
The [action](../../.github/workflows/commit-queue.yml) runs on scheduled events.
77-
It uses a five-minute cron because that is the smallest interval accepted by
78-
GitHub Actions. Scheduled workflows are not guaranteed to run exactly at that
79-
cadence and might take longer between runs.
80-
81-
The workflow also uses a concurrency group so only one commit queue run can be
82-
active at a time. If a scheduled run starts while a previous run is still
83-
running, GitHub Actions keeps at most one pending run for the same concurrency
84-
group. A newer pending run replaces an older pending run.
85-
86-
Using the scheduler is preferable over using pull\_request\_target for two
87-
reasons:
88-
89-
1. if two Commit Queue Actions execution overlap, there's a high-risk that
90-
the last one to finish will fail because the local branch will be out of
91-
sync with the remote after the first Action pushes. `issue_comment` event
92-
has the same limitation.
93-
2.`pull_request_target` will only run if the Action exists on the base commit
94-
of a pull request, and it will run the Action version present on that
95-
commit, meaning we wouldn't be able to use it for already opened PRs
96-
without rebasing them first.
97-
98-
The workflow starts with a small candidate job that uses GitHub CLI to fetch
99-
open pull requests with the `commit-queue` label and without the `blocked`
100-
label. It fetches two buckets: pull requests created at least two days earlier
101-
and pull requests with the `fast-track` label. The job de-duplicates the
102-
buckets before passing the candidates to the landing job. Pull requests in
103-
neither bucket remain labeled but are not processed during that run.
104-
105-
If there are candidate PRs, the landing job installs and configures
106-
`@node-core/utils` once with a personal token and a Jenkins token from
107-
[@nodejs-github-bot](https://github.com/nodejs/github-bot). It then downloads
108-
the workflow commit's README without checking out the repository and runs
109-
`git node metadata --readme --json` for each candidate. This uses the same
110-
`@node-core/utils` PR readiness checks as `git node land`, but does not clone,
111-
fetch, or merge the PR. The filter consumes the structured metadata result
112-
and its exit code instead of matching human-readable output:
113-
114-
* exit code `0`: the PR is ready and is passed to
115-
[`commit-queue.sh`](../../tools/actions/commit-queue.sh)
116-
* exit codes `20`-`29`: the PR is not ready for a deferrable metadata reason,
117-
currently wait time, so it keeps the `commit-queue` label and is retried
118-
later
119-
* exit codes `40`-`49`: the PR has a hard or mixed metadata readiness failure
120-
and is passed to [`commit-queue.sh`](../../tools/actions/commit-queue.sh)
121-
122-
The `20`-`29` exit code range is reserved by `@node-core/utils` for deferrable
123-
metadata readiness states, and `40`-`49` is reserved for hard metadata failure
124-
states. Unknown filter failures fail the workflow before starting the landing
125-
script and leave PR labels unchanged so the queue can retry on a later
126-
scheduled run. PRs passed through with exit code `40`-`49` continue through
127-
`commit-queue.sh`. The workflow checks out the repository only when at least
128-
one PR remains after filtering. The script does not separately skip PRs with a
129-
`request-ci` label or pending GitHub checks. Instead, `git node land` performs
130-
the landing checks and the script reports any failure through the normal queue
131-
failure path.
132-
133-
> The personal token needs permission for public repositories and to read
134-
> profiles. It is used by `@node-core/utils` and by the landing job for
135-
> checkout, label and comment updates, merging, and pushing. Jenkins token is
136-
> required to check CI status.
137-
138-
`commit-queue.sh` receives the following positional arguments:
139-
140-
1. The repository owner
141-
2. The repository name
142-
3. Every positional argument starting at this one will be a pull request ID of
143-
a pull request with commit-queue set.
144-
145-
The script iterates over the pull requests. For each PR, it uses GitHub CLI to
146-
fetch the labels and select the multiple-commit policy, then runs
147-
`git node land`, forwarding stdout and stderr to a file. It does not perform a
148-
separate CI preflight; `git node land` performs the current readiness and CI
149-
validation.
150-
151-
The script keeps the `commit-queue` label in place while `git node land` is
152-
running. PRs that are only blocked on wait time should have already been
153-
filtered by the metadata check. A hard or mixed readiness failure is passed
154-
through so `git node land` can produce the failure output. If the landing
155-
attempt fails for that or any other reason, the job replaces the
156-
`commit-queue` label with `commit-queue-failed`, leaves a comment with the
157-
output, and then aborts the landing session. If the abort fails, the queue
158-
stops instead of continuing in an unknown state.
159-
160-
Fast-tracked PRs use the metadata check before checkout and the landing script.
161-
If the fast-track request has not yet received enough collaborator thumbs-up,
162-
the queue keeps the `commit-queue` label and retries until either the
163-
fast-track request is approved or the PR becomes landable through the regular
164-
wait-time rules. The commit queue does not create the fast-track request
165-
comment; that is handled when the `fast-track` label is added. If that comment
166-
is missing, the queue reports the failure instead of keeping the PR queued.
167-
168-
If no errors happen during `git node land`, the script either pushes the direct
169-
rebase landing to `main` or uses GitHub's squash merge API for single-commit and
170-
fixup landings. It then leaves a `Landed in ...` comment in the PR. GitHub
171-
closes PRs merged through the merge API automatically; for direct pushes, the
172-
script closes the PR. The script then removes the `commit-queue` label.
173-
Iteration continues until all PRs have done the steps above.
174-
175-
## Reverting broken commits
176-
177-
Reverting broken commits is done manually by collaborators, just like when
178-
commits are landed manually via `git node land`. An easy way to revert is a
179-
good feature for the project, but is not explicitly required for the Commit
180-
Queue to work because the Action lands PRs just like collaborators do today. If
181-
once we start using the Commit Queue we notice that the number of required
182-
reverts increases drastically, we can pause the queue until a Revert Queue is
183-
implemented, but until then we can enable the Commit Queue and then work on a
184-
Revert Queue as a follow-up.
34+
as backport PRs, are ignored).

‎tools/actions/commit-queue.sh‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
set -xe
44

5-
OWNER=$1
6-
REPOSITORY=$2
7-
shift 2
8-
95
UPSTREAM=origin
106
DEFAULT_BRANCH=main
117

128
COMMIT_QUEUE_LABEL="commit-queue"
139
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1410

11+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
12+
1513
commit_queue_failed() {
1614
pr=$1
1715

18-
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
16+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1917

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2218
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
2319
echo"$body"
2420

25-
gh pr comment "$pr" --body "$body"
21+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2622

2723
rm output
2824
}
2925

30-
# TODO(mmarchini): should this be set with whoever added the label for each PR?
31-
git config --local user.email "github-bot@iojs.org"
32-
git config --local user.name "Node.js GitHub Bot"
33-
3426
SHOULD_ABORT=
3527

3628
forprin"$@";do
37-
gh pr view "$pr" --json labels --jq ".labels"> labels.json
29+
gh -R "$GITHUB_REPOSITORY"pr view "$pr" --json labels --jq ".labels"> labels.json
3830

3931
if jq -e 'map(.name) | index("commit-queue-squash")'< labels.json;then
4032
MULTIPLE_COMMIT_POLICY="--fixupAll"
@@ -87,7 +79,7 @@ for pr in "$@"; do
8779
--arg body "${commit_body}" \
8880
--arg head "${commit_head}" \
8981
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}'|\
90-
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
82+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
9183
--jq 'if .merged then .sha else halt_error end'
9284
)";then
9385
commit_queue_failed "$pr"
@@ -97,12 +89,12 @@ for pr in "$@"; do
9789

9890
rm output
9991

100-
gh pr comment "$pr" --body "Landed in $commits"
92+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "Landed in $commits"
10193

102-
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
94+
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh -R "$GITHUB_REPOSITORY"pr close "$pr"
10395

10496
# Delete the commit queue label (but ignore errors, it's no big deal if a closed PR still has the label)
105-
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
97+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
10698
done
10799

108100
rm -f labels.json

‎tools/actions/start-ci.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ set -xe
44

55
REQUEST_CI_LABEL="request-ci"
66
REQUEST_CI_FAILED_LABEL="request-ci-failed"
7+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
78

89
forprin"$@";do
9-
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
1011

1112
ci_started=yes
1213
rm -f output;
@@ -15,14 +16,12 @@ for pr in "$@"; do
1516

1617
if [ "$ci_started"="no" ];then
1718
# Do we need to reset?
18-
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
1920

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2221
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
2322
echo"$body"
2423

25-
gh pr comment "$pr" --body "$body"
24+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2625

2726
rm output
2827
fi

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 41edd2f

Browse files
committed
tools: make env variables consistent in cron jobs
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65168 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ec956f2 commit 41edd2f

5 files changed

Lines changed: 36 additions & 195 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This action uses the following secrets:
2+
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3+
# JENKINS_TOKEN: Jenkins token, to be used to start CI
14
name: Auto Start CI
25

36
on:
@@ -36,11 +39,13 @@ jobs:
3639
-t '{{ range . }}{{ .number }} {{ end }}' \
3740
--limit 5)" >> "$GITHUB_OUTPUT"
3841
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ github.token }}
4043
start-ci:
4144
permissions:
45+
checks: read
4246
contents: read
4347
pull-requests: write
48+
statuses: read
4449
needs: get-prs-for-ci
4550
if: needs.get-prs-for-ci.outputs.numbers != ''
4651
runs-on: ubuntu-slim
@@ -59,16 +64,15 @@ jobs:
5964
ncu-config set token "$GH_TOKEN"
6065
ncu-config set jenkins_token "$JENKINS_TOKEN"
6166
ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
62-
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
67+
ncu-config set repo "${GITHUB_REPOSITORY#*/}"
6368
env:
6469
USERNAME: ${{ secrets.JENKINS_USER }}
65-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
70+
GH_TOKEN: ${{ github.token }}
6671
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6772

6873
- name: Start the CI
6974
run: |
7075
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
7176
| sh -s -- ${{ needs.get-prs-for-ci.outputs.numbers }}
7277
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GH_REPO: ${{ github.repository }}
78+
GH_TOKEN: ${{ github.token }}

‎.github/workflows/commit-queue.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
jq -r -s 'reduce .[] as $pr ([]; if index($pr) then . else . + [$pr] end) | join(" ")')
5353
echo "candidates=$candidates" >> "$GITHUB_OUTPUT"
5454
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
GH_TOKEN: ${{ github.token }}
5656
commitQueue:
5757
needs: get_candidate_prs
5858
if: needs.get_candidate_prs.outputs.candidates != ''
@@ -63,18 +63,14 @@ jobs:
6363
statuses: read
6464
runs-on: ubuntu-slim
6565
steps:
66-
# Install dependencies
6766
- name: Install Node.js
6867
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6968
with:
7069
node-version: ${{ env.NODE_VERSION }}
70+
7171
- name: Install @node-core/utils
7272
run: npm install -g @node-core/utils
7373

74-
- name: Set variables
75-
run: |
76-
echo "REPOSITORY=$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" >> "$GITHUB_ENV"
77-
7874
- name: Configure @node-core/utils
7975
run: |
8076
# Keep the config outside the workspace so checkout does not remove it.
@@ -83,7 +79,7 @@ jobs:
8379
ncu-config --global set username "$USERNAME"
8480
ncu-config --global set token "$GH_TOKEN"
8581
ncu-config --global set jenkins_token "$JENKINS_TOKEN"
86-
ncu-config --global set repo "${REPOSITORY}"
82+
ncu-config --global set repo "${GITHUB_REPOSITORY#*/}"
8783
ncu-config --global set owner "${GITHUB_REPOSITORY_OWNER}"
8884
env:
8985
USERNAME: ${{ secrets.JENKINS_USER }}
@@ -102,8 +98,6 @@ jobs:
10298
metadata="${RUNNER_TEMP}/metadata-${pr}.json"
10399
output="${RUNNER_TEMP}/metadata-${pr}.txt"
104100
if git node metadata "$pr" \
105-
--owner "$GITHUB_REPOSITORY_OWNER" \
106-
--repo "$REPOSITORY" \
107101
--readme "$readme" \
108102
--json > "$metadata" 2> "$output"; then
109103
metadata_status=0
@@ -171,7 +165,9 @@ jobs:
171165
- name: Start the Commit Queue
172166
if: steps.get_mergeable_prs.outputs.numbers != ''
173167
run: |
168+
git config --local user.email "github-bot@iojs.org"
169+
git config --local user.name "Node.js GitHub Bot"
174170
ncu-config set token "$GH_TOKEN"
175-
./tools/actions/commit-queue.sh "${GITHUB_REPOSITORY_OWNER}" "${REPOSITORY}" ${{ steps.get_mergeable_prs.outputs.numbers }}
171+
./tools/actions/commit-queue.sh ${{ steps.get_mergeable_prs.outputs.numbers }}
176172
env:
177173
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

‎doc/contributing/commit-queue.md‎

Lines changed: 8 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,24 @@ blocked on a deferrable condition, currently wait time, the queue leaves the
1111
label in place and retries later. Other failures continue to the existing
1212
landing and failure-reporting path.
1313

14-
This document gives an overview of how the Commit Queue works, as well as
15-
implementation details, reasoning for design choices, and current limitations.
16-
17-
## Overview
18-
19-
From a high-level, the Commit Queue works as follows:
20-
21-
1. Collaborators will add `commit-queue` label to pull requests they want the
22-
queue to land. The label can be added before the pull request has completed
23-
its wait time. Required approvals must already be in place, and any required
24-
CI must have completed successfully. The commit queue does not request CI on
25-
its own.
26-
2. On each scheduled run, the queue builds a candidate list from open pull
27-
requests with the `commit-queue` label and without the `blocked` label. A
28-
candidate must also either have been created at least two days earlier or
29-
have the `fast-track` label. Other labeled pull requests retain the label
30-
until they become old enough or are fast-tracked. The workflow uses a
31-
five-minute cron, but GitHub Actions scheduled workflows are not guaranteed
32-
to run exactly every five minutes. For each candidate, the queue will:
33-
1. In the landing job, install and configure `@node-core/utils`, then run a
34-
metadata-only readiness check without checking out the repository
35-
2. If the metadata check exits with a deferrable readiness code, meaning
36-
the PR is only blocked on wait time, keep the `commit-queue` label and
37-
skip this PR until a later queue run
38-
3. Run `git node land` for ready PRs and PRs with hard or mixed readiness
39-
failures, keeping the `commit-queue` label in place during the attempt
40-
4. If it fails:
41-
1. Replace the `commit-queue` label with the `commit-queue-failed` label
42-
2. Leave a comment on the PR with the output from `git node land`
43-
3. Abort the `git node land` session. If the abort succeeds, continue to
44-
the next PR; otherwise, stop the queue in an unknown state
45-
5. If it succeeds:
46-
1. Push or merge the changes into nodejs/node
47-
2. Leave a comment on the PR with `Landed in ...`
48-
3. Close the PR
49-
4. Remove the `commit-queue` label
50-
5. Go to next PR in the queue
51-
5214
To make the Commit Queue squash all the commits of a pull request into the
5315
first one, add the `commit-queue-squash` label.
5416
To make the Commit Queue land a pull request containing several commits, add the
5517
`commit-queue-rebase` label. When using this option, make sure
5618
that all commits are self-contained, meaning every commit should pass all tests.
5719

20+
The implementation is in `commit-queue.yml` and `commit-queue.sh`.
21+
5822
## Current limitations
5923

60-
The Commit Queue feature is still in early stages, and as such it might not
61-
work for more complex pull requests. These are the currently known limitations
62-
of the commit queue:
24+
These are the currently known limitations of the commit queue:
6325

6426
1. All commits in a pull request must either be following commit message
6527
guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6628
commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash)
67-
option
68-
2. A CI must have run and succeeded since the last change on the PR
69-
3. A collaborator must have approved the PR since the last change
70-
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored)
29+
option.
30+
2. A CI must have run and succeeded since the last change on the PR.
31+
3. A collaborator must have approved the PR since the last change.
32+
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored).
7133
5. The PR must target the `main` branch (PRs opened against other branches, such
72-
as backport PRs, are ignored)
73-
74-
## Implementation
75-
76-
The [action](../../.github/workflows/commit-queue.yml) runs on scheduled events.
77-
It uses a five-minute cron because that is the smallest interval accepted by
78-
GitHub Actions. Scheduled workflows are not guaranteed to run exactly at that
79-
cadence and might take longer between runs.
80-
81-
The workflow also uses a concurrency group so only one commit queue run can be
82-
active at a time. If a scheduled run starts while a previous run is still
83-
running, GitHub Actions keeps at most one pending run for the same concurrency
84-
group. A newer pending run replaces an older pending run.
85-
86-
Using the scheduler is preferable over using pull\_request\_target for two
87-
reasons:
88-
89-
1. if two Commit Queue Actions execution overlap, there's a high-risk that
90-
the last one to finish will fail because the local branch will be out of
91-
sync with the remote after the first Action pushes. `issue_comment` event
92-
has the same limitation.
93-
2.`pull_request_target` will only run if the Action exists on the base commit
94-
of a pull request, and it will run the Action version present on that
95-
commit, meaning we wouldn't be able to use it for already opened PRs
96-
without rebasing them first.
97-
98-
The workflow starts with a small candidate job that uses GitHub CLI to fetch
99-
open pull requests with the `commit-queue` label and without the `blocked`
100-
label. It fetches two buckets: pull requests created at least two days earlier
101-
and pull requests with the `fast-track` label. The job de-duplicates the
102-
buckets before passing the candidates to the landing job. Pull requests in
103-
neither bucket remain labeled but are not processed during that run.
104-
105-
If there are candidate PRs, the landing job installs and configures
106-
`@node-core/utils` once with a personal token and a Jenkins token from
107-
[@nodejs-github-bot](https://github.com/nodejs/github-bot). It then downloads
108-
the workflow commit's README without checking out the repository and runs
109-
`git node metadata --readme --json` for each candidate. This uses the same
110-
`@node-core/utils` PR readiness checks as `git node land`, but does not clone,
111-
fetch, or merge the PR. The filter consumes the structured metadata result
112-
and its exit code instead of matching human-readable output:
113-
114-
* exit code `0`: the PR is ready and is passed to
115-
[`commit-queue.sh`](../../tools/actions/commit-queue.sh)
116-
* exit codes `20`-`29`: the PR is not ready for a deferrable metadata reason,
117-
currently wait time, so it keeps the `commit-queue` label and is retried
118-
later
119-
* exit codes `40`-`49`: the PR has a hard or mixed metadata readiness failure
120-
and is passed to [`commit-queue.sh`](../../tools/actions/commit-queue.sh)
121-
122-
The `20`-`29` exit code range is reserved by `@node-core/utils` for deferrable
123-
metadata readiness states, and `40`-`49` is reserved for hard metadata failure
124-
states. Unknown filter failures fail the workflow before starting the landing
125-
script and leave PR labels unchanged so the queue can retry on a later
126-
scheduled run. PRs passed through with exit code `40`-`49` continue through
127-
`commit-queue.sh`. The workflow checks out the repository only when at least
128-
one PR remains after filtering. The script does not separately skip PRs with a
129-
`request-ci` label or pending GitHub checks. Instead, `git node land` performs
130-
the landing checks and the script reports any failure through the normal queue
131-
failure path.
132-
133-
> The personal token needs permission for public repositories and to read
134-
> profiles. It is used by `@node-core/utils` and by the landing job for
135-
> checkout, label and comment updates, merging, and pushing. Jenkins token is
136-
> required to check CI status.
137-
138-
`commit-queue.sh` receives the following positional arguments:
139-
140-
1. The repository owner
141-
2. The repository name
142-
3. Every positional argument starting at this one will be a pull request ID of
143-
a pull request with commit-queue set.
144-
145-
The script iterates over the pull requests. For each PR, it uses GitHub CLI to
146-
fetch the labels and select the multiple-commit policy, then runs
147-
`git node land`, forwarding stdout and stderr to a file. It does not perform a
148-
separate CI preflight; `git node land` performs the current readiness and CI
149-
validation.
150-
151-
The script keeps the `commit-queue` label in place while `git node land` is
152-
running. PRs that are only blocked on wait time should have already been
153-
filtered by the metadata check. A hard or mixed readiness failure is passed
154-
through so `git node land` can produce the failure output. If the landing
155-
attempt fails for that or any other reason, the job replaces the
156-
`commit-queue` label with `commit-queue-failed`, leaves a comment with the
157-
output, and then aborts the landing session. If the abort fails, the queue
158-
stops instead of continuing in an unknown state.
159-
160-
Fast-tracked PRs use the metadata check before checkout and the landing script.
161-
If the fast-track request has not yet received enough collaborator thumbs-up,
162-
the queue keeps the `commit-queue` label and retries until either the
163-
fast-track request is approved or the PR becomes landable through the regular
164-
wait-time rules. The commit queue does not create the fast-track request
165-
comment; that is handled when the `fast-track` label is added. If that comment
166-
is missing, the queue reports the failure instead of keeping the PR queued.
167-
168-
If no errors happen during `git node land`, the script either pushes the direct
169-
rebase landing to `main` or uses GitHub's squash merge API for single-commit and
170-
fixup landings. It then leaves a `Landed in ...` comment in the PR. GitHub
171-
closes PRs merged through the merge API automatically; for direct pushes, the
172-
script closes the PR. The script then removes the `commit-queue` label.
173-
Iteration continues until all PRs have done the steps above.
174-
175-
## Reverting broken commits
176-
177-
Reverting broken commits is done manually by collaborators, just like when
178-
commits are landed manually via `git node land`. An easy way to revert is a
179-
good feature for the project, but is not explicitly required for the Commit
180-
Queue to work because the Action lands PRs just like collaborators do today. If
181-
once we start using the Commit Queue we notice that the number of required
182-
reverts increases drastically, we can pause the queue until a Revert Queue is
183-
implemented, but until then we can enable the Commit Queue and then work on a
184-
Revert Queue as a follow-up.
34+
as backport PRs, are ignored).

‎tools/actions/commit-queue.sh‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
set -xe
44

5-
OWNER=$1
6-
REPOSITORY=$2
7-
shift 2
8-
95
UPSTREAM=origin
106
DEFAULT_BRANCH=main
117

128
COMMIT_QUEUE_LABEL="commit-queue"
139
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1410

11+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
12+
1513
commit_queue_failed() {
1614
pr=$1
1715

18-
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
16+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1917

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2218
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
2319
echo"$body"
2420

25-
gh pr comment "$pr" --body "$body"
21+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2622

2723
rm output
2824
}
2925

30-
# TODO(mmarchini): should this be set with whoever added the label for each PR?
31-
git config --local user.email "github-bot@iojs.org"
32-
git config --local user.name "Node.js GitHub Bot"
33-
3426
SHOULD_ABORT=
3527

3628
forprin"$@";do
37-
gh pr view "$pr" --json labels --jq ".labels"> labels.json
29+
gh -R "$GITHUB_REPOSITORY"pr view "$pr" --json labels --jq ".labels"> labels.json
3830

3931
if jq -e 'map(.name) | index("commit-queue-squash")'< labels.json;then
4032
MULTIPLE_COMMIT_POLICY="--fixupAll"
@@ -87,7 +79,7 @@ for pr in "$@"; do
8779
--arg body "${commit_body}" \
8880
--arg head "${commit_head}" \
8981
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}'|\
90-
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
82+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
9183
--jq 'if .merged then .sha else halt_error end'
9284
)";then
9385
commit_queue_failed "$pr"
@@ -97,12 +89,12 @@ for pr in "$@"; do
9789

9890
rm output
9991

100-
gh pr comment "$pr" --body "Landed in $commits"
92+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "Landed in $commits"
10193

102-
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
94+
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh -R "$GITHUB_REPOSITORY"pr close "$pr"
10395

10496
# Delete the commit queue label (but ignore errors, it's no big deal if a closed PR still has the label)
105-
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
97+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
10698
done
10799

108100
rm -f labels.json

‎tools/actions/start-ci.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ set -xe
44

55
REQUEST_CI_LABEL="request-ci"
66
REQUEST_CI_FAILED_LABEL="request-ci-failed"
7+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
78

89
forprin"$@";do
9-
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
1011

1112
ci_started=yes
1213
rm -f output;
@@ -15,14 +16,12 @@ for pr in "$@"; do
1516

1617
if [ "$ci_started"="no" ];then
1718
# Do we need to reset?
18-
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
1920

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2221
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
2322
echo"$body"
2423

25-
gh pr comment "$pr" --body "$body"
24+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2625

2726
rm output
2827
fi

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 41edd2f

Browse files
committed
tools: make env variables consistent in cron jobs
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65168 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ec956f2 commit 41edd2f

5 files changed

Lines changed: 36 additions & 195 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This action uses the following secrets:
2+
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3+
# JENKINS_TOKEN: Jenkins token, to be used to start CI
14
name: Auto Start CI
25

36
on:
@@ -36,11 +39,13 @@ jobs:
3639
-t '{{ range . }}{{ .number }} {{ end }}' \
3740
--limit 5)" >> "$GITHUB_OUTPUT"
3841
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ github.token }}
4043
start-ci:
4144
permissions:
45+
checks: read
4246
contents: read
4347
pull-requests: write
48+
statuses: read
4449
needs: get-prs-for-ci
4550
if: needs.get-prs-for-ci.outputs.numbers != ''
4651
runs-on: ubuntu-slim
@@ -59,16 +64,15 @@ jobs:
5964
ncu-config set token "$GH_TOKEN"
6065
ncu-config set jenkins_token "$JENKINS_TOKEN"
6166
ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
62-
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
67+
ncu-config set repo "${GITHUB_REPOSITORY#*/}"
6368
env:
6469
USERNAME: ${{ secrets.JENKINS_USER }}
65-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
70+
GH_TOKEN: ${{ github.token }}
6671
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6772

6873
- name: Start the CI
6974
run: |
7075
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
7176
| sh -s -- ${{ needs.get-prs-for-ci.outputs.numbers }}
7277
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GH_REPO: ${{ github.repository }}
78+
GH_TOKEN: ${{ github.token }}

‎.github/workflows/commit-queue.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
jq -r -s 'reduce .[] as $pr ([]; if index($pr) then . else . + [$pr] end) | join(" ")')
5353
echo "candidates=$candidates" >> "$GITHUB_OUTPUT"
5454
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
GH_TOKEN: ${{ github.token }}
5656
commitQueue:
5757
needs: get_candidate_prs
5858
if: needs.get_candidate_prs.outputs.candidates != ''
@@ -63,18 +63,14 @@ jobs:
6363
statuses: read
6464
runs-on: ubuntu-slim
6565
steps:
66-
# Install dependencies
6766
- name: Install Node.js
6867
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6968
with:
7069
node-version: ${{ env.NODE_VERSION }}
70+
7171
- name: Install @node-core/utils
7272
run: npm install -g @node-core/utils
7373

74-
- name: Set variables
75-
run: |
76-
echo "REPOSITORY=$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" >> "$GITHUB_ENV"
77-
7874
- name: Configure @node-core/utils
7975
run: |
8076
# Keep the config outside the workspace so checkout does not remove it.
@@ -83,7 +79,7 @@ jobs:
8379
ncu-config --global set username "$USERNAME"
8480
ncu-config --global set token "$GH_TOKEN"
8581
ncu-config --global set jenkins_token "$JENKINS_TOKEN"
86-
ncu-config --global set repo "${REPOSITORY}"
82+
ncu-config --global set repo "${GITHUB_REPOSITORY#*/}"
8783
ncu-config --global set owner "${GITHUB_REPOSITORY_OWNER}"
8884
env:
8985
USERNAME: ${{ secrets.JENKINS_USER }}
@@ -102,8 +98,6 @@ jobs:
10298
metadata="${RUNNER_TEMP}/metadata-${pr}.json"
10399
output="${RUNNER_TEMP}/metadata-${pr}.txt"
104100
if git node metadata "$pr" \
105-
--owner "$GITHUB_REPOSITORY_OWNER" \
106-
--repo "$REPOSITORY" \
107101
--readme "$readme" \
108102
--json > "$metadata" 2> "$output"; then
109103
metadata_status=0
@@ -171,7 +165,9 @@ jobs:
171165
- name: Start the Commit Queue
172166
if: steps.get_mergeable_prs.outputs.numbers != ''
173167
run: |
168+
git config --local user.email "github-bot@iojs.org"
169+
git config --local user.name "Node.js GitHub Bot"
174170
ncu-config set token "$GH_TOKEN"
175-
./tools/actions/commit-queue.sh "${GITHUB_REPOSITORY_OWNER}" "${REPOSITORY}" ${{ steps.get_mergeable_prs.outputs.numbers }}
171+
./tools/actions/commit-queue.sh ${{ steps.get_mergeable_prs.outputs.numbers }}
176172
env:
177173
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

‎doc/contributing/commit-queue.md‎

Lines changed: 8 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,24 @@ blocked on a deferrable condition, currently wait time, the queue leaves the
1111
label in place and retries later. Other failures continue to the existing
1212
landing and failure-reporting path.
1313

14-
This document gives an overview of how the Commit Queue works, as well as
15-
implementation details, reasoning for design choices, and current limitations.
16-
17-
## Overview
18-
19-
From a high-level, the Commit Queue works as follows:
20-
21-
1. Collaborators will add `commit-queue` label to pull requests they want the
22-
queue to land. The label can be added before the pull request has completed
23-
its wait time. Required approvals must already be in place, and any required
24-
CI must have completed successfully. The commit queue does not request CI on
25-
its own.
26-
2. On each scheduled run, the queue builds a candidate list from open pull
27-
requests with the `commit-queue` label and without the `blocked` label. A
28-
candidate must also either have been created at least two days earlier or
29-
have the `fast-track` label. Other labeled pull requests retain the label
30-
until they become old enough or are fast-tracked. The workflow uses a
31-
five-minute cron, but GitHub Actions scheduled workflows are not guaranteed
32-
to run exactly every five minutes. For each candidate, the queue will:
33-
1. In the landing job, install and configure `@node-core/utils`, then run a
34-
metadata-only readiness check without checking out the repository
35-
2. If the metadata check exits with a deferrable readiness code, meaning
36-
the PR is only blocked on wait time, keep the `commit-queue` label and
37-
skip this PR until a later queue run
38-
3. Run `git node land` for ready PRs and PRs with hard or mixed readiness
39-
failures, keeping the `commit-queue` label in place during the attempt
40-
4. If it fails:
41-
1. Replace the `commit-queue` label with the `commit-queue-failed` label
42-
2. Leave a comment on the PR with the output from `git node land`
43-
3. Abort the `git node land` session. If the abort succeeds, continue to
44-
the next PR; otherwise, stop the queue in an unknown state
45-
5. If it succeeds:
46-
1. Push or merge the changes into nodejs/node
47-
2. Leave a comment on the PR with `Landed in ...`
48-
3. Close the PR
49-
4. Remove the `commit-queue` label
50-
5. Go to next PR in the queue
51-
5214
To make the Commit Queue squash all the commits of a pull request into the
5315
first one, add the `commit-queue-squash` label.
5416
To make the Commit Queue land a pull request containing several commits, add the
5517
`commit-queue-rebase` label. When using this option, make sure
5618
that all commits are self-contained, meaning every commit should pass all tests.
5719

20+
The implementation is in `commit-queue.yml` and `commit-queue.sh`.
21+
5822
## Current limitations
5923

60-
The Commit Queue feature is still in early stages, and as such it might not
61-
work for more complex pull requests. These are the currently known limitations
62-
of the commit queue:
24+
These are the currently known limitations of the commit queue:
6325

6426
1. All commits in a pull request must either be following commit message
6527
guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6628
commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash)
67-
option
68-
2. A CI must have run and succeeded since the last change on the PR
69-
3. A collaborator must have approved the PR since the last change
70-
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored)
29+
option.
30+
2. A CI must have run and succeeded since the last change on the PR.
31+
3. A collaborator must have approved the PR since the last change.
32+
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored).
7133
5. The PR must target the `main` branch (PRs opened against other branches, such
72-
as backport PRs, are ignored)
73-
74-
## Implementation
75-
76-
The [action](../../.github/workflows/commit-queue.yml) runs on scheduled events.
77-
It uses a five-minute cron because that is the smallest interval accepted by
78-
GitHub Actions. Scheduled workflows are not guaranteed to run exactly at that
79-
cadence and might take longer between runs.
80-
81-
The workflow also uses a concurrency group so only one commit queue run can be
82-
active at a time. If a scheduled run starts while a previous run is still
83-
running, GitHub Actions keeps at most one pending run for the same concurrency
84-
group. A newer pending run replaces an older pending run.
85-
86-
Using the scheduler is preferable over using pull\_request\_target for two
87-
reasons:
88-
89-
1. if two Commit Queue Actions execution overlap, there's a high-risk that
90-
the last one to finish will fail because the local branch will be out of
91-
sync with the remote after the first Action pushes. `issue_comment` event
92-
has the same limitation.
93-
2.`pull_request_target` will only run if the Action exists on the base commit
94-
of a pull request, and it will run the Action version present on that
95-
commit, meaning we wouldn't be able to use it for already opened PRs
96-
without rebasing them first.
97-
98-
The workflow starts with a small candidate job that uses GitHub CLI to fetch
99-
open pull requests with the `commit-queue` label and without the `blocked`
100-
label. It fetches two buckets: pull requests created at least two days earlier
101-
and pull requests with the `fast-track` label. The job de-duplicates the
102-
buckets before passing the candidates to the landing job. Pull requests in
103-
neither bucket remain labeled but are not processed during that run.
104-
105-
If there are candidate PRs, the landing job installs and configures
106-
`@node-core/utils` once with a personal token and a Jenkins token from
107-
[@nodejs-github-bot](https://github.com/nodejs/github-bot). It then downloads
108-
the workflow commit's README without checking out the repository and runs
109-
`git node metadata --readme --json` for each candidate. This uses the same
110-
`@node-core/utils` PR readiness checks as `git node land`, but does not clone,
111-
fetch, or merge the PR. The filter consumes the structured metadata result
112-
and its exit code instead of matching human-readable output:
113-
114-
* exit code `0`: the PR is ready and is passed to
115-
[`commit-queue.sh`](../../tools/actions/commit-queue.sh)
116-
* exit codes `20`-`29`: the PR is not ready for a deferrable metadata reason,
117-
currently wait time, so it keeps the `commit-queue` label and is retried
118-
later
119-
* exit codes `40`-`49`: the PR has a hard or mixed metadata readiness failure
120-
and is passed to [`commit-queue.sh`](../../tools/actions/commit-queue.sh)
121-
122-
The `20`-`29` exit code range is reserved by `@node-core/utils` for deferrable
123-
metadata readiness states, and `40`-`49` is reserved for hard metadata failure
124-
states. Unknown filter failures fail the workflow before starting the landing
125-
script and leave PR labels unchanged so the queue can retry on a later
126-
scheduled run. PRs passed through with exit code `40`-`49` continue through
127-
`commit-queue.sh`. The workflow checks out the repository only when at least
128-
one PR remains after filtering. The script does not separately skip PRs with a
129-
`request-ci` label or pending GitHub checks. Instead, `git node land` performs
130-
the landing checks and the script reports any failure through the normal queue
131-
failure path.
132-
133-
> The personal token needs permission for public repositories and to read
134-
> profiles. It is used by `@node-core/utils` and by the landing job for
135-
> checkout, label and comment updates, merging, and pushing. Jenkins token is
136-
> required to check CI status.
137-
138-
`commit-queue.sh` receives the following positional arguments:
139-
140-
1. The repository owner
141-
2. The repository name
142-
3. Every positional argument starting at this one will be a pull request ID of
143-
a pull request with commit-queue set.
144-
145-
The script iterates over the pull requests. For each PR, it uses GitHub CLI to
146-
fetch the labels and select the multiple-commit policy, then runs
147-
`git node land`, forwarding stdout and stderr to a file. It does not perform a
148-
separate CI preflight; `git node land` performs the current readiness and CI
149-
validation.
150-
151-
The script keeps the `commit-queue` label in place while `git node land` is
152-
running. PRs that are only blocked on wait time should have already been
153-
filtered by the metadata check. A hard or mixed readiness failure is passed
154-
through so `git node land` can produce the failure output. If the landing
155-
attempt fails for that or any other reason, the job replaces the
156-
`commit-queue` label with `commit-queue-failed`, leaves a comment with the
157-
output, and then aborts the landing session. If the abort fails, the queue
158-
stops instead of continuing in an unknown state.
159-
160-
Fast-tracked PRs use the metadata check before checkout and the landing script.
161-
If the fast-track request has not yet received enough collaborator thumbs-up,
162-
the queue keeps the `commit-queue` label and retries until either the
163-
fast-track request is approved or the PR becomes landable through the regular
164-
wait-time rules. The commit queue does not create the fast-track request
165-
comment; that is handled when the `fast-track` label is added. If that comment
166-
is missing, the queue reports the failure instead of keeping the PR queued.
167-
168-
If no errors happen during `git node land`, the script either pushes the direct
169-
rebase landing to `main` or uses GitHub's squash merge API for single-commit and
170-
fixup landings. It then leaves a `Landed in ...` comment in the PR. GitHub
171-
closes PRs merged through the merge API automatically; for direct pushes, the
172-
script closes the PR. The script then removes the `commit-queue` label.
173-
Iteration continues until all PRs have done the steps above.
174-
175-
## Reverting broken commits
176-
177-
Reverting broken commits is done manually by collaborators, just like when
178-
commits are landed manually via `git node land`. An easy way to revert is a
179-
good feature for the project, but is not explicitly required for the Commit
180-
Queue to work because the Action lands PRs just like collaborators do today. If
181-
once we start using the Commit Queue we notice that the number of required
182-
reverts increases drastically, we can pause the queue until a Revert Queue is
183-
implemented, but until then we can enable the Commit Queue and then work on a
184-
Revert Queue as a follow-up.
34+
as backport PRs, are ignored).

‎tools/actions/commit-queue.sh‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
set -xe
44

5-
OWNER=$1
6-
REPOSITORY=$2
7-
shift 2
8-
95
UPSTREAM=origin
106
DEFAULT_BRANCH=main
117

128
COMMIT_QUEUE_LABEL="commit-queue"
139
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1410

11+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
12+
1513
commit_queue_failed() {
1614
pr=$1
1715

18-
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
16+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1917

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2218
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
2319
echo"$body"
2420

25-
gh pr comment "$pr" --body "$body"
21+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2622

2723
rm output
2824
}
2925

30-
# TODO(mmarchini): should this be set with whoever added the label for each PR?
31-
git config --local user.email "github-bot@iojs.org"
32-
git config --local user.name "Node.js GitHub Bot"
33-
3426
SHOULD_ABORT=
3527

3628
forprin"$@";do
37-
gh pr view "$pr" --json labels --jq ".labels"> labels.json
29+
gh -R "$GITHUB_REPOSITORY"pr view "$pr" --json labels --jq ".labels"> labels.json
3830

3931
if jq -e 'map(.name) | index("commit-queue-squash")'< labels.json;then
4032
MULTIPLE_COMMIT_POLICY="--fixupAll"
@@ -87,7 +79,7 @@ for pr in "$@"; do
8779
--arg body "${commit_body}" \
8880
--arg head "${commit_head}" \
8981
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}'|\
90-
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
82+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
9183
--jq 'if .merged then .sha else halt_error end'
9284
)";then
9385
commit_queue_failed "$pr"
@@ -97,12 +89,12 @@ for pr in "$@"; do
9789

9890
rm output
9991

100-
gh pr comment "$pr" --body "Landed in $commits"
92+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "Landed in $commits"
10193

102-
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
94+
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh -R "$GITHUB_REPOSITORY"pr close "$pr"
10395

10496
# Delete the commit queue label (but ignore errors, it's no big deal if a closed PR still has the label)
105-
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
97+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
10698
done
10799

108100
rm -f labels.json

‎tools/actions/start-ci.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ set -xe
44

55
REQUEST_CI_LABEL="request-ci"
66
REQUEST_CI_FAILED_LABEL="request-ci-failed"
7+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
78

89
forprin"$@";do
9-
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
1011

1112
ci_started=yes
1213
rm -f output;
@@ -15,14 +16,12 @@ for pr in "$@"; do
1516

1617
if [ "$ci_started"="no" ];then
1718
# Do we need to reset?
18-
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
1920

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2221
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
2322
echo"$body"
2423

25-
gh pr comment "$pr" --body "$body"
24+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2625

2726
rm output
2827
fi

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 41edd2f

Browse files
committed
tools: make env variables consistent in cron jobs
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65168 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ec956f2 commit 41edd2f

5 files changed

Lines changed: 36 additions & 195 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This action uses the following secrets:
2+
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3+
# JENKINS_TOKEN: Jenkins token, to be used to start CI
14
name: Auto Start CI
25

36
on:
@@ -36,11 +39,13 @@ jobs:
3639
-t '{{ range . }}{{ .number }} {{ end }}' \
3740
--limit 5)" >> "$GITHUB_OUTPUT"
3841
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ github.token }}
4043
start-ci:
4144
permissions:
45+
checks: read
4246
contents: read
4347
pull-requests: write
48+
statuses: read
4449
needs: get-prs-for-ci
4550
if: needs.get-prs-for-ci.outputs.numbers != ''
4651
runs-on: ubuntu-slim
@@ -59,16 +64,15 @@ jobs:
5964
ncu-config set token "$GH_TOKEN"
6065
ncu-config set jenkins_token "$JENKINS_TOKEN"
6166
ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
62-
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
67+
ncu-config set repo "${GITHUB_REPOSITORY#*/}"
6368
env:
6469
USERNAME: ${{ secrets.JENKINS_USER }}
65-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
70+
GH_TOKEN: ${{ github.token }}
6671
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6772

6873
- name: Start the CI
6974
run: |
7075
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
7176
| sh -s -- ${{ needs.get-prs-for-ci.outputs.numbers }}
7277
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GH_REPO: ${{ github.repository }}
78+
GH_TOKEN: ${{ github.token }}

‎.github/workflows/commit-queue.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
jq -r -s 'reduce .[] as $pr ([]; if index($pr) then . else . + [$pr] end) | join(" ")')
5353
echo "candidates=$candidates" >> "$GITHUB_OUTPUT"
5454
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
GH_TOKEN: ${{ github.token }}
5656
commitQueue:
5757
needs: get_candidate_prs
5858
if: needs.get_candidate_prs.outputs.candidates != ''
@@ -63,18 +63,14 @@ jobs:
6363
statuses: read
6464
runs-on: ubuntu-slim
6565
steps:
66-
# Install dependencies
6766
- name: Install Node.js
6867
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6968
with:
7069
node-version: ${{ env.NODE_VERSION }}
70+
7171
- name: Install @node-core/utils
7272
run: npm install -g @node-core/utils
7373

74-
- name: Set variables
75-
run: |
76-
echo "REPOSITORY=$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" >> "$GITHUB_ENV"
77-
7874
- name: Configure @node-core/utils
7975
run: |
8076
# Keep the config outside the workspace so checkout does not remove it.
@@ -83,7 +79,7 @@ jobs:
8379
ncu-config --global set username "$USERNAME"
8480
ncu-config --global set token "$GH_TOKEN"
8581
ncu-config --global set jenkins_token "$JENKINS_TOKEN"
86-
ncu-config --global set repo "${REPOSITORY}"
82+
ncu-config --global set repo "${GITHUB_REPOSITORY#*/}"
8783
ncu-config --global set owner "${GITHUB_REPOSITORY_OWNER}"
8884
env:
8985
USERNAME: ${{ secrets.JENKINS_USER }}
@@ -102,8 +98,6 @@ jobs:
10298
metadata="${RUNNER_TEMP}/metadata-${pr}.json"
10399
output="${RUNNER_TEMP}/metadata-${pr}.txt"
104100
if git node metadata "$pr" \
105-
--owner "$GITHUB_REPOSITORY_OWNER" \
106-
--repo "$REPOSITORY" \
107101
--readme "$readme" \
108102
--json > "$metadata" 2> "$output"; then
109103
metadata_status=0
@@ -171,7 +165,9 @@ jobs:
171165
- name: Start the Commit Queue
172166
if: steps.get_mergeable_prs.outputs.numbers != ''
173167
run: |
168+
git config --local user.email "github-bot@iojs.org"
169+
git config --local user.name "Node.js GitHub Bot"
174170
ncu-config set token "$GH_TOKEN"
175-
./tools/actions/commit-queue.sh "${GITHUB_REPOSITORY_OWNER}" "${REPOSITORY}" ${{ steps.get_mergeable_prs.outputs.numbers }}
171+
./tools/actions/commit-queue.sh ${{ steps.get_mergeable_prs.outputs.numbers }}
176172
env:
177173
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

‎doc/contributing/commit-queue.md‎

Lines changed: 8 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,24 @@ blocked on a deferrable condition, currently wait time, the queue leaves the
1111
label in place and retries later. Other failures continue to the existing
1212
landing and failure-reporting path.
1313

14-
This document gives an overview of how the Commit Queue works, as well as
15-
implementation details, reasoning for design choices, and current limitations.
16-
17-
## Overview
18-
19-
From a high-level, the Commit Queue works as follows:
20-
21-
1. Collaborators will add `commit-queue` label to pull requests they want the
22-
queue to land. The label can be added before the pull request has completed
23-
its wait time. Required approvals must already be in place, and any required
24-
CI must have completed successfully. The commit queue does not request CI on
25-
its own.
26-
2. On each scheduled run, the queue builds a candidate list from open pull
27-
requests with the `commit-queue` label and without the `blocked` label. A
28-
candidate must also either have been created at least two days earlier or
29-
have the `fast-track` label. Other labeled pull requests retain the label
30-
until they become old enough or are fast-tracked. The workflow uses a
31-
five-minute cron, but GitHub Actions scheduled workflows are not guaranteed
32-
to run exactly every five minutes. For each candidate, the queue will:
33-
1. In the landing job, install and configure `@node-core/utils`, then run a
34-
metadata-only readiness check without checking out the repository
35-
2. If the metadata check exits with a deferrable readiness code, meaning
36-
the PR is only blocked on wait time, keep the `commit-queue` label and
37-
skip this PR until a later queue run
38-
3. Run `git node land` for ready PRs and PRs with hard or mixed readiness
39-
failures, keeping the `commit-queue` label in place during the attempt
40-
4. If it fails:
41-
1. Replace the `commit-queue` label with the `commit-queue-failed` label
42-
2. Leave a comment on the PR with the output from `git node land`
43-
3. Abort the `git node land` session. If the abort succeeds, continue to
44-
the next PR; otherwise, stop the queue in an unknown state
45-
5. If it succeeds:
46-
1. Push or merge the changes into nodejs/node
47-
2. Leave a comment on the PR with `Landed in ...`
48-
3. Close the PR
49-
4. Remove the `commit-queue` label
50-
5. Go to next PR in the queue
51-
5214
To make the Commit Queue squash all the commits of a pull request into the
5315
first one, add the `commit-queue-squash` label.
5416
To make the Commit Queue land a pull request containing several commits, add the
5517
`commit-queue-rebase` label. When using this option, make sure
5618
that all commits are self-contained, meaning every commit should pass all tests.
5719

20+
The implementation is in `commit-queue.yml` and `commit-queue.sh`.
21+
5822
## Current limitations
5923

60-
The Commit Queue feature is still in early stages, and as such it might not
61-
work for more complex pull requests. These are the currently known limitations
62-
of the commit queue:
24+
These are the currently known limitations of the commit queue:
6325

6426
1. All commits in a pull request must either be following commit message
6527
guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6628
commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash)
67-
option
68-
2. A CI must have run and succeeded since the last change on the PR
69-
3. A collaborator must have approved the PR since the last change
70-
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored)
29+
option.
30+
2. A CI must have run and succeeded since the last change on the PR.
31+
3. A collaborator must have approved the PR since the last change.
32+
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored).
7133
5. The PR must target the `main` branch (PRs opened against other branches, such
72-
as backport PRs, are ignored)
73-
74-
## Implementation
75-
76-
The [action](../../.github/workflows/commit-queue.yml) runs on scheduled events.
77-
It uses a five-minute cron because that is the smallest interval accepted by
78-
GitHub Actions. Scheduled workflows are not guaranteed to run exactly at that
79-
cadence and might take longer between runs.
80-
81-
The workflow also uses a concurrency group so only one commit queue run can be
82-
active at a time. If a scheduled run starts while a previous run is still
83-
running, GitHub Actions keeps at most one pending run for the same concurrency
84-
group. A newer pending run replaces an older pending run.
85-
86-
Using the scheduler is preferable over using pull\_request\_target for two
87-
reasons:
88-
89-
1. if two Commit Queue Actions execution overlap, there's a high-risk that
90-
the last one to finish will fail because the local branch will be out of
91-
sync with the remote after the first Action pushes. `issue_comment` event
92-
has the same limitation.
93-
2.`pull_request_target` will only run if the Action exists on the base commit
94-
of a pull request, and it will run the Action version present on that
95-
commit, meaning we wouldn't be able to use it for already opened PRs
96-
without rebasing them first.
97-
98-
The workflow starts with a small candidate job that uses GitHub CLI to fetch
99-
open pull requests with the `commit-queue` label and without the `blocked`
100-
label. It fetches two buckets: pull requests created at least two days earlier
101-
and pull requests with the `fast-track` label. The job de-duplicates the
102-
buckets before passing the candidates to the landing job. Pull requests in
103-
neither bucket remain labeled but are not processed during that run.
104-
105-
If there are candidate PRs, the landing job installs and configures
106-
`@node-core/utils` once with a personal token and a Jenkins token from
107-
[@nodejs-github-bot](https://github.com/nodejs/github-bot). It then downloads
108-
the workflow commit's README without checking out the repository and runs
109-
`git node metadata --readme --json` for each candidate. This uses the same
110-
`@node-core/utils` PR readiness checks as `git node land`, but does not clone,
111-
fetch, or merge the PR. The filter consumes the structured metadata result
112-
and its exit code instead of matching human-readable output:
113-
114-
* exit code `0`: the PR is ready and is passed to
115-
[`commit-queue.sh`](../../tools/actions/commit-queue.sh)
116-
* exit codes `20`-`29`: the PR is not ready for a deferrable metadata reason,
117-
currently wait time, so it keeps the `commit-queue` label and is retried
118-
later
119-
* exit codes `40`-`49`: the PR has a hard or mixed metadata readiness failure
120-
and is passed to [`commit-queue.sh`](../../tools/actions/commit-queue.sh)
121-
122-
The `20`-`29` exit code range is reserved by `@node-core/utils` for deferrable
123-
metadata readiness states, and `40`-`49` is reserved for hard metadata failure
124-
states. Unknown filter failures fail the workflow before starting the landing
125-
script and leave PR labels unchanged so the queue can retry on a later
126-
scheduled run. PRs passed through with exit code `40`-`49` continue through
127-
`commit-queue.sh`. The workflow checks out the repository only when at least
128-
one PR remains after filtering. The script does not separately skip PRs with a
129-
`request-ci` label or pending GitHub checks. Instead, `git node land` performs
130-
the landing checks and the script reports any failure through the normal queue
131-
failure path.
132-
133-
> The personal token needs permission for public repositories and to read
134-
> profiles. It is used by `@node-core/utils` and by the landing job for
135-
> checkout, label and comment updates, merging, and pushing. Jenkins token is
136-
> required to check CI status.
137-
138-
`commit-queue.sh` receives the following positional arguments:
139-
140-
1. The repository owner
141-
2. The repository name
142-
3. Every positional argument starting at this one will be a pull request ID of
143-
a pull request with commit-queue set.
144-
145-
The script iterates over the pull requests. For each PR, it uses GitHub CLI to
146-
fetch the labels and select the multiple-commit policy, then runs
147-
`git node land`, forwarding stdout and stderr to a file. It does not perform a
148-
separate CI preflight; `git node land` performs the current readiness and CI
149-
validation.
150-
151-
The script keeps the `commit-queue` label in place while `git node land` is
152-
running. PRs that are only blocked on wait time should have already been
153-
filtered by the metadata check. A hard or mixed readiness failure is passed
154-
through so `git node land` can produce the failure output. If the landing
155-
attempt fails for that or any other reason, the job replaces the
156-
`commit-queue` label with `commit-queue-failed`, leaves a comment with the
157-
output, and then aborts the landing session. If the abort fails, the queue
158-
stops instead of continuing in an unknown state.
159-
160-
Fast-tracked PRs use the metadata check before checkout and the landing script.
161-
If the fast-track request has not yet received enough collaborator thumbs-up,
162-
the queue keeps the `commit-queue` label and retries until either the
163-
fast-track request is approved or the PR becomes landable through the regular
164-
wait-time rules. The commit queue does not create the fast-track request
165-
comment; that is handled when the `fast-track` label is added. If that comment
166-
is missing, the queue reports the failure instead of keeping the PR queued.
167-
168-
If no errors happen during `git node land`, the script either pushes the direct
169-
rebase landing to `main` or uses GitHub's squash merge API for single-commit and
170-
fixup landings. It then leaves a `Landed in ...` comment in the PR. GitHub
171-
closes PRs merged through the merge API automatically; for direct pushes, the
172-
script closes the PR. The script then removes the `commit-queue` label.
173-
Iteration continues until all PRs have done the steps above.
174-
175-
## Reverting broken commits
176-
177-
Reverting broken commits is done manually by collaborators, just like when
178-
commits are landed manually via `git node land`. An easy way to revert is a
179-
good feature for the project, but is not explicitly required for the Commit
180-
Queue to work because the Action lands PRs just like collaborators do today. If
181-
once we start using the Commit Queue we notice that the number of required
182-
reverts increases drastically, we can pause the queue until a Revert Queue is
183-
implemented, but until then we can enable the Commit Queue and then work on a
184-
Revert Queue as a follow-up.
34+
as backport PRs, are ignored).

‎tools/actions/commit-queue.sh‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
set -xe
44

5-
OWNER=$1
6-
REPOSITORY=$2
7-
shift 2
8-
95
UPSTREAM=origin
106
DEFAULT_BRANCH=main
117

128
COMMIT_QUEUE_LABEL="commit-queue"
139
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1410

11+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
12+
1513
commit_queue_failed() {
1614
pr=$1
1715

18-
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
16+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1917

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2218
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
2319
echo"$body"
2420

25-
gh pr comment "$pr" --body "$body"
21+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2622

2723
rm output
2824
}
2925

30-
# TODO(mmarchini): should this be set with whoever added the label for each PR?
31-
git config --local user.email "github-bot@iojs.org"
32-
git config --local user.name "Node.js GitHub Bot"
33-
3426
SHOULD_ABORT=
3527

3628
forprin"$@";do
37-
gh pr view "$pr" --json labels --jq ".labels"> labels.json
29+
gh -R "$GITHUB_REPOSITORY"pr view "$pr" --json labels --jq ".labels"> labels.json
3830

3931
if jq -e 'map(.name) | index("commit-queue-squash")'< labels.json;then
4032
MULTIPLE_COMMIT_POLICY="--fixupAll"
@@ -87,7 +79,7 @@ for pr in "$@"; do
8779
--arg body "${commit_body}" \
8880
--arg head "${commit_head}" \
8981
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}'|\
90-
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
82+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
9183
--jq 'if .merged then .sha else halt_error end'
9284
)";then
9385
commit_queue_failed "$pr"
@@ -97,12 +89,12 @@ for pr in "$@"; do
9789

9890
rm output
9991

100-
gh pr comment "$pr" --body "Landed in $commits"
92+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "Landed in $commits"
10193

102-
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
94+
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh -R "$GITHUB_REPOSITORY"pr close "$pr"
10395

10496
# Delete the commit queue label (but ignore errors, it's no big deal if a closed PR still has the label)
105-
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
97+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
10698
done
10799

108100
rm -f labels.json

‎tools/actions/start-ci.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ set -xe
44

55
REQUEST_CI_LABEL="request-ci"
66
REQUEST_CI_FAILED_LABEL="request-ci-failed"
7+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
78

89
forprin"$@";do
9-
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
1011

1112
ci_started=yes
1213
rm -f output;
@@ -15,14 +16,12 @@ for pr in "$@"; do
1516

1617
if [ "$ci_started"="no" ];then
1718
# Do we need to reset?
18-
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
1920

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2221
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
2322
echo"$body"
2423

25-
gh pr comment "$pr" --body "$body"
24+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2625

2726
rm output
2827
fi

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 41edd2f

Browse files
committed
tools: make env variables consistent in cron jobs
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65168 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ec956f2 commit 41edd2f

5 files changed

Lines changed: 36 additions & 195 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This action uses the following secrets:
2+
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3+
# JENKINS_TOKEN: Jenkins token, to be used to start CI
14
name: Auto Start CI
25

36
on:
@@ -36,11 +39,13 @@ jobs:
3639
-t '{{ range . }}{{ .number }} {{ end }}' \
3740
--limit 5)" >> "$GITHUB_OUTPUT"
3841
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ github.token }}
4043
start-ci:
4144
permissions:
45+
checks: read
4246
contents: read
4347
pull-requests: write
48+
statuses: read
4449
needs: get-prs-for-ci
4550
if: needs.get-prs-for-ci.outputs.numbers != ''
4651
runs-on: ubuntu-slim
@@ -59,16 +64,15 @@ jobs:
5964
ncu-config set token "$GH_TOKEN"
6065
ncu-config set jenkins_token "$JENKINS_TOKEN"
6166
ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
62-
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
67+
ncu-config set repo "${GITHUB_REPOSITORY#*/}"
6368
env:
6469
USERNAME: ${{ secrets.JENKINS_USER }}
65-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
70+
GH_TOKEN: ${{ github.token }}
6671
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6772

6873
- name: Start the CI
6974
run: |
7075
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
7176
| sh -s -- ${{ needs.get-prs-for-ci.outputs.numbers }}
7277
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GH_REPO: ${{ github.repository }}
78+
GH_TOKEN: ${{ github.token }}

‎.github/workflows/commit-queue.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
jq -r -s 'reduce .[] as $pr ([]; if index($pr) then . else . + [$pr] end) | join(" ")')
5353
echo "candidates=$candidates" >> "$GITHUB_OUTPUT"
5454
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
GH_TOKEN: ${{ github.token }}
5656
commitQueue:
5757
needs: get_candidate_prs
5858
if: needs.get_candidate_prs.outputs.candidates != ''
@@ -63,18 +63,14 @@ jobs:
6363
statuses: read
6464
runs-on: ubuntu-slim
6565
steps:
66-
# Install dependencies
6766
- name: Install Node.js
6867
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6968
with:
7069
node-version: ${{ env.NODE_VERSION }}
70+
7171
- name: Install @node-core/utils
7272
run: npm install -g @node-core/utils
7373

74-
- name: Set variables
75-
run: |
76-
echo "REPOSITORY=$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" >> "$GITHUB_ENV"
77-
7874
- name: Configure @node-core/utils
7975
run: |
8076
# Keep the config outside the workspace so checkout does not remove it.
@@ -83,7 +79,7 @@ jobs:
8379
ncu-config --global set username "$USERNAME"
8480
ncu-config --global set token "$GH_TOKEN"
8581
ncu-config --global set jenkins_token "$JENKINS_TOKEN"
86-
ncu-config --global set repo "${REPOSITORY}"
82+
ncu-config --global set repo "${GITHUB_REPOSITORY#*/}"
8783
ncu-config --global set owner "${GITHUB_REPOSITORY_OWNER}"
8884
env:
8985
USERNAME: ${{ secrets.JENKINS_USER }}
@@ -102,8 +98,6 @@ jobs:
10298
metadata="${RUNNER_TEMP}/metadata-${pr}.json"
10399
output="${RUNNER_TEMP}/metadata-${pr}.txt"
104100
if git node metadata "$pr" \
105-
--owner "$GITHUB_REPOSITORY_OWNER" \
106-
--repo "$REPOSITORY" \
107101
--readme "$readme" \
108102
--json > "$metadata" 2> "$output"; then
109103
metadata_status=0
@@ -171,7 +165,9 @@ jobs:
171165
- name: Start the Commit Queue
172166
if: steps.get_mergeable_prs.outputs.numbers != ''
173167
run: |
168+
git config --local user.email "github-bot@iojs.org"
169+
git config --local user.name "Node.js GitHub Bot"
174170
ncu-config set token "$GH_TOKEN"
175-
./tools/actions/commit-queue.sh "${GITHUB_REPOSITORY_OWNER}" "${REPOSITORY}" ${{ steps.get_mergeable_prs.outputs.numbers }}
171+
./tools/actions/commit-queue.sh ${{ steps.get_mergeable_prs.outputs.numbers }}
176172
env:
177173
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

‎doc/contributing/commit-queue.md‎

Lines changed: 8 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,24 @@ blocked on a deferrable condition, currently wait time, the queue leaves the
1111
label in place and retries later. Other failures continue to the existing
1212
landing and failure-reporting path.
1313

14-
This document gives an overview of how the Commit Queue works, as well as
15-
implementation details, reasoning for design choices, and current limitations.
16-
17-
## Overview
18-
19-
From a high-level, the Commit Queue works as follows:
20-
21-
1. Collaborators will add `commit-queue` label to pull requests they want the
22-
queue to land. The label can be added before the pull request has completed
23-
its wait time. Required approvals must already be in place, and any required
24-
CI must have completed successfully. The commit queue does not request CI on
25-
its own.
26-
2. On each scheduled run, the queue builds a candidate list from open pull
27-
requests with the `commit-queue` label and without the `blocked` label. A
28-
candidate must also either have been created at least two days earlier or
29-
have the `fast-track` label. Other labeled pull requests retain the label
30-
until they become old enough or are fast-tracked. The workflow uses a
31-
five-minute cron, but GitHub Actions scheduled workflows are not guaranteed
32-
to run exactly every five minutes. For each candidate, the queue will:
33-
1. In the landing job, install and configure `@node-core/utils`, then run a
34-
metadata-only readiness check without checking out the repository
35-
2. If the metadata check exits with a deferrable readiness code, meaning
36-
the PR is only blocked on wait time, keep the `commit-queue` label and
37-
skip this PR until a later queue run
38-
3. Run `git node land` for ready PRs and PRs with hard or mixed readiness
39-
failures, keeping the `commit-queue` label in place during the attempt
40-
4. If it fails:
41-
1. Replace the `commit-queue` label with the `commit-queue-failed` label
42-
2. Leave a comment on the PR with the output from `git node land`
43-
3. Abort the `git node land` session. If the abort succeeds, continue to
44-
the next PR; otherwise, stop the queue in an unknown state
45-
5. If it succeeds:
46-
1. Push or merge the changes into nodejs/node
47-
2. Leave a comment on the PR with `Landed in ...`
48-
3. Close the PR
49-
4. Remove the `commit-queue` label
50-
5. Go to next PR in the queue
51-
5214
To make the Commit Queue squash all the commits of a pull request into the
5315
first one, add the `commit-queue-squash` label.
5416
To make the Commit Queue land a pull request containing several commits, add the
5517
`commit-queue-rebase` label. When using this option, make sure
5618
that all commits are self-contained, meaning every commit should pass all tests.
5719

20+
The implementation is in `commit-queue.yml` and `commit-queue.sh`.
21+
5822
## Current limitations
5923

60-
The Commit Queue feature is still in early stages, and as such it might not
61-
work for more complex pull requests. These are the currently known limitations
62-
of the commit queue:
24+
These are the currently known limitations of the commit queue:
6325

6426
1. All commits in a pull request must either be following commit message
6527
guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6628
commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash)
67-
option
68-
2. A CI must have run and succeeded since the last change on the PR
69-
3. A collaborator must have approved the PR since the last change
70-
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored)
29+
option.
30+
2. A CI must have run and succeeded since the last change on the PR.
31+
3. A collaborator must have approved the PR since the last change.
32+
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored).
7133
5. The PR must target the `main` branch (PRs opened against other branches, such
72-
as backport PRs, are ignored)
73-
74-
## Implementation
75-
76-
The [action](../../.github/workflows/commit-queue.yml) runs on scheduled events.
77-
It uses a five-minute cron because that is the smallest interval accepted by
78-
GitHub Actions. Scheduled workflows are not guaranteed to run exactly at that
79-
cadence and might take longer between runs.
80-
81-
The workflow also uses a concurrency group so only one commit queue run can be
82-
active at a time. If a scheduled run starts while a previous run is still
83-
running, GitHub Actions keeps at most one pending run for the same concurrency
84-
group. A newer pending run replaces an older pending run.
85-
86-
Using the scheduler is preferable over using pull\_request\_target for two
87-
reasons:
88-
89-
1. if two Commit Queue Actions execution overlap, there's a high-risk that
90-
the last one to finish will fail because the local branch will be out of
91-
sync with the remote after the first Action pushes. `issue_comment` event
92-
has the same limitation.
93-
2.`pull_request_target` will only run if the Action exists on the base commit
94-
of a pull request, and it will run the Action version present on that
95-
commit, meaning we wouldn't be able to use it for already opened PRs
96-
without rebasing them first.
97-
98-
The workflow starts with a small candidate job that uses GitHub CLI to fetch
99-
open pull requests with the `commit-queue` label and without the `blocked`
100-
label. It fetches two buckets: pull requests created at least two days earlier
101-
and pull requests with the `fast-track` label. The job de-duplicates the
102-
buckets before passing the candidates to the landing job. Pull requests in
103-
neither bucket remain labeled but are not processed during that run.
104-
105-
If there are candidate PRs, the landing job installs and configures
106-
`@node-core/utils` once with a personal token and a Jenkins token from
107-
[@nodejs-github-bot](https://github.com/nodejs/github-bot). It then downloads
108-
the workflow commit's README without checking out the repository and runs
109-
`git node metadata --readme --json` for each candidate. This uses the same
110-
`@node-core/utils` PR readiness checks as `git node land`, but does not clone,
111-
fetch, or merge the PR. The filter consumes the structured metadata result
112-
and its exit code instead of matching human-readable output:
113-
114-
* exit code `0`: the PR is ready and is passed to
115-
[`commit-queue.sh`](../../tools/actions/commit-queue.sh)
116-
* exit codes `20`-`29`: the PR is not ready for a deferrable metadata reason,
117-
currently wait time, so it keeps the `commit-queue` label and is retried
118-
later
119-
* exit codes `40`-`49`: the PR has a hard or mixed metadata readiness failure
120-
and is passed to [`commit-queue.sh`](../../tools/actions/commit-queue.sh)
121-
122-
The `20`-`29` exit code range is reserved by `@node-core/utils` for deferrable
123-
metadata readiness states, and `40`-`49` is reserved for hard metadata failure
124-
states. Unknown filter failures fail the workflow before starting the landing
125-
script and leave PR labels unchanged so the queue can retry on a later
126-
scheduled run. PRs passed through with exit code `40`-`49` continue through
127-
`commit-queue.sh`. The workflow checks out the repository only when at least
128-
one PR remains after filtering. The script does not separately skip PRs with a
129-
`request-ci` label or pending GitHub checks. Instead, `git node land` performs
130-
the landing checks and the script reports any failure through the normal queue
131-
failure path.
132-
133-
> The personal token needs permission for public repositories and to read
134-
> profiles. It is used by `@node-core/utils` and by the landing job for
135-
> checkout, label and comment updates, merging, and pushing. Jenkins token is
136-
> required to check CI status.
137-
138-
`commit-queue.sh` receives the following positional arguments:
139-
140-
1. The repository owner
141-
2. The repository name
142-
3. Every positional argument starting at this one will be a pull request ID of
143-
a pull request with commit-queue set.
144-
145-
The script iterates over the pull requests. For each PR, it uses GitHub CLI to
146-
fetch the labels and select the multiple-commit policy, then runs
147-
`git node land`, forwarding stdout and stderr to a file. It does not perform a
148-
separate CI preflight; `git node land` performs the current readiness and CI
149-
validation.
150-
151-
The script keeps the `commit-queue` label in place while `git node land` is
152-
running. PRs that are only blocked on wait time should have already been
153-
filtered by the metadata check. A hard or mixed readiness failure is passed
154-
through so `git node land` can produce the failure output. If the landing
155-
attempt fails for that or any other reason, the job replaces the
156-
`commit-queue` label with `commit-queue-failed`, leaves a comment with the
157-
output, and then aborts the landing session. If the abort fails, the queue
158-
stops instead of continuing in an unknown state.
159-
160-
Fast-tracked PRs use the metadata check before checkout and the landing script.
161-
If the fast-track request has not yet received enough collaborator thumbs-up,
162-
the queue keeps the `commit-queue` label and retries until either the
163-
fast-track request is approved or the PR becomes landable through the regular
164-
wait-time rules. The commit queue does not create the fast-track request
165-
comment; that is handled when the `fast-track` label is added. If that comment
166-
is missing, the queue reports the failure instead of keeping the PR queued.
167-
168-
If no errors happen during `git node land`, the script either pushes the direct
169-
rebase landing to `main` or uses GitHub's squash merge API for single-commit and
170-
fixup landings. It then leaves a `Landed in ...` comment in the PR. GitHub
171-
closes PRs merged through the merge API automatically; for direct pushes, the
172-
script closes the PR. The script then removes the `commit-queue` label.
173-
Iteration continues until all PRs have done the steps above.
174-
175-
## Reverting broken commits
176-
177-
Reverting broken commits is done manually by collaborators, just like when
178-
commits are landed manually via `git node land`. An easy way to revert is a
179-
good feature for the project, but is not explicitly required for the Commit
180-
Queue to work because the Action lands PRs just like collaborators do today. If
181-
once we start using the Commit Queue we notice that the number of required
182-
reverts increases drastically, we can pause the queue until a Revert Queue is
183-
implemented, but until then we can enable the Commit Queue and then work on a
184-
Revert Queue as a follow-up.
34+
as backport PRs, are ignored).

‎tools/actions/commit-queue.sh‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
set -xe
44

5-
OWNER=$1
6-
REPOSITORY=$2
7-
shift 2
8-
95
UPSTREAM=origin
106
DEFAULT_BRANCH=main
117

128
COMMIT_QUEUE_LABEL="commit-queue"
139
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1410

11+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
12+
1513
commit_queue_failed() {
1614
pr=$1
1715

18-
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
16+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1917

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2218
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
2319
echo"$body"
2420

25-
gh pr comment "$pr" --body "$body"
21+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2622

2723
rm output
2824
}
2925

30-
# TODO(mmarchini): should this be set with whoever added the label for each PR?
31-
git config --local user.email "github-bot@iojs.org"
32-
git config --local user.name "Node.js GitHub Bot"
33-
3426
SHOULD_ABORT=
3527

3628
forprin"$@";do
37-
gh pr view "$pr" --json labels --jq ".labels"> labels.json
29+
gh -R "$GITHUB_REPOSITORY"pr view "$pr" --json labels --jq ".labels"> labels.json
3830

3931
if jq -e 'map(.name) | index("commit-queue-squash")'< labels.json;then
4032
MULTIPLE_COMMIT_POLICY="--fixupAll"
@@ -87,7 +79,7 @@ for pr in "$@"; do
8779
--arg body "${commit_body}" \
8880
--arg head "${commit_head}" \
8981
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}'|\
90-
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
82+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
9183
--jq 'if .merged then .sha else halt_error end'
9284
)";then
9385
commit_queue_failed "$pr"
@@ -97,12 +89,12 @@ for pr in "$@"; do
9789

9890
rm output
9991

100-
gh pr comment "$pr" --body "Landed in $commits"
92+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "Landed in $commits"
10193

102-
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
94+
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh -R "$GITHUB_REPOSITORY"pr close "$pr"
10395

10496
# Delete the commit queue label (but ignore errors, it's no big deal if a closed PR still has the label)
105-
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
97+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
10698
done
10799

108100
rm -f labels.json

‎tools/actions/start-ci.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ set -xe
44

55
REQUEST_CI_LABEL="request-ci"
66
REQUEST_CI_FAILED_LABEL="request-ci-failed"
7+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
78

89
forprin"$@";do
9-
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
1011

1112
ci_started=yes
1213
rm -f output;
@@ -15,14 +16,12 @@ for pr in "$@"; do
1516

1617
if [ "$ci_started"="no" ];then
1718
# Do we need to reset?
18-
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
1920

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2221
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
2322
echo"$body"
2423

25-
gh pr comment "$pr" --body "$body"
24+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2625

2726
rm output
2827
fi

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 41edd2f

Browse files
committed
tools: make env variables consistent in cron jobs
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65168 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ec956f2 commit 41edd2f

5 files changed

Lines changed: 36 additions & 195 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This action uses the following secrets:
2+
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3+
# JENKINS_TOKEN: Jenkins token, to be used to start CI
14
name: Auto Start CI
25

36
on:
@@ -36,11 +39,13 @@ jobs:
3639
-t '{{ range . }}{{ .number }} {{ end }}' \
3740
--limit 5)" >> "$GITHUB_OUTPUT"
3841
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ github.token }}
4043
start-ci:
4144
permissions:
45+
checks: read
4246
contents: read
4347
pull-requests: write
48+
statuses: read
4449
needs: get-prs-for-ci
4550
if: needs.get-prs-for-ci.outputs.numbers != ''
4651
runs-on: ubuntu-slim
@@ -59,16 +64,15 @@ jobs:
5964
ncu-config set token "$GH_TOKEN"
6065
ncu-config set jenkins_token "$JENKINS_TOKEN"
6166
ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
62-
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
67+
ncu-config set repo "${GITHUB_REPOSITORY#*/}"
6368
env:
6469
USERNAME: ${{ secrets.JENKINS_USER }}
65-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
70+
GH_TOKEN: ${{ github.token }}
6671
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6772

6873
- name: Start the CI
6974
run: |
7075
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
7176
| sh -s -- ${{ needs.get-prs-for-ci.outputs.numbers }}
7277
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GH_REPO: ${{ github.repository }}
78+
GH_TOKEN: ${{ github.token }}

‎.github/workflows/commit-queue.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
jq -r -s 'reduce .[] as $pr ([]; if index($pr) then . else . + [$pr] end) | join(" ")')
5353
echo "candidates=$candidates" >> "$GITHUB_OUTPUT"
5454
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
GH_TOKEN: ${{ github.token }}
5656
commitQueue:
5757
needs: get_candidate_prs
5858
if: needs.get_candidate_prs.outputs.candidates != ''
@@ -63,18 +63,14 @@ jobs:
6363
statuses: read
6464
runs-on: ubuntu-slim
6565
steps:
66-
# Install dependencies
6766
- name: Install Node.js
6867
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6968
with:
7069
node-version: ${{ env.NODE_VERSION }}
70+
7171
- name: Install @node-core/utils
7272
run: npm install -g @node-core/utils
7373

74-
- name: Set variables
75-
run: |
76-
echo "REPOSITORY=$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" >> "$GITHUB_ENV"
77-
7874
- name: Configure @node-core/utils
7975
run: |
8076
# Keep the config outside the workspace so checkout does not remove it.
@@ -83,7 +79,7 @@ jobs:
8379
ncu-config --global set username "$USERNAME"
8480
ncu-config --global set token "$GH_TOKEN"
8581
ncu-config --global set jenkins_token "$JENKINS_TOKEN"
86-
ncu-config --global set repo "${REPOSITORY}"
82+
ncu-config --global set repo "${GITHUB_REPOSITORY#*/}"
8783
ncu-config --global set owner "${GITHUB_REPOSITORY_OWNER}"
8884
env:
8985
USERNAME: ${{ secrets.JENKINS_USER }}
@@ -102,8 +98,6 @@ jobs:
10298
metadata="${RUNNER_TEMP}/metadata-${pr}.json"
10399
output="${RUNNER_TEMP}/metadata-${pr}.txt"
104100
if git node metadata "$pr" \
105-
--owner "$GITHUB_REPOSITORY_OWNER" \
106-
--repo "$REPOSITORY" \
107101
--readme "$readme" \
108102
--json > "$metadata" 2> "$output"; then
109103
metadata_status=0
@@ -171,7 +165,9 @@ jobs:
171165
- name: Start the Commit Queue
172166
if: steps.get_mergeable_prs.outputs.numbers != ''
173167
run: |
168+
git config --local user.email "github-bot@iojs.org"
169+
git config --local user.name "Node.js GitHub Bot"
174170
ncu-config set token "$GH_TOKEN"
175-
./tools/actions/commit-queue.sh "${GITHUB_REPOSITORY_OWNER}" "${REPOSITORY}" ${{ steps.get_mergeable_prs.outputs.numbers }}
171+
./tools/actions/commit-queue.sh ${{ steps.get_mergeable_prs.outputs.numbers }}
176172
env:
177173
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

‎doc/contributing/commit-queue.md‎

Lines changed: 8 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,24 @@ blocked on a deferrable condition, currently wait time, the queue leaves the
1111
label in place and retries later. Other failures continue to the existing
1212
landing and failure-reporting path.
1313

14-
This document gives an overview of how the Commit Queue works, as well as
15-
implementation details, reasoning for design choices, and current limitations.
16-
17-
## Overview
18-
19-
From a high-level, the Commit Queue works as follows:
20-
21-
1. Collaborators will add `commit-queue` label to pull requests they want the
22-
queue to land. The label can be added before the pull request has completed
23-
its wait time. Required approvals must already be in place, and any required
24-
CI must have completed successfully. The commit queue does not request CI on
25-
its own.
26-
2. On each scheduled run, the queue builds a candidate list from open pull
27-
requests with the `commit-queue` label and without the `blocked` label. A
28-
candidate must also either have been created at least two days earlier or
29-
have the `fast-track` label. Other labeled pull requests retain the label
30-
until they become old enough or are fast-tracked. The workflow uses a
31-
five-minute cron, but GitHub Actions scheduled workflows are not guaranteed
32-
to run exactly every five minutes. For each candidate, the queue will:
33-
1. In the landing job, install and configure `@node-core/utils`, then run a
34-
metadata-only readiness check without checking out the repository
35-
2. If the metadata check exits with a deferrable readiness code, meaning
36-
the PR is only blocked on wait time, keep the `commit-queue` label and
37-
skip this PR until a later queue run
38-
3. Run `git node land` for ready PRs and PRs with hard or mixed readiness
39-
failures, keeping the `commit-queue` label in place during the attempt
40-
4. If it fails:
41-
1. Replace the `commit-queue` label with the `commit-queue-failed` label
42-
2. Leave a comment on the PR with the output from `git node land`
43-
3. Abort the `git node land` session. If the abort succeeds, continue to
44-
the next PR; otherwise, stop the queue in an unknown state
45-
5. If it succeeds:
46-
1. Push or merge the changes into nodejs/node
47-
2. Leave a comment on the PR with `Landed in ...`
48-
3. Close the PR
49-
4. Remove the `commit-queue` label
50-
5. Go to next PR in the queue
51-
5214
To make the Commit Queue squash all the commits of a pull request into the
5315
first one, add the `commit-queue-squash` label.
5416
To make the Commit Queue land a pull request containing several commits, add the
5517
`commit-queue-rebase` label. When using this option, make sure
5618
that all commits are self-contained, meaning every commit should pass all tests.
5719

20+
The implementation is in `commit-queue.yml` and `commit-queue.sh`.
21+
5822
## Current limitations
5923

60-
The Commit Queue feature is still in early stages, and as such it might not
61-
work for more complex pull requests. These are the currently known limitations
62-
of the commit queue:
24+
These are the currently known limitations of the commit queue:
6325

6426
1. All commits in a pull request must either be following commit message
6527
guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6628
commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash)
67-
option
68-
2. A CI must have run and succeeded since the last change on the PR
69-
3. A collaborator must have approved the PR since the last change
70-
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored)
29+
option.
30+
2. A CI must have run and succeeded since the last change on the PR.
31+
3. A collaborator must have approved the PR since the last change.
32+
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored).
7133
5. The PR must target the `main` branch (PRs opened against other branches, such
72-
as backport PRs, are ignored)
73-
74-
## Implementation
75-
76-
The [action](../../.github/workflows/commit-queue.yml) runs on scheduled events.
77-
It uses a five-minute cron because that is the smallest interval accepted by
78-
GitHub Actions. Scheduled workflows are not guaranteed to run exactly at that
79-
cadence and might take longer between runs.
80-
81-
The workflow also uses a concurrency group so only one commit queue run can be
82-
active at a time. If a scheduled run starts while a previous run is still
83-
running, GitHub Actions keeps at most one pending run for the same concurrency
84-
group. A newer pending run replaces an older pending run.
85-
86-
Using the scheduler is preferable over using pull\_request\_target for two
87-
reasons:
88-
89-
1. if two Commit Queue Actions execution overlap, there's a high-risk that
90-
the last one to finish will fail because the local branch will be out of
91-
sync with the remote after the first Action pushes. `issue_comment` event
92-
has the same limitation.
93-
2.`pull_request_target` will only run if the Action exists on the base commit
94-
of a pull request, and it will run the Action version present on that
95-
commit, meaning we wouldn't be able to use it for already opened PRs
96-
without rebasing them first.
97-
98-
The workflow starts with a small candidate job that uses GitHub CLI to fetch
99-
open pull requests with the `commit-queue` label and without the `blocked`
100-
label. It fetches two buckets: pull requests created at least two days earlier
101-
and pull requests with the `fast-track` label. The job de-duplicates the
102-
buckets before passing the candidates to the landing job. Pull requests in
103-
neither bucket remain labeled but are not processed during that run.
104-
105-
If there are candidate PRs, the landing job installs and configures
106-
`@node-core/utils` once with a personal token and a Jenkins token from
107-
[@nodejs-github-bot](https://github.com/nodejs/github-bot). It then downloads
108-
the workflow commit's README without checking out the repository and runs
109-
`git node metadata --readme --json` for each candidate. This uses the same
110-
`@node-core/utils` PR readiness checks as `git node land`, but does not clone,
111-
fetch, or merge the PR. The filter consumes the structured metadata result
112-
and its exit code instead of matching human-readable output:
113-
114-
* exit code `0`: the PR is ready and is passed to
115-
[`commit-queue.sh`](../../tools/actions/commit-queue.sh)
116-
* exit codes `20`-`29`: the PR is not ready for a deferrable metadata reason,
117-
currently wait time, so it keeps the `commit-queue` label and is retried
118-
later
119-
* exit codes `40`-`49`: the PR has a hard or mixed metadata readiness failure
120-
and is passed to [`commit-queue.sh`](../../tools/actions/commit-queue.sh)
121-
122-
The `20`-`29` exit code range is reserved by `@node-core/utils` for deferrable
123-
metadata readiness states, and `40`-`49` is reserved for hard metadata failure
124-
states. Unknown filter failures fail the workflow before starting the landing
125-
script and leave PR labels unchanged so the queue can retry on a later
126-
scheduled run. PRs passed through with exit code `40`-`49` continue through
127-
`commit-queue.sh`. The workflow checks out the repository only when at least
128-
one PR remains after filtering. The script does not separately skip PRs with a
129-
`request-ci` label or pending GitHub checks. Instead, `git node land` performs
130-
the landing checks and the script reports any failure through the normal queue
131-
failure path.
132-
133-
> The personal token needs permission for public repositories and to read
134-
> profiles. It is used by `@node-core/utils` and by the landing job for
135-
> checkout, label and comment updates, merging, and pushing. Jenkins token is
136-
> required to check CI status.
137-
138-
`commit-queue.sh` receives the following positional arguments:
139-
140-
1. The repository owner
141-
2. The repository name
142-
3. Every positional argument starting at this one will be a pull request ID of
143-
a pull request with commit-queue set.
144-
145-
The script iterates over the pull requests. For each PR, it uses GitHub CLI to
146-
fetch the labels and select the multiple-commit policy, then runs
147-
`git node land`, forwarding stdout and stderr to a file. It does not perform a
148-
separate CI preflight; `git node land` performs the current readiness and CI
149-
validation.
150-
151-
The script keeps the `commit-queue` label in place while `git node land` is
152-
running. PRs that are only blocked on wait time should have already been
153-
filtered by the metadata check. A hard or mixed readiness failure is passed
154-
through so `git node land` can produce the failure output. If the landing
155-
attempt fails for that or any other reason, the job replaces the
156-
`commit-queue` label with `commit-queue-failed`, leaves a comment with the
157-
output, and then aborts the landing session. If the abort fails, the queue
158-
stops instead of continuing in an unknown state.
159-
160-
Fast-tracked PRs use the metadata check before checkout and the landing script.
161-
If the fast-track request has not yet received enough collaborator thumbs-up,
162-
the queue keeps the `commit-queue` label and retries until either the
163-
fast-track request is approved or the PR becomes landable through the regular
164-
wait-time rules. The commit queue does not create the fast-track request
165-
comment; that is handled when the `fast-track` label is added. If that comment
166-
is missing, the queue reports the failure instead of keeping the PR queued.
167-
168-
If no errors happen during `git node land`, the script either pushes the direct
169-
rebase landing to `main` or uses GitHub's squash merge API for single-commit and
170-
fixup landings. It then leaves a `Landed in ...` comment in the PR. GitHub
171-
closes PRs merged through the merge API automatically; for direct pushes, the
172-
script closes the PR. The script then removes the `commit-queue` label.
173-
Iteration continues until all PRs have done the steps above.
174-
175-
## Reverting broken commits
176-
177-
Reverting broken commits is done manually by collaborators, just like when
178-
commits are landed manually via `git node land`. An easy way to revert is a
179-
good feature for the project, but is not explicitly required for the Commit
180-
Queue to work because the Action lands PRs just like collaborators do today. If
181-
once we start using the Commit Queue we notice that the number of required
182-
reverts increases drastically, we can pause the queue until a Revert Queue is
183-
implemented, but until then we can enable the Commit Queue and then work on a
184-
Revert Queue as a follow-up.
34+
as backport PRs, are ignored).

‎tools/actions/commit-queue.sh‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
set -xe
44

5-
OWNER=$1
6-
REPOSITORY=$2
7-
shift 2
8-
95
UPSTREAM=origin
106
DEFAULT_BRANCH=main
117

128
COMMIT_QUEUE_LABEL="commit-queue"
139
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1410

11+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
12+
1513
commit_queue_failed() {
1614
pr=$1
1715

18-
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
16+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1917

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2218
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
2319
echo"$body"
2420

25-
gh pr comment "$pr" --body "$body"
21+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2622

2723
rm output
2824
}
2925

30-
# TODO(mmarchini): should this be set with whoever added the label for each PR?
31-
git config --local user.email "github-bot@iojs.org"
32-
git config --local user.name "Node.js GitHub Bot"
33-
3426
SHOULD_ABORT=
3527

3628
forprin"$@";do
37-
gh pr view "$pr" --json labels --jq ".labels"> labels.json
29+
gh -R "$GITHUB_REPOSITORY"pr view "$pr" --json labels --jq ".labels"> labels.json
3830

3931
if jq -e 'map(.name) | index("commit-queue-squash")'< labels.json;then
4032
MULTIPLE_COMMIT_POLICY="--fixupAll"
@@ -87,7 +79,7 @@ for pr in "$@"; do
8779
--arg body "${commit_body}" \
8880
--arg head "${commit_head}" \
8981
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}'|\
90-
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
82+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
9183
--jq 'if .merged then .sha else halt_error end'
9284
)";then
9385
commit_queue_failed "$pr"
@@ -97,12 +89,12 @@ for pr in "$@"; do
9789

9890
rm output
9991

100-
gh pr comment "$pr" --body "Landed in $commits"
92+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "Landed in $commits"
10193

102-
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
94+
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh -R "$GITHUB_REPOSITORY"pr close "$pr"
10395

10496
# Delete the commit queue label (but ignore errors, it's no big deal if a closed PR still has the label)
105-
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
97+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
10698
done
10799

108100
rm -f labels.json

‎tools/actions/start-ci.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ set -xe
44

55
REQUEST_CI_LABEL="request-ci"
66
REQUEST_CI_FAILED_LABEL="request-ci-failed"
7+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
78

89
forprin"$@";do
9-
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
1011

1112
ci_started=yes
1213
rm -f output;
@@ -15,14 +16,12 @@ for pr in "$@"; do
1516

1617
if [ "$ci_started"="no" ];then
1718
# Do we need to reset?
18-
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
1920

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2221
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
2322
echo"$body"
2423

25-
gh pr comment "$pr" --body "$body"
24+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2625

2726
rm output
2827
fi

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 41edd2f

Browse files
committed
tools: make env variables consistent in cron jobs
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65168 Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent ec956f2 commit 41edd2f

5 files changed

Lines changed: 36 additions & 195 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This action uses the following secrets:
2+
# JENKINS_USER: GitHub user whose Jenkins token is defined below
3+
# JENKINS_TOKEN: Jenkins token, to be used to start CI
14
name: Auto Start CI
25

36
on:
@@ -36,11 +39,13 @@ jobs:
3639
-t '{{ range . }}{{ .number }} {{ end }}' \
3740
--limit 5)" >> "$GITHUB_OUTPUT"
3841
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ github.token }}
4043
start-ci:
4144
permissions:
45+
checks: read
4246
contents: read
4347
pull-requests: write
48+
statuses: read
4449
needs: get-prs-for-ci
4550
if: needs.get-prs-for-ci.outputs.numbers != ''
4651
runs-on: ubuntu-slim
@@ -59,16 +64,15 @@ jobs:
5964
ncu-config set token "$GH_TOKEN"
6065
ncu-config set jenkins_token "$JENKINS_TOKEN"
6166
ncu-config set owner "$GITHUB_REPOSITORY_OWNER"
62-
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
67+
ncu-config set repo "${GITHUB_REPOSITORY#*/}"
6368
env:
6469
USERNAME: ${{ secrets.JENKINS_USER }}
65-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
70+
GH_TOKEN: ${{ github.token }}
6671
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6772

6873
- name: Start the CI
6974
run: |
7075
curl -fsSL "https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/start-ci.sh" \
7176
| sh -s -- ${{ needs.get-prs-for-ci.outputs.numbers }}
7277
env:
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GH_REPO: ${{ github.repository }}
78+
GH_TOKEN: ${{ github.token }}

‎.github/workflows/commit-queue.yml‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
jq -r -s 'reduce .[] as $pr ([]; if index($pr) then . else . + [$pr] end) | join(" ")')
5353
echo "candidates=$candidates" >> "$GITHUB_OUTPUT"
5454
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
GH_TOKEN: ${{ github.token }}
5656
commitQueue:
5757
needs: get_candidate_prs
5858
if: needs.get_candidate_prs.outputs.candidates != ''
@@ -63,18 +63,14 @@ jobs:
6363
statuses: read
6464
runs-on: ubuntu-slim
6565
steps:
66-
# Install dependencies
6766
- name: Install Node.js
6867
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
6968
with:
7069
node-version: ${{ env.NODE_VERSION }}
70+
7171
- name: Install @node-core/utils
7272
run: npm install -g @node-core/utils
7373

74-
- name: Set variables
75-
run: |
76-
echo "REPOSITORY=$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)" >> "$GITHUB_ENV"
77-
7874
- name: Configure @node-core/utils
7975
run: |
8076
# Keep the config outside the workspace so checkout does not remove it.
@@ -83,7 +79,7 @@ jobs:
8379
ncu-config --global set username "$USERNAME"
8480
ncu-config --global set token "$GH_TOKEN"
8581
ncu-config --global set jenkins_token "$JENKINS_TOKEN"
86-
ncu-config --global set repo "${REPOSITORY}"
82+
ncu-config --global set repo "${GITHUB_REPOSITORY#*/}"
8783
ncu-config --global set owner "${GITHUB_REPOSITORY_OWNER}"
8884
env:
8985
USERNAME: ${{ secrets.JENKINS_USER }}
@@ -102,8 +98,6 @@ jobs:
10298
metadata="${RUNNER_TEMP}/metadata-${pr}.json"
10399
output="${RUNNER_TEMP}/metadata-${pr}.txt"
104100
if git node metadata "$pr" \
105-
--owner "$GITHUB_REPOSITORY_OWNER" \
106-
--repo "$REPOSITORY" \
107101
--readme "$readme" \
108102
--json > "$metadata" 2> "$output"; then
109103
metadata_status=0
@@ -171,7 +165,9 @@ jobs:
171165
- name: Start the Commit Queue
172166
if: steps.get_mergeable_prs.outputs.numbers != ''
173167
run: |
168+
git config --local user.email "github-bot@iojs.org"
169+
git config --local user.name "Node.js GitHub Bot"
174170
ncu-config set token "$GH_TOKEN"
175-
./tools/actions/commit-queue.sh "${GITHUB_REPOSITORY_OWNER}" "${REPOSITORY}" ${{ steps.get_mergeable_prs.outputs.numbers }}
171+
./tools/actions/commit-queue.sh ${{ steps.get_mergeable_prs.outputs.numbers }}
176172
env:
177173
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

‎doc/contributing/commit-queue.md‎

Lines changed: 8 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,24 @@ blocked on a deferrable condition, currently wait time, the queue leaves the
1111
label in place and retries later. Other failures continue to the existing
1212
landing and failure-reporting path.
1313

14-
This document gives an overview of how the Commit Queue works, as well as
15-
implementation details, reasoning for design choices, and current limitations.
16-
17-
## Overview
18-
19-
From a high-level, the Commit Queue works as follows:
20-
21-
1. Collaborators will add `commit-queue` label to pull requests they want the
22-
queue to land. The label can be added before the pull request has completed
23-
its wait time. Required approvals must already be in place, and any required
24-
CI must have completed successfully. The commit queue does not request CI on
25-
its own.
26-
2. On each scheduled run, the queue builds a candidate list from open pull
27-
requests with the `commit-queue` label and without the `blocked` label. A
28-
candidate must also either have been created at least two days earlier or
29-
have the `fast-track` label. Other labeled pull requests retain the label
30-
until they become old enough or are fast-tracked. The workflow uses a
31-
five-minute cron, but GitHub Actions scheduled workflows are not guaranteed
32-
to run exactly every five minutes. For each candidate, the queue will:
33-
1. In the landing job, install and configure `@node-core/utils`, then run a
34-
metadata-only readiness check without checking out the repository
35-
2. If the metadata check exits with a deferrable readiness code, meaning
36-
the PR is only blocked on wait time, keep the `commit-queue` label and
37-
skip this PR until a later queue run
38-
3. Run `git node land` for ready PRs and PRs with hard or mixed readiness
39-
failures, keeping the `commit-queue` label in place during the attempt
40-
4. If it fails:
41-
1. Replace the `commit-queue` label with the `commit-queue-failed` label
42-
2. Leave a comment on the PR with the output from `git node land`
43-
3. Abort the `git node land` session. If the abort succeeds, continue to
44-
the next PR; otherwise, stop the queue in an unknown state
45-
5. If it succeeds:
46-
1. Push or merge the changes into nodejs/node
47-
2. Leave a comment on the PR with `Landed in ...`
48-
3. Close the PR
49-
4. Remove the `commit-queue` label
50-
5. Go to next PR in the queue
51-
5214
To make the Commit Queue squash all the commits of a pull request into the
5315
first one, add the `commit-queue-squash` label.
5416
To make the Commit Queue land a pull request containing several commits, add the
5517
`commit-queue-rebase` label. When using this option, make sure
5618
that all commits are self-contained, meaning every commit should pass all tests.
5719

20+
The implementation is in `commit-queue.yml` and `commit-queue.sh`.
21+
5822
## Current limitations
5923

60-
The Commit Queue feature is still in early stages, and as such it might not
61-
work for more complex pull requests. These are the currently known limitations
62-
of the commit queue:
24+
These are the currently known limitations of the commit queue:
6325

6426
1. All commits in a pull request must either be following commit message
6527
guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt)
6628
commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash)
67-
option
68-
2. A CI must have run and succeeded since the last change on the PR
69-
3. A collaborator must have approved the PR since the last change
70-
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored)
29+
option.
30+
2. A CI must have run and succeeded since the last change on the PR.
31+
3. A collaborator must have approved the PR since the last change.
32+
4. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored).
7133
5. The PR must target the `main` branch (PRs opened against other branches, such
72-
as backport PRs, are ignored)
73-
74-
## Implementation
75-
76-
The [action](../../.github/workflows/commit-queue.yml) runs on scheduled events.
77-
It uses a five-minute cron because that is the smallest interval accepted by
78-
GitHub Actions. Scheduled workflows are not guaranteed to run exactly at that
79-
cadence and might take longer between runs.
80-
81-
The workflow also uses a concurrency group so only one commit queue run can be
82-
active at a time. If a scheduled run starts while a previous run is still
83-
running, GitHub Actions keeps at most one pending run for the same concurrency
84-
group. A newer pending run replaces an older pending run.
85-
86-
Using the scheduler is preferable over using pull\_request\_target for two
87-
reasons:
88-
89-
1. if two Commit Queue Actions execution overlap, there's a high-risk that
90-
the last one to finish will fail because the local branch will be out of
91-
sync with the remote after the first Action pushes. `issue_comment` event
92-
has the same limitation.
93-
2.`pull_request_target` will only run if the Action exists on the base commit
94-
of a pull request, and it will run the Action version present on that
95-
commit, meaning we wouldn't be able to use it for already opened PRs
96-
without rebasing them first.
97-
98-
The workflow starts with a small candidate job that uses GitHub CLI to fetch
99-
open pull requests with the `commit-queue` label and without the `blocked`
100-
label. It fetches two buckets: pull requests created at least two days earlier
101-
and pull requests with the `fast-track` label. The job de-duplicates the
102-
buckets before passing the candidates to the landing job. Pull requests in
103-
neither bucket remain labeled but are not processed during that run.
104-
105-
If there are candidate PRs, the landing job installs and configures
106-
`@node-core/utils` once with a personal token and a Jenkins token from
107-
[@nodejs-github-bot](https://github.com/nodejs/github-bot). It then downloads
108-
the workflow commit's README without checking out the repository and runs
109-
`git node metadata --readme --json` for each candidate. This uses the same
110-
`@node-core/utils` PR readiness checks as `git node land`, but does not clone,
111-
fetch, or merge the PR. The filter consumes the structured metadata result
112-
and its exit code instead of matching human-readable output:
113-
114-
* exit code `0`: the PR is ready and is passed to
115-
[`commit-queue.sh`](../../tools/actions/commit-queue.sh)
116-
* exit codes `20`-`29`: the PR is not ready for a deferrable metadata reason,
117-
currently wait time, so it keeps the `commit-queue` label and is retried
118-
later
119-
* exit codes `40`-`49`: the PR has a hard or mixed metadata readiness failure
120-
and is passed to [`commit-queue.sh`](../../tools/actions/commit-queue.sh)
121-
122-
The `20`-`29` exit code range is reserved by `@node-core/utils` for deferrable
123-
metadata readiness states, and `40`-`49` is reserved for hard metadata failure
124-
states. Unknown filter failures fail the workflow before starting the landing
125-
script and leave PR labels unchanged so the queue can retry on a later
126-
scheduled run. PRs passed through with exit code `40`-`49` continue through
127-
`commit-queue.sh`. The workflow checks out the repository only when at least
128-
one PR remains after filtering. The script does not separately skip PRs with a
129-
`request-ci` label or pending GitHub checks. Instead, `git node land` performs
130-
the landing checks and the script reports any failure through the normal queue
131-
failure path.
132-
133-
> The personal token needs permission for public repositories and to read
134-
> profiles. It is used by `@node-core/utils` and by the landing job for
135-
> checkout, label and comment updates, merging, and pushing. Jenkins token is
136-
> required to check CI status.
137-
138-
`commit-queue.sh` receives the following positional arguments:
139-
140-
1. The repository owner
141-
2. The repository name
142-
3. Every positional argument starting at this one will be a pull request ID of
143-
a pull request with commit-queue set.
144-
145-
The script iterates over the pull requests. For each PR, it uses GitHub CLI to
146-
fetch the labels and select the multiple-commit policy, then runs
147-
`git node land`, forwarding stdout and stderr to a file. It does not perform a
148-
separate CI preflight; `git node land` performs the current readiness and CI
149-
validation.
150-
151-
The script keeps the `commit-queue` label in place while `git node land` is
152-
running. PRs that are only blocked on wait time should have already been
153-
filtered by the metadata check. A hard or mixed readiness failure is passed
154-
through so `git node land` can produce the failure output. If the landing
155-
attempt fails for that or any other reason, the job replaces the
156-
`commit-queue` label with `commit-queue-failed`, leaves a comment with the
157-
output, and then aborts the landing session. If the abort fails, the queue
158-
stops instead of continuing in an unknown state.
159-
160-
Fast-tracked PRs use the metadata check before checkout and the landing script.
161-
If the fast-track request has not yet received enough collaborator thumbs-up,
162-
the queue keeps the `commit-queue` label and retries until either the
163-
fast-track request is approved or the PR becomes landable through the regular
164-
wait-time rules. The commit queue does not create the fast-track request
165-
comment; that is handled when the `fast-track` label is added. If that comment
166-
is missing, the queue reports the failure instead of keeping the PR queued.
167-
168-
If no errors happen during `git node land`, the script either pushes the direct
169-
rebase landing to `main` or uses GitHub's squash merge API for single-commit and
170-
fixup landings. It then leaves a `Landed in ...` comment in the PR. GitHub
171-
closes PRs merged through the merge API automatically; for direct pushes, the
172-
script closes the PR. The script then removes the `commit-queue` label.
173-
Iteration continues until all PRs have done the steps above.
174-
175-
## Reverting broken commits
176-
177-
Reverting broken commits is done manually by collaborators, just like when
178-
commits are landed manually via `git node land`. An easy way to revert is a
179-
good feature for the project, but is not explicitly required for the Commit
180-
Queue to work because the Action lands PRs just like collaborators do today. If
181-
once we start using the Commit Queue we notice that the number of required
182-
reverts increases drastically, we can pause the queue until a Revert Queue is
183-
implemented, but until then we can enable the Commit Queue and then work on a
184-
Revert Queue as a follow-up.
34+
as backport PRs, are ignored).

‎tools/actions/commit-queue.sh‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,31 @@
22

33
set -xe
44

5-
OWNER=$1
6-
REPOSITORY=$2
7-
shift 2
8-
95
UPSTREAM=origin
106
DEFAULT_BRANCH=main
117

128
COMMIT_QUEUE_LABEL="commit-queue"
139
COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1410

11+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
12+
1513
commit_queue_failed() {
1614
pr=$1
1715

18-
gh pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
16+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1917

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${OWNER}/${REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2218
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
2319
echo"$body"
2420

25-
gh pr comment "$pr" --body "$body"
21+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2622

2723
rm output
2824
}
2925

30-
# TODO(mmarchini): should this be set with whoever added the label for each PR?
31-
git config --local user.email "github-bot@iojs.org"
32-
git config --local user.name "Node.js GitHub Bot"
33-
3426
SHOULD_ABORT=
3527

3628
forprin"$@";do
37-
gh pr view "$pr" --json labels --jq ".labels"> labels.json
29+
gh -R "$GITHUB_REPOSITORY"pr view "$pr" --json labels --jq ".labels"> labels.json
3830

3931
if jq -e 'map(.name) | index("commit-queue-squash")'< labels.json;then
4032
MULTIPLE_COMMIT_POLICY="--fixupAll"
@@ -87,7 +79,7 @@ for pr in "$@"; do
8779
--arg body "${commit_body}" \
8880
--arg head "${commit_head}" \
8981
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}'|\
90-
gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input -\
82+
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
9183
--jq 'if .merged then .sha else halt_error end'
9284
)";then
9385
commit_queue_failed "$pr"
@@ -97,12 +89,12 @@ for pr in "$@"; do
9789

9890
rm output
9991

100-
gh pr comment "$pr" --body "Landed in $commits"
92+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "Landed in $commits"
10193

102-
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh pr close "$pr"
94+
[ -z"$MULTIPLE_COMMIT_POLICY" ] && gh -R "$GITHUB_REPOSITORY"pr close "$pr"
10395

10496
# Delete the commit queue label (but ignore errors, it's no big deal if a closed PR still has the label)
105-
gh pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
97+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$COMMIT_QUEUE_LABEL"||true
10698
done
10799

108100
rm -f labels.json

‎tools/actions/start-ci.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ set -xe
44

55
REQUEST_CI_LABEL="request-ci"
66
REQUEST_CI_FAILED_LABEL="request-ci-failed"
7+
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
78

89
forprin"$@";do
9-
gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
1011

1112
ci_started=yes
1213
rm -f output;
@@ -15,14 +16,12 @@ for pr in "$@"; do
1516

1617
if [ "$ci_started"="no" ];then
1718
# Do we need to reset?
18-
gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19+
gh -R "$GITHUB_REPOSITORY"pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
1920

20-
# shellcheck disable=SC2154
21-
cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
2221
body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
2322
echo"$body"
2423

25-
gh pr comment "$pr" --body "$body"
24+
gh -R "$GITHUB_REPOSITORY"pr comment "$pr" --body "$body"
2625

2726
rm output
2827
fi

0 commit comments

Comments
 (0)