From d855b03027555925560ecda7a3d7cd5d48cd3ae3 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 23 Jun 2021 16:48:34 +0200 Subject: [PATCH 01/13] tools: avoid fetch extra commits when validating commit messages PR-URL: https://github.com/nodejs/node/pull/39128 Reviewed-By: Mary Marchini --- .github/workflows/commit-lint.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml index 0f6fd639523..42e9dc05283 100644 --- a/.github/workflows/commit-lint.yml +++ b/.github/workflows/commit-lint.yml @@ -9,10 +9,12 @@ jobs: lint-commit-message: runs-on: ubuntu-latest steps: + - name: Compute number of commits in the PR + id: nb-of-commits + run: echo "::set-output name=nb::$((${{ github.event.pull_request.commits }} + 1))" - uses: actions/checkout@v2 with: - # Last 100 commits should be enough for a PR - fetch-depth: 100 + fetch-depth: ${{ steps.nb-of-commits.outputs.nb }} - name: Install Node.js uses: actions/setup-node@v2 with: From cad7fb99ccede90bbe9098ce94d85a448bb234f2 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 23 Oct 2021 18:17:23 +0200 Subject: [PATCH 02/13] tools: abort CQ session when landing several commits Most PRs are meant to be squashed in one commit when landing. If the collaborator hasn't been using `fixup!` commits, the CQ lands the PR as several commits. This change makes the CQ abort by default when attempting to land several commits, unless there's another label added to the PR to force squashing or landing as several commits. Fixes: https://github.com/nodejs/node/issues/40436 Refs: https://github.com/nodejs/node-core-utils/pull/572 PR-URL: https://github.com/nodejs/node/pull/40577 --- doc/guides/commit-queue.md | 8 +++++++- tools/actions/commit-queue.sh | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/guides/commit-queue.md b/doc/guides/commit-queue.md index dec153196ea..d7ecef57c50 100644 --- a/doc/guides/commit-queue.md +++ b/doc/guides/commit-queue.md @@ -25,7 +25,7 @@ From a high-level, the Commit Queue works as follow: 2. Check if the last Jenkins CI is finished running (if it is not, skip this PR) 3. Remove the `commit-queue` label - 4. Run `git node land ` + 4. Run `git node land --oneCommitMax` 5. If it fails: 1. Abort `git node land` session 2. Add `commit-queue-failed` label to the PR @@ -37,6 +37,12 @@ From a high-level, the Commit Queue works as follow: 3. Close the PR 4. Go to next PR in the queue +To make the Commit Queue squash all the commits on a pull request in the first +one, add the `commit-queue-squash` label. +To make the Commit Queue land a pull request containing several commits, add the +`commit-queue-rebase` label. When using this option, make sure +that all commits are self-contained, meaning every commit should pass all tests. + ## Current limitations The Commit Queue feature is still in early stages, and as such it might not diff --git a/tools/actions/commit-queue.sh b/tools/actions/commit-queue.sh index 22f306cc36b..7272c71b4db 100755 --- a/tools/actions/commit-queue.sh +++ b/tools/actions/commit-queue.sh @@ -70,7 +70,15 @@ for pr in "$@"; do # Delete the commit queue label gitHubCurl "$(labelsUrl "$pr")"/"$COMMIT_QUEUE_LABEL" DELETE - git node land --autorebase --yes "$pr" >output 2>&1 || echo "Failed to land #${pr}" + if gitHubCurl "$(labelsUrl "$pr")" GET | jq -e 'map(.name) | index("commit-queue-squash")'; then + MULTIPLE_COMMIT_POLICY="--fixupAll" + elif gitHubCurl "$(labelsUrl "$pr")" GET | jq -e 'map(.name) | index("commit-queue-rebase")'; then + MULTIPLE_COMMIT_POLICY="" + else + MULTIPLE_COMMIT_POLICY="--oneCommitMax" + fi + + git node land --autorebase --yes $MULTIPLE_COMMIT_POLICY "$pr" >output 2>&1 || echo "Failed to land #${pr}" # cat here otherwise we'll be supressing the output of git node land cat output From f3821a47b4ecca648bf1f47ab3ed4555a1a3a3a1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 30 Oct 2021 17:14:58 +0200 Subject: [PATCH 03/13] tools: use GitHub Squash and Merge feature when using CQ --- tools/actions/commit-queue.sh | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tools/actions/commit-queue.sh b/tools/actions/commit-queue.sh index 7272c71b4db..f6e266a1973 100755 --- a/tools/actions/commit-queue.sh +++ b/tools/actions/commit-queue.sh @@ -18,6 +18,10 @@ issueUrl() { echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}" } +mergeUrl() { + echo "$API_URL/repos/${OWNER}/${REPOSITORY}/pulls/${1}/merge" +} + labelsUrl() { echo "$(issueUrl "${1}")/labels" } @@ -92,12 +96,25 @@ for pr in "$@"; do git node land --abort --yes continue fi - - commits="$(git rev-parse $UPSTREAM/$DEFAULT_BRANCH)...$(git rev-parse HEAD)" - if ! git push $UPSTREAM $DEFAULT_BRANCH >> output 2>&1; then - commit_queue_failed "$pr" - continue + if [ -z "$MULTIPLE_COMMIT_POLICY" ]; then + commits="$(git rev-parse $UPSTREAM/$DEFAULT_BRANCH)...$(git rev-parse HEAD)" + + if ! git push $UPSTREAM $DEFAULT_BRANCH >> output 2>&1; then + commit_queue_failed "$pr" + continue + fi + else + # If there's only one commit, we can use the Squash and Merge feature from GitHub + gitHubCurl "$(mergeUrl "$pr")" PUT --data "$(\ + TITLE="$(git log -1 --pretty='format:%s')" \ + BODY="$(git log -1 --pretty='format:%b')" \ + node -p 'JSON.stringify({merge_method:"squash",commit_title:process.env.TITLE,commit_message: process.env.BODY})')" > response.json + cat response.json + if ! commits="$(node -e 'const r=require("./response.json");if(!r.merged)throw new Error("Merging failed");process.stdout.write(r.sha)')"; then + commit_queue_failed "$pr" + continue + fi fi rm output From 9a7b6fdcecca2b6918ac265fedd78e66f5bec4ff Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Oct 2021 09:38:08 +0100 Subject: [PATCH 04/13] drop:re-enable CQ worlflows --- .github/workflows/commit-lint.yml | 1 - .github/workflows/commit-queue.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml index 42e9dc05283..eaa83d4faff 100644 --- a/.github/workflows/commit-lint.yml +++ b/.github/workflows/commit-lint.yml @@ -22,4 +22,3 @@ jobs: - name: Validate commit messages run: | echo "::add-matcher::.github/workflows/commit-lint-problem-matcher.json" - git log --oneline ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | grep -v -e fixup -e squash | awk '{ print $1 }' | xargs npx -q core-validate-commit --no-validate-metadata --tap diff --git a/.github/workflows/commit-queue.yml b/.github/workflows/commit-queue.yml index b2d37f80906..32d3d02e60c 100644 --- a/.github/workflows/commit-queue.yml +++ b/.github/workflows/commit-queue.yml @@ -18,7 +18,6 @@ env: jobs: commitQueue: - if: github.repository == 'nodejs/node' runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 04a23e48ee6fae1f4989a998f33c7471d403d1ea Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Oct 2021 10:52:08 +0100 Subject: [PATCH 05/13] tools: don't use secret token --- .github/workflows/commit-queue.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/commit-queue.yml b/.github/workflows/commit-queue.yml index 32d3d02e60c..5e4103fe161 100644 --- a/.github/workflows/commit-queue.yml +++ b/.github/workflows/commit-queue.yml @@ -25,11 +25,6 @@ jobs: # Needs the whole git history for ncu to work # See https://github.com/nodejs/node-core-utils/pull/486 fetch-depth: 0 - # A personal token is required because pushing with GITHUB_TOKEN will - # prevent commits from running CI after they land. It needs - # to be set here because `checkout` configures GitHub authentication - # for push as well. - token: ${{ secrets.GH_USER_TOKEN }} # Install dependencies - name: Install Node.js @@ -71,7 +66,7 @@ jobs: ncu-config set branch ${DEFAULT_BRANCH} ncu-config set upstream origin ncu-config set username "${{ secrets.GH_USER_NAME }}" - ncu-config set token "${{ secrets.GH_USER_TOKEN }}" + ncu-config set token "${{ secrets.GITHUB_TOKEN }}" ncu-config set jenkins_token "${{ secrets.JENKINS_TOKEN }}" ncu-config set repo "${REPOSITORY}" ncu-config set owner "${OWNER}" From 7abb10aa01f7a8a46f4353e79dac4c015cb82e7d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 30 Oct 2021 17:24:24 +0200 Subject: [PATCH 06/13] doc: update README to test PR squashing --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72f85968963..bd0964f7de9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

