-
Notifications
You must be signed in to change notification settings - Fork 0
feat: report the pull request's commit when CI checks out a merge commit #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
65acdde
feat: report the pull request's commit when CI checks out a merge commit
agoldis 1152644
test: check the pull request commit on real GitHub checkouts
agoldis 5e02907
test: trust the checkout in the git 2.25 container
agoldis 2408742
fix: only replace a checked-out merge commit with the pull request's …
agoldis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| 'use strict' | ||
|
|
||
| // Runs commitInfo on the checkout that actions/checkout makes for a | ||
| // pull_request event: GitHub's merge commit refs/pull/N/merge. | ||
| // | ||
| // EXPECTED_COMMIT=head: commitInfo reports the pull request's last commit | ||
| // EXPECTED_COMMIT=checkout: commitInfo reports the merge commit, as before | ||
|
|
||
| const assert = require('assert') | ||
| const { execFileSync } = require('child_process') | ||
| const { commitInfo } = require('../../src') | ||
|
|
||
| const headSha = process.env.HEAD_SHA | ||
| const expected = process.env.EXPECTED_COMMIT || 'head' | ||
|
|
||
| const git = (...args) => | ||
| execFileSync('git', args, { encoding: 'utf8' }).replace(/\n$/, '') | ||
|
|
||
| const checkoutSha = git('rev-parse', 'HEAD') | ||
| assert.notStrictEqual(checkoutSha, headSha, 'expected the merge commit') | ||
|
|
||
| commitInfo() | ||
| .then(info => { | ||
| console.log(info) | ||
| const sha = expected === 'head' ? headSha : checkoutSha | ||
| assert.strictEqual(info.sha, sha) | ||
| assert.strictEqual(info.message, git('show', '-s', '--pretty=%B', sha)) | ||
| assert.strictEqual(info.author, git('show', '-s', '--pretty=%an', sha)) | ||
| assert.strictEqual(info.email, git('show', '-s', '--pretty=%ae', sha)) | ||
| console.log(`commitInfo reported ${expected} commit ${sha}`) | ||
| }) | ||
| .catch(e => { | ||
| console.error(e) | ||
| process.exit(1) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| name: Pull request commit | ||
| on: pull_request | ||
|
|
||
| # the job runs code from the pull request | ||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| commit-info: | ||
| name: commitInfo (${{ matrix.name }}) | ||
| runs-on: ubuntu-latest | ||
| container: ${{ matrix.container }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - name: default checkout | ||
| fetch-depth: 1 | ||
| expected: head | ||
| - name: full clone | ||
| fetch-depth: 0 | ||
| expected: head | ||
| - name: git 2.25 | ||
| fetch-depth: 1 | ||
| expected: head | ||
| container: mcr.microsoft.com/playwright:v1.28.1-focal | ||
| - name: fetch disabled | ||
| fetch-depth: 1 | ||
| expected: checkout | ||
| disable-fetch: 'true' | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: ${{ matrix.fetch-depth }} | ||
| - uses: actions/setup-node@v4 | ||
| if: ${{ !matrix.container }} | ||
| with: | ||
| node-version: 16 | ||
| # the checkout belongs to another user than the container's root | ||
| - if: ${{ matrix.container }} | ||
| run: git config --global --add safe.directory "$GITHUB_WORKSPACE" | ||
| - run: git --version && node --version | ||
| - run: npm ci --ignore-scripts | ||
| - run: node .github/scripts/check-pull-request-commit.js | ||
| env: | ||
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
| EXPECTED_COMMIT: ${{ matrix.expected }} | ||
| CURRENTS_DISABLE_HEAD_COMMIT_FETCH: ${{ matrix.disable-fetch }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.