fix: raise error when the previous sha cannot be determined and since_last_remote_commit is true (#1554)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack 2023-09-08 19:18:37 -06:00 committed by GitHub
parent 4a0a3c4aa5
commit 523e8b6f11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 33 deletions

31
dist/index.js generated vendored
View File

@ -998,7 +998,7 @@ const getSHAForNonPullRequestEvent = (inputs, env, workingDirectory, isShallow,
}); });
exports.getSHAForNonPullRequestEvent = getSHAForNonPullRequestEvent; exports.getSHAForNonPullRequestEvent = getSHAForNonPullRequestEvent;
const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs) => __awaiter(void 0, void 0, void 0, function* () { const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs) => __awaiter(void 0, void 0, void 0, function* () {
var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0; var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
let targetBranch = (_m = (_l = github.context.payload.pull_request) === null || _l === void 0 ? void 0 : _l.base) === null || _m === void 0 ? void 0 : _m.ref; let targetBranch = (_m = (_l = github.context.payload.pull_request) === null || _l === void 0 ? void 0 : _l.base) === null || _m === void 0 ? void 0 : _m.ref;
const currentBranch = (_p = (_o = github.context.payload.pull_request) === null || _o === void 0 ? void 0 : _o.head) === null || _p === void 0 ? void 0 : _p.ref; const currentBranch = (_p = (_o = github.context.payload.pull_request) === null || _o === void 0 ? void 0 : _o.head) === null || _p === void 0 ? void 0 : _p.ref;
if (inputs.sinceLastRemoteCommit) { if (inputs.sinceLastRemoteCommit) {
@ -1102,21 +1102,24 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
previousSha = github.context.payload.before; previousSha = github.context.payload.before;
if (!previousSha || if (!previousSha ||
(previousSha && (previousSha &&
(yield (0, utils_1.verifyCommitSha)({ sha: previousSha, cwd: workingDirectory })) !== (yield (0, utils_1.verifyCommitSha)({
0)) { sha: previousSha,
if (github.context.payload.action && cwd: workingDirectory,
github.context.payload.action === 'synchronize') { showAsErrorMessage: false
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)'); })) !== 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.`);
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.`);
}
previousSha = yield (0, utils_1.getParentSha)({ previousSha = yield (0, utils_1.getParentSha)({
cwd: workingDirectory cwd: workingDirectory
}); });
if (github.context.payload.action &&
github.context.payload.action === 'synchronize' &&
previousSha &&
(yield (0, utils_1.verifyCommitSha)({ sha: previousSha, cwd: workingDirectory })) !==
0) {
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');
}
if (!previousSha) { 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 = (_w = (_v = github.context.payload.pull_request) === null || _v === void 0 ? void 0 : _v.base) === null || _w === void 0 ? void 0 : _w.sha;
} }
} }
} }
@ -1126,7 +1129,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
branch: targetBranch branch: targetBranch
}); });
if (!previousSha) { if (!previousSha) {
previousSha = (_y = (_x = github.context.payload.pull_request) === null || _x === void 0 ? void 0 : _x.base) === null || _y === void 0 ? void 0 : _y.sha; previousSha = (_w = (_v = github.context.payload.pull_request) === null || _v === void 0 ? void 0 : _v.base) === null || _w === void 0 ? void 0 : _w.sha;
} }
if (isShallow) { if (isShallow) {
if (!(yield (0, utils_1.canDiffCommits)({ if (!(yield (0, utils_1.canDiffCommits)({
@ -1163,7 +1166,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
} }
} }
if (!previousSha || previousSha === currentSha) { if (!previousSha || previousSha === currentSha) {
previousSha = (_0 = (_z = github.context.payload.pull_request) === null || _z === void 0 ? void 0 : _z.base) === null || _0 === void 0 ? void 0 : _0.sha; previousSha = (_y = (_x = github.context.payload.pull_request) === null || _x === void 0 ? void 0 : _x.base) === null || _y === void 0 ? void 0 : _y.sha;
} }
} }
if (!(yield (0, utils_1.canDiffCommits)({ if (!(yield (0, utils_1.canDiffCommits)({

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -419,30 +419,36 @@ export const getSHAForPullRequestEvent = async (
if ( if (
!previousSha || !previousSha ||
(previousSha && (previousSha &&
(await verifyCommitSha({sha: previousSha, cwd: workingDirectory})) !== (await verifyCommitSha({
0) sha: previousSha,
cwd: workingDirectory,
showAsErrorMessage: false
})) !== 0)
) { ) {
if (
github.context.payload.action &&
github.context.payload.action === 'synchronize'
) {
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( 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.` `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({ previousSha = await getParentSha({
cwd: workingDirectory cwd: workingDirectory
}) })
if (!previousSha) { if (
core.warning( github.context.payload.action &&
'Unable to locate the previous commit in the local history. Falling back to the pull request base sha.' github.context.payload.action === 'synchronize' &&
previousSha &&
(await verifyCommitSha({sha: previousSha, cwd: workingDirectory})) !==
0
) {
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'
)
}
if (!previousSha) {
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 { } else {