diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml index 0f6fd639523..eaa83d4faff 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: @@ -20,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..bdfd0339ffe 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 @@ -26,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,8 +65,8 @@ jobs: run: | 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 username "${{ github.actor }}" + 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}" diff --git a/README.md b/README.md index 72f85968963..eb39974d5b4 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,10 @@

-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][]. +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][].** 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..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" } @@ -70,7 +74,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 @@ -84,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