Skip to content

Commit

Permalink
fix: raise error when the previous sha cannot be determined and since…
Browse files Browse the repository at this point in the history
…_last_remote_commit is true (#1554)

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
jackton1 and actions-user authored Sep 9, 2023
1 parent 4a0a3c4 commit 523e8b6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
31 changes: 17 additions & 14 deletions 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.

36 changes: 21 additions & 15 deletions src/commitSha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,30 +419,36 @@ export const getSHAForPullRequestEvent = async (
if (
!previousSha ||
(previousSha &&
(await verifyCommitSha({sha: previousSha, cwd: workingDirectory})) !==
0)
(await verifyCommitSha({
sha: previousSha,
cwd: workingDirectory,
showAsErrorMessage: false
})) !== 0)
) {
core.info(
`Unable to locate the previous commit in the local history for ${github.context.eventName} (${github.context.payload.action}) event. Falling back to the previous commit in the local history.`
)

previousSha = await getParentSha({
cwd: workingDirectory
})

if (
github.context.payload.action &&
github.context.payload.action === 'synchronize'
github.context.payload.action === 'synchronize' &&
previousSha &&
(await verifyCommitSha({sha: previousSha, cwd: workingDirectory})) !==
0
) {
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(
`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.`
throw new 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'
)
}
previousSha = await getParentSha({
cwd: workingDirectory
})

if (!previousSha) {
core.warning(
'Unable to locate the previous commit in the local history. Falling back to the pull request base sha.'
throw new 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'
)
previousSha = github.context.payload.pull_request?.base?.sha
}
}
} else {
Expand Down

0 comments on commit 523e8b6

Please sign in to comment.