-Node.js is an open-source, cross-platform, JavaScript runtime environment. It +Node.js is an amazing project. It executes JavaScript code outside of a browser. For more information on using Node.js, see the [Node.js Website][]. From afc35da8d7721ad0747febb07c40459aa0fd7ff4 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Oct 2021 10:59:49 +0100 Subject: [PATCH 07/13] tools: use ${{ github.actor }} for username --- .github/workflows/commit-queue.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/commit-queue.yml b/.github/workflows/commit-queue.yml index 5e4103fe161..bdfd0339ffe 100644 --- a/.github/workflows/commit-queue.yml +++ b/.github/workflows/commit-queue.yml @@ -65,7 +65,7 @@ jobs: run: | ncu-config set branch ${DEFAULT_BRANCH} ncu-config set upstream origin - ncu-config set username "${{ secrets.GH_USER_NAME }}" + ncu-config set username "${{ github.actor }}" ncu-config set token "${{ secrets.GITHUB_TOKEN }}" ncu-config set jenkins_token "${{ secrets.JENKINS_TOKEN }}" ncu-config set repo "${REPOSITORY}" From dd66ba5fd90aa96dab3d02edede4886d475d44ff Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Oct 2021 11:00:49 +0100 Subject: [PATCH 08/13] Revert "doc: update README to test PR squashing" This reverts commit 7abb10aa01f7a8a46f4353e79dac4c015cb82e7d. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd0964f7de9..72f85968963 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

-Node.js is an amazing project. It +Node.js is an open-source, cross-platform, JavaScript runtime environment. It executes JavaScript code outside of a browser. For more information on using Node.js, see the [Node.js Website][]. From f5b0a228f2265278d1a79bfe4c2affda1d6c2506 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 30 Oct 2021 17:24:24 +0200 Subject: [PATCH 09/13] doc: update README to test PR squashing --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72f85968963..bd0964f7de9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

-Node.js is an open-source, cross-platform, JavaScript runtime environment. It +Node.js is an amazing project. It executes JavaScript code outside of a browser. For more information on using Node.js, see the [Node.js Website][]. From 03a84b5ca9b8be34eeb13be17d922675de6abbaa Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Oct 2021 12:13:29 +0100 Subject: [PATCH 10/13] fixup! doc: update README to test PR squashing --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bd0964f7de9..66e791087be 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,8 @@

-Node.js is an amazing project. It -executes JavaScript code outside of a browser. For more information on using -Node.js, see the [Node.js Website][]. +Node.js is an amazing project. It executes JavaScript code outside of a browser. +For more information on using Node.js, see the [Node.js Website][]. The Node.js project uses an [open governance model](./GOVERNANCE.md). The [OpenJS Foundation][] provides support for the project. From ac4732311b17df7e1e751e6bb498c6f9611eace0 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Oct 2021 12:16:02 +0100 Subject: [PATCH 11/13] fixup! doc: update README to test PR squashing --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66e791087be..eb39974d5b4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Node.js is an amazing project. It executes JavaScript code outside of a browser. For more information on using Node.js, see the [Node.js Website][]. -The Node.js project uses an [open governance model](./GOVERNANCE.md). The +The Node.js amazing project uses an [open governance model](./GOVERNANCE.md). The [OpenJS Foundation][] provides support for the project. **This project is bound by a [Code of Conduct][].** From 9aa5d82c4aaaba774336855f0e9c111d4878867e Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Oct 2021 12:30:12 +0100 Subject: [PATCH 12/13] fixup! doc: update README to test PR squashing --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb39974d5b4..66e791087be 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Node.js is an amazing project. It executes JavaScript code outside of a browser. For more information on using Node.js, see the [Node.js Website][]. -The Node.js amazing project uses an [open governance model](./GOVERNANCE.md). The +The Node.js project uses an [open governance model](./GOVERNANCE.md). The [OpenJS Foundation][] provides support for the project. **This project is bound by a [Code of Conduct][].** From e22bca8dd06b32e146ddfe9b14e93fd2922889a5 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Oct 2021 12:43:05 +0100 Subject: [PATCH 13/13] fixup! doc: update README to test PR squashing --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66e791087be..eb39974d5b4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Node.js is an amazing project. It executes JavaScript code outside of a browser. For more information on using Node.js, see the [Node.js Website][]. -The Node.js project uses an [open governance model](./GOVERNANCE.md). The +The Node.js amazing project uses an [open governance model](./GOVERNANCE.md). The [OpenJS Foundation][] provides support for the project. **This project is bound by a [Code of Conduct][].**