fix/resolve bug fetching more history (#1176)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack
2023-05-25 21:14:24 -06:00
committed by GitHub
parent 77f872a759
commit 25eaddf37a
7 changed files with 71 additions and 55 deletions

54
dist/index.js generated vendored
View File

@@ -260,7 +260,7 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
throw new Error('Similar commit hashes detected.');
}
yield (0, utils_1.verifyCommitSha)({ sha: previousSha, cwd: workingDirectory });
core.info(`Previous SHA: ${previousSha}`);
core.debug(`Previous SHA: ${previousSha}`);
return {
previousSha,
currentSha,
@@ -299,13 +299,18 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
if (env.GITHUB_EVENT_FORCED === 'false' || !env.GITHUB_EVENT_FORCED) {
previousSha = env.GITHUB_EVENT_BEFORE;
}
else {
if (!previousSha ||
previousSha === '0000000000000000000000000000000000000000') {
previousSha = yield (0, utils_1.getParentSha)({
cwd: workingDirectory
});
}
if (!previousSha ||
previousSha === '0000000000000000000000000000000000000000') {
else if ((yield (0, utils_1.verifyCommitSha)({
sha: previousSha,
cwd: workingDirectory,
showAsErrorMessage: false
})) !== 0) {
core.warning(`Previous commit ${previousSha} is not valid. Using parent commit.`);
previousSha = yield (0, utils_1.getParentSha)({
cwd: workingDirectory
});
@@ -415,7 +420,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
throw new Error('Similar commit hashes detected.');
}
yield (0, utils_1.verifyCommitSha)({ sha: currentSha, cwd: workingDirectory });
core.info(`Previous SHA: ${previousSha}`);
core.debug(`Previous SHA: ${previousSha}`);
return {
previousSha,
currentSha,
@@ -575,6 +580,7 @@ const getEnv = () => __awaiter(void 0, void 0, void 0, function* () {
if (eventPath) {
eventJson = JSON.parse(yield fs_1.promises.readFile(eventPath, { encoding: 'utf8' }));
}
core.debug(`Env: ${JSON.stringify(process.env, null, 2)}`);
core.debug(`Event: ${JSON.stringify(eventJson, null, 2)}`);
return {
GITHUB_EVENT_PULL_REQUEST_HEAD_REF: ((_b = (_a = eventJson.pull_request) === null || _a === void 0 ? void 0 : _a.head) === null || _b === void 0 ? void 0 : _b.ref) || '',
@@ -713,7 +719,7 @@ const getInputs = () => {
outputDir
};
if (fetchDepth) {
inputs.fetchDepth = parseInt(fetchDepth, 10);
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2);
}
if (dirNamesMaxDepth) {
inputs.dirNamesMaxDepth = parseInt(dirNamesMaxDepth, 10);
@@ -1234,7 +1240,7 @@ const versionToNumber = (version) => {
return major * 1000000 + minor * 1000 + patch;
};
const verifyMinimumGitVersion = () => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['--version'], { silent: process.env.ACTION_DEBUG === 'false' });
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['--version'], { silent: process.env.RUNNER_DEBUG !== '1' });
if (exitCode !== 0) {
throw new Error(stderr || 'An unexpected error occurred');
}
@@ -1329,7 +1335,7 @@ const getFilesFromSourceFile = ({ filePaths, excludedFiles = false }) => __await
const updateGitGlobalConfig = ({ name, value }) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stderr } = yield exec.getExecOutput('git', ['config', '--global', name, value], {
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
/* istanbul ignore if */
if (exitCode !== 0 || stderr) {
@@ -1340,7 +1346,7 @@ exports.updateGitGlobalConfig = updateGitGlobalConfig;
const isRepoShallow = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-parse', '--is-shallow-repository'], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
return stdout.trim() === 'true';
});
@@ -1349,7 +1355,7 @@ const submoduleExists = ({ cwd }) => __awaiter(void 0, void 0, void 0, function*
const { stdout, exitCode } = yield exec.getExecOutput('git', ['submodule', 'status'], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
if (exitCode !== 0) {
return false;
@@ -1361,7 +1367,7 @@ const gitFetch = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function*
const { exitCode } = yield exec.getExecOutput('git', ['fetch', '-q', ...args], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
return exitCode;
});
@@ -1370,7 +1376,7 @@ const gitFetchSubmodules = ({ args, cwd }) => __awaiter(void 0, void 0, void 0,
const { exitCode, stderr } = yield exec.getExecOutput('git', ['submodule', 'foreach', 'git', 'fetch', '-q', ...args], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
/* istanbul ignore if */
if (exitCode !== 0) {
@@ -1385,7 +1391,7 @@ const getSubmodulePath = ({ cwd }) => __awaiter(void 0, void 0, void 0, function
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['submodule', 'status'], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
if (exitCode !== 0) {
core.warning(stderr || "Couldn't get submodule names");
@@ -1401,7 +1407,7 @@ const gitSubmoduleDiffSHA = ({ cwd, parentSha1, parentSha2, submodulePath, diff
var _h, _j, _k, _l;
const { stdout } = yield exec.getExecOutput('git', ['diff', parentSha1, parentSha2, '--', submodulePath], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
const subprojectCommitPreRegex = /^(?<preCommit>-)Subproject commit (?<commitHash>.+)$/m;
const subprojectCommitCurRegex = /^(?<curCommit>\+)Subproject commit (?<commitHash>.+)$/m;
@@ -1425,7 +1431,7 @@ const gitRenamedFiles = ({ cwd, sha1, sha2, diff, oldNewSeparator, isSubmodule =
], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
if (exitCode !== 0) {
if (isSubmodule) {
@@ -1463,7 +1469,7 @@ const gitDiff = ({ cwd, sha1, sha2, diff, diffFilter, filePatterns = [], isSubmo
], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
if (exitCode !== 0) {
if (isSubmodule) {
@@ -1498,7 +1504,7 @@ exports.gitDiff = gitDiff;
const gitLog = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['log', ...args], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
return stdout.trim();
});
@@ -1506,7 +1512,7 @@ exports.gitLog = gitLog;
const getHeadSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-parse', 'HEAD'], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
return stdout.trim();
});
@@ -1514,7 +1520,7 @@ exports.getHeadSha = getHeadSha;
const gitLsRemote = ({ cwd, args }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['ls-remote', 'origin', ...args], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
const output = stdout.trim().split('\t');
if (output.length === 0) {
@@ -1526,7 +1532,7 @@ exports.gitLsRemote = gitLsRemote;
const getParentSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-list', '-n', '1', 'HEAD^'], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
return stdout.trim();
});
@@ -1535,7 +1541,7 @@ const verifyCommitSha = ({ sha, cwd, showAsErrorMessage = true }) => __awaiter(v
const { exitCode, stderr } = yield exec.getExecOutput('git', ['rev-parse', '--verify', `${sha}^{commit}`], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
if (exitCode !== 0) {
if (showAsErrorMessage) {
@@ -1554,7 +1560,7 @@ exports.verifyCommitSha = verifyCommitSha;
const getPreviousGitTag = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['tag', '--sort=-version:refname'], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
const tags = stdout.trim().split('\n');
if (tags.length < 2) {
@@ -1564,7 +1570,7 @@ const getPreviousGitTag = ({ cwd }) => __awaiter(void 0, void 0, void 0, functio
const previousTag = tags[1];
const { stdout: stdout2 } = yield exec.getExecOutput('git', ['rev-parse', previousTag], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
const sha = stdout2.trim();
return { tag: previousTag, sha };
@@ -1574,7 +1580,7 @@ const canDiffCommits = ({ cwd, sha1, sha2, diff }) => __awaiter(void 0, void 0,
const { exitCode, stderr } = yield exec.getExecOutput('git', ['diff', '--name-only', '--ignore-submodules=all', `${sha1}${diff}${sha2}`], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
});
if (exitCode !== 0) {
core.warning(stderr || `Unable find merge base between ${sha1} and ${sha2}`);