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

feat: improve warning message #1241

Merged
merged 4 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 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.

25 changes: 22 additions & 3 deletions src/commitSha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,28 @@ export const getSHAForPullRequestEvent = async (
core.error(
`Similar commit hashes detected: previous sha: ${previousSha} is equivalent to the current sha: ${currentSha}.`
)
core.error(
`Please verify that both commits are valid, and increase the fetch_depth to a number higher than ${inputs.fetchDepth}.`
)
// This occurs if a PR is created from a forked repository and the event is pull_request_target.
// - name: Checkout to branch
// uses: actions/checkout@v3
// Without setting the repository to use the same repository as the pull request will cause the previousSha
// to be the same as the currentSha since the currentSha cannot be found in the local history.
// The solution is to use:
// - name: Checkout to branch
// uses: actions/checkout@v3
// with:
// repository: ${{ github.event.pull_request.head.repo.full_name }}
if (env.GITHUB_EVENT_NAME === 'pull_request_target') {
core.warning(
'If this pull request is from a forked repository, please set the checkout action `repository` input to the same repository as the pull request.'
)
core.warning(
'This can be done by setting actions/checkout `repository` to ${{ github.event.pull_request.head.repo.full_name }}'
)
} else {
core.error(
`Please verify that both commits are valid, and increase the fetch_depth to a number higher than ${inputs.fetchDepth}.`
)
}
throw new Error('Similar commit hashes detected.')
}

Expand Down
4 changes: 3 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type Env = {
GITHUB_EVENT_PULL_REQUEST_NUMBER: string
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: string
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: string
GITHUB_EVENT_NAME: string
}

type GithubEvent = {
Expand Down Expand Up @@ -66,6 +67,7 @@ export const getEnv = async (): Promise<Env> => {
GITHUB_EVENT_FORCED: eventJson.forced || '',
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
GITHUB_REF: process.env.GITHUB_REF || '',
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE || ''
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE || '',
GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || ''
}
}