Skip to content

Commit

Permalink
fix: raise errors when unable to locate the previous commit in local …
Browse files Browse the repository at this point in the history
…history (#1551)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
jackton1 and actions-user authored Sep 8, 2023
1 parent 534262e commit 796ac2d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 31 deletions.
94 changes: 67 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
- name: shellcheck
uses: reviewdog/action-shellcheck@v1.19

Expand All @@ -46,7 +46,7 @@ jobs:
outputs:
files_changed: ${{ steps.changed_files.outputs.files_changed }}
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
if: needs.build.outputs.files_changed != 'true'
steps:
- name: Checkout into dir1
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
path: dir2/dist

- name: Checkout into dir2
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
Expand Down Expand Up @@ -294,7 +294,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
Expand Down Expand Up @@ -332,7 +332,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: ${{ matrix.fetch-depth }}
Expand Down Expand Up @@ -364,7 +364,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

Expand Down Expand Up @@ -396,7 +396,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
fetch-depth: ${{ matrix.fetch-depth }}
persist-credentials: false
Expand Down Expand Up @@ -425,7 +425,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4

- name: Download build assets
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -479,7 +479,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4

- name: Download build assets
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -534,7 +534,7 @@ jobs:
pull-requests: read
steps:
- name: Checkout into dir1
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
Expand Down Expand Up @@ -570,7 +570,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive
Expand Down Expand Up @@ -613,7 +613,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive
Expand Down Expand Up @@ -665,7 +665,7 @@ jobs:

steps:
- name: Checkout branch
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
submodules: recursive
Expand Down Expand Up @@ -805,6 +805,56 @@ jobs:
else
cat "deleted_files/test/test deleted.txt"
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:
name: Test changed-files
Expand All @@ -820,7 +870,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@v4
with:
submodules: true
repository: ${{ github.event.pull_request.head.repo.full_name }}
Expand All @@ -841,16 +891,6 @@ jobs:
echo '${{ toJSON(steps.changed-files.outputs) }}'
shell:
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
id: changed-files-dir-name
uses: ./
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/commitSha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ export const getSHAForPullRequestEvent = async (
github.context.payload.action &&
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 {
core.info(
Expand Down

0 comments on commit 796ac2d

Please sign in to comment.