1# Commit queue 2 3> Stability: 1 - Experimental 4 5*tl;dr: You can land pull requests by adding the `commit-queue` label to it.* 6 7Commit Queue is an experimental feature for the project which simplifies the 8landing process by automating it via GitHub Actions. With it, collaborators can 9land pull requests by adding the `commit-queue` label to a PR. All 10checks will run via node-core-utils, and if the pull request is ready to land, 11the Action will rebase it and push to master. 12 13This document gives an overview of how the Commit Queue works, as well as 14implementation details, reasoning for design choices, and current limitations. 15 16## Overview 17 18From a high-level, the Commit Queue works as follow: 19 201. Collaborators will add `commit-queue` label to pull requests ready to land 212. Every five minutes the queue will do the following for each pull request 22 with the label: 23 1. Check if the PR also has a `request-ci` label (if it has, skip this PR 24 since it's pending a CI run) 25 2. Check if the last Jenkins CI is finished running (if it is not, skip this 26 PR) 27 3. Remove the `commit-queue` label 28 4. Run `git node land <pr>` 29 5. If it fails: 30 1. Abort `git node land` session 31 2. Add `commit-queue-failed` label to the PR 32 3. Leave a comment on the PR with the output from `git node land` 33 4. Skip next steps, go to next PR in the queue 34 6. If it succeeds: 35 1. Push the changes to nodejs/node 36 2. Leave a comment on the PR with `Landed in ...` 37 3. Close the PR 38 4. Go to next PR in the queue 39 40## Current limitations 41 42The Commit Queue feature is still in early stages, and as such it might not 43work for more complex pull requests. These are the currently known limitations 44of the commit queue: 45 461. All commits in a pull request must either be following commit message 47 guidelines or be a valid [`fixup!`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupltcommitgt) 48 commit that will be correctly handled by the [`--autosquash`](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash) 49 option 502. A CI must've ran and succeeded since the last change on the PR 513. A collaborator must have approved the PR since the last change 524. Only Jenkins CI and GitHub Actions are checked (V8 CI and CITGM are ignored) 53 54## Implementation 55 56The [action](../../.github/workflows/commit-queue.yml) will run on scheduler 57events every five minutes. Five minutes is the smallest number accepted by 58the scheduler. The scheduler is not guaranteed to run every five minutes, it 59might take longer between runs. 60 61Using the scheduler is preferable over using pull_request_target for two 62reasons: 63 641. if two Commit Queue Actions execution overlap, there's a high-risk that 65 the last one to finish will fail because the local branch will be out of 66 sync with the remote after the first Action pushes. `issue_comment` event 67 has the same limitation. 682. `pull_request_target` will only run if the Action exists on the base commit 69 of a pull request, and it will run the Action version present on that 70 commit, meaning we wouldn't be able to use it for already opened PRs 71 without rebasing them first. 72 73`node-core-utils` is configured with a personal token and 74a Jenkins token from 75[@nodejs-github-bot](https://github.com/nodejs/github-bot). 76`octokit/graphql-action` is used to fetch all pull requests with the 77`commit-queue` label. The output is a JSON payload, so `jq` is used to turn 78that into a list of PR ids we can pass as arguments to 79[`commit-queue.sh`](../../tools/actions/commit-queue.sh). 80 81> The personal token only needs permission for public repositories and to read 82> profiles, we can use the GITHUB_TOKEN for write operations. Jenkins token is 83> required to check CI status. 84 85`commit-queue.sh` receives the following positional arguments: 86 871. The repository owner 882. The repository name 893. The Action GITHUB_TOKEN 904. Every positional argument starting at this one will be a pull request ID of 91 a pull request with commit-queue set. 92 93The script will iterate over the pull requests. `ncu-ci` is used to check if 94the last CI is still pending, and calls to the GitHub API are used to check if 95the PR is waiting for CI to start (`request-ci` label). The PR is skipped if CI 96is pending. No other CI validation is done here since `git node land` will fail 97if the last CI failed. 98 99The script removes the `commit-queue` label. It then runs `git node land`, 100forwarding stdout and stderr to a file. If any errors happen, 101`git node land --abort` is run, and then a `commit-queue-failed` label is added 102to the PR, as well as a comment with the output of `git node land`. 103 104If no errors happen during `git node land`, the script will use the 105`GITHUB_TOKEN` to push the changes to `master`, and then will leave a 106`Landed in ...` comment in the PR, and then will close it. Iteration continues 107until all PRs have done the steps above. 108 109## Reverting broken commits 110 111Reverting broken commits is done manually by collaborators, just like when 112commits are landed manually via `git node land`. An easy way to revert is a 113good feature for the project, but is not explicitly required for the Commit 114Queue to work because the Action lands PRs just like collaborators do today. If 115once we start using the Commit Queue we notice that the number of required 116reverts increases drastically, we can pause the queue until a Revert Queue is 117implemented, but until then we can enable the Commit Queue and then work on a 118Revert Queue as a follow-up. 119