feat: improve warning message (#1241)
Co-authored-by: GitHub Action <action@github.com> Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
parent
f490eeaa59
commit
f41e41fa3f
21
dist/index.js
generated
vendored
21
dist/index.js
generated
vendored
@ -515,7 +515,23 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
|||||||
}
|
}
|
||||||
if (previousSha === currentSha) {
|
if (previousSha === currentSha) {
|
||||||
core.error(`Similar commit hashes detected: previous sha: ${previousSha} is equivalent to the current sha: ${currentSha}.`);
|
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.');
|
throw new Error('Similar commit hashes detected.');
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@ -594,7 +610,8 @@ const getEnv = () => __awaiter(void 0, void 0, void 0, function* () {
|
|||||||
GITHUB_EVENT_FORCED: eventJson.forced || '',
|
GITHUB_EVENT_FORCED: eventJson.forced || '',
|
||||||
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
|
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
|
||||||
GITHUB_REF: process.env.GITHUB_REF || '',
|
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 || ''
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
exports.getEnv = getEnv;
|
exports.getEnv = getEnv;
|
||||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -469,9 +469,28 @@ export const getSHAForPullRequestEvent = async (
|
|||||||
core.error(
|
core.error(
|
||||||
`Similar commit hashes detected: previous sha: ${previousSha} is equivalent to the current sha: ${currentSha}.`
|
`Similar commit hashes detected: previous sha: ${previousSha} is equivalent to the current sha: ${currentSha}.`
|
||||||
)
|
)
|
||||||
core.error(
|
// This occurs if a PR is created from a forked repository and the event is pull_request_target.
|
||||||
`Please verify that both commits are valid, and increase the fetch_depth to a number higher than ${inputs.fetchDepth}.`
|
// - 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.')
|
throw new Error('Similar commit hashes detected.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ export type Env = {
|
|||||||
GITHUB_EVENT_PULL_REQUEST_NUMBER: string
|
GITHUB_EVENT_PULL_REQUEST_NUMBER: string
|
||||||
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: string
|
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: string
|
||||||
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: string
|
GITHUB_EVENT_PULL_REQUEST_HEAD_SHA: string
|
||||||
|
GITHUB_EVENT_NAME: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GithubEvent = {
|
type GithubEvent = {
|
||||||
@ -66,6 +67,7 @@ export const getEnv = async (): Promise<Env> => {
|
|||||||
GITHUB_EVENT_FORCED: eventJson.forced || '',
|
GITHUB_EVENT_FORCED: eventJson.forced || '',
|
||||||
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
|
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
|
||||||
GITHUB_REF: process.env.GITHUB_REF || '',
|
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 || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user