fix: raise errors when unable to locate the previous commit in local history (#1551)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack 2023-09-08 12:31:25 -06:00 committed by GitHub
parent 534262e0b2
commit 796ac2d08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 31 deletions

View File

@ -37,7 +37,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
- name: shellcheck - name: shellcheck
uses: reviewdog/action-shellcheck@v1.19 uses: reviewdog/action-shellcheck@v1.19
@ -46,7 +46,7 @@ jobs:
outputs: outputs:
files_changed: ${{ steps.changed_files.outputs.files_changed }} files_changed: ${{ steps.changed_files.outputs.files_changed }}
steps: steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - uses: actions/checkout@v4
with: with:
persist-credentials: false persist-credentials: false
fetch-depth: 0 fetch-depth: 0
@ -123,7 +123,7 @@ jobs:
if: needs.build.outputs.files_changed != 'true' if: needs.build.outputs.files_changed != 'true'
steps: steps:
- name: Checkout into dir1 - name: Checkout into dir1
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
repository: ${{ github.event.pull_request.head.repo.full_name }} repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true submodules: true
@ -163,7 +163,7 @@ jobs:
path: dir2/dist path: dir2/dist
- name: Checkout into dir2 - name: Checkout into dir2
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
repository: ${{ github.event.pull_request.head.repo.full_name }} repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true submodules: true
@ -198,7 +198,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
repository: ${{ github.event.pull_request.head.repo.full_name }} repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0 fetch-depth: 0
@ -256,7 +256,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
repository: ${{ github.event.pull_request.head.repo.full_name }} repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0 fetch-depth: 0
@ -294,7 +294,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
repository: ${{ github.event.pull_request.head.repo.full_name }} repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0 fetch-depth: 0
@ -332,7 +332,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
repository: ${{ github.event.pull_request.head.repo.full_name }} repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: ${{ matrix.fetch-depth }} fetch-depth: ${{ matrix.fetch-depth }}
@ -364,7 +364,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
@ -396,7 +396,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
fetch-depth: ${{ matrix.fetch-depth }} fetch-depth: ${{ matrix.fetch-depth }}
persist-credentials: false persist-credentials: false
@ -425,7 +425,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
- name: Download build assets - name: Download build assets
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
@ -479,7 +479,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
- name: Download build assets - name: Download build assets
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
@ -534,7 +534,7 @@ jobs:
pull-requests: read pull-requests: read
steps: steps:
- name: Checkout into dir1 - name: Checkout into dir1
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
repository: ${{ github.event.pull_request.head.repo.full_name }} repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true submodules: true
@ -570,7 +570,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.event.pull_request.head.sha || github.sha }} ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive submodules: recursive
@ -613,7 +613,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.event.pull_request.head.sha || github.sha }} ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive submodules: recursive
@ -665,7 +665,7 @@ jobs:
steps: steps:
- name: Checkout branch - name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.event.pull_request.head.sha || github.sha }} ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive submodules: recursive
@ -806,6 +806,56 @@ jobs:
cat "deleted_files/test/test deleted.txt" cat "deleted_files/test/test deleted.txt"
fi fi
test-since-last-remote-commit:
name: Test changed-files since last remote commit
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'
strategy:
fail-fast: false
max-parallel: 4
matrix:
fetch-depth: [0, 1, 2]
steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
fetch-depth: ${{ matrix.fetch-depth }}
- name: Download build assets
uses: actions/download-artifact@v3
with:
name: build-assets
- name: Run changed-files with since_last_remote_commit
id: changed-files-since-last-remote-commit
continue-on-error: true
uses: ./
with:
since_last_remote_commit: true
- name: Verify failed
if: steps.changed-files-since-last-remote-commit.outcome != 'failure' && matrix.fetch-depth == 1 && github.event_name != 'push'
run: |
echo "Expected: (failure) got ${{ steps.changed-files-since-last-remote-commit.outcome }}"
exit 1
- name: Verify succeeded
if: steps.changed-files-since-last-remote-commit.outcome != 'success' && matrix.fetch-depth != 1
run: |
echo "Expected: (success) got ${{ steps.changed-files-since-last-remote-commit.outcome }}"
exit 1
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-since-last-remote-commit.outputs) }}'
shell:
bash
test: test:
name: Test changed-files name: Test changed-files
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
@ -820,7 +870,7 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@v4
with: with:
submodules: true submodules: true
repository: ${{ github.event.pull_request.head.repo.full_name }} repository: ${{ github.event.pull_request.head.repo.full_name }}
@ -841,16 +891,6 @@ jobs:
echo '${{ toJSON(steps.changed-files.outputs) }}' echo '${{ toJSON(steps.changed-files.outputs) }}'
shell: shell:
bash bash
- name: Run changed-files with since_last_remote_commit
id: changed-files-since-last-remote-commit
uses: ./
with:
since_last_remote_commit: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-since-last-remote-commit.outputs) }}'
shell:
bash
- name: Run changed-files with dir name - name: Run changed-files with dir name
id: changed-files-dir-name id: changed-files-dir-name
uses: ./ uses: ./

2
dist/index.js generated vendored
View File

@ -1106,7 +1106,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
0)) { 0)) {
if (github.context.payload.action && if (github.context.payload.action &&
github.context.payload.action === 'synchronize') { github.context.payload.action === 'synchronize') {
core.warning('Unable to locate the remote branch head sha. Falling back to the previous commit in the local history.'); throw Error('Unable to locate the previous commit in the local history. Please ensure to checkout pull request HEAD commit instead of the merge commit. See: https://github.com/actions/checkout/blob/main/README.md#checkout-pull-request-head-commit-instead-of-merge-commit)');
} }
else { else {
core.info(`Unable to locate the remote branch head sha for ${github.context.eventName} (${github.context.payload.action}) events. Falling back to the previous commit in the local history.`); core.info(`Unable to locate the remote branch head sha for ${github.context.eventName} (${github.context.payload.action}) events. Falling back to the previous commit in the local history.`);

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -426,8 +426,8 @@ export const getSHAForPullRequestEvent = async (
github.context.payload.action && github.context.payload.action &&
github.context.payload.action === 'synchronize' github.context.payload.action === 'synchronize'
) { ) {
core.warning( throw Error(
'Unable to locate the remote branch head sha. Falling back to the previous commit in the local history.' 'Unable to locate the previous commit in the local history. Please ensure to checkout pull request HEAD commit instead of the merge commit. See: https://github.com/actions/checkout/blob/main/README.md#checkout-pull-request-head-commit-instead-of-merge-commit)'
) )
} else { } else {
core.info( core.info(