Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: update README to test PR squashing #40

Closed
wants to merge 13 commits into from
Closed
7 changes: 4 additions & 3 deletions .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ 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:
node-version: ${{ env.NODE_VERSION }}
- 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
10 changes: 2 additions & 8 deletions .github/workflows/commit-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ env:

jobs:
commitQueue:
if: github.repository == 'nodejs/node'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# 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
Expand Down Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</a>
</p>

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][].

Expand Down
8 changes: 7 additions & 1 deletion doc/guides/commit-queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pr>`
4. Run `git node land <pr> --oneCommitMax`
5. If it fails:
1. Abort `git node land` session
2. Add `commit-queue-failed` label to the PR
Expand All @@ -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
Expand Down
37 changes: 31 additions & 6 deletions tools/actions/commit-queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down