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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 55 deletions

View File

@ -689,16 +689,16 @@ jobs:
echo '${{ toJSON(steps.changed-files-json.outputs.all_changed_files) }}'
shell:
bash
- name: Run changed-files with json raw format
id: changed-files-json-raw-format
- name: Run changed-files with json unescaped format
id: changed-files-json-unescaped
uses: ./
with:
json: true
json_raw_format: true
escape_json: false
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-json-raw-format.outputs) }}'
echo '${{ toJSON(steps.changed-files-json-raw-format.outputs.all_changed_files) }}'
echo '${{ toJSON(steps.changed-files-json-unescaped.outputs) }}'
echo '${{ toJSON(steps.changed-files-json-unescaped.outputs.all_changed_files) }}'
shell:
bash
- name: Run changed-files with comma separator

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}`);

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -137,7 +137,7 @@ export const getSHAForPushEvent = async (
}
await verifyCommitSha({sha: previousSha, cwd: workingDirectory})
core.info(`Previous SHA: ${previousSha}`)
core.debug(`Previous SHA: ${previousSha}`)
return {
previousSha,
@ -177,10 +177,6 @@ export const getSHAForPushEvent = async (
core.debug('Getting previous SHA for last remote commit...')
if (env.GITHUB_EVENT_FORCED === 'false' || !env.GITHUB_EVENT_FORCED) {
previousSha = env.GITHUB_EVENT_BEFORE
} else {
previousSha = await getParentSha({
cwd: workingDirectory
})
}
if (
@ -190,6 +186,19 @@ export const getSHAForPushEvent = async (
previousSha = await getParentSha({
cwd: workingDirectory
})
} else if (
(await verifyCommitSha({
sha: previousSha,
cwd: workingDirectory,
showAsErrorMessage: false
})) !== 0
) {
core.warning(
`Previous commit ${previousSha} is not valid. Using parent commit.`
)
previousSha = await getParentSha({
cwd: workingDirectory
})
}
if (previousSha === currentSha) {
@ -322,7 +331,7 @@ export const getSHAForPullRequestEvent = async (
}
await verifyCommitSha({sha: currentSha, cwd: workingDirectory})
core.info(`Previous SHA: ${previousSha}`)
core.debug(`Previous SHA: ${previousSha}`)
return {
previousSha,

View File

@ -41,6 +41,7 @@ export const getEnv = async (): Promise<Env> => {
if (eventPath) {
eventJson = JSON.parse(await fs.readFile(eventPath, {encoding: 'utf8'}))
}
core.debug(`Env: ${JSON.stringify(process.env, null, 2)}`)
core.debug(`Event: ${JSON.stringify(eventJson, null, 2)}`)
return {

View File

@ -135,7 +135,7 @@ export const getInputs = (): Inputs => {
}
if (fetchDepth) {
inputs.fetchDepth = parseInt(fetchDepth, 10)
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2)
}
if (dirNamesMaxDepth) {

View File

@ -93,7 +93,7 @@ export const verifyMinimumGitVersion = async (): Promise<void> => {
const {exitCode, stdout, stderr} = await exec.getExecOutput(
'git',
['--version'],
{silent: process.env.ACTION_DEBUG === 'false'}
{silent: process.env.RUNNER_DEBUG !== '1'}
)
if (exitCode !== 0) {
@ -177,7 +177,7 @@ export const updateGitGlobalConfig = async ({
['config', '--global', name, value],
{
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -193,7 +193,7 @@ export const isRepoShallow = async ({cwd}: {cwd: string}): Promise<boolean> => {
['rev-parse', '--is-shallow-repository'],
{
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -211,7 +211,7 @@ export const submoduleExists = async ({
{
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -232,7 +232,7 @@ export const gitFetch = async ({
const {exitCode} = await exec.getExecOutput('git', ['fetch', '-q', ...args], {
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
})
return exitCode
@ -251,7 +251,7 @@ export const gitFetchSubmodules = async ({
{
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -276,7 +276,7 @@ export const getSubmodulePath = async ({
{
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -309,7 +309,7 @@ export const gitSubmoduleDiffSHA = async ({
['diff', parentSha1, parentSha2, '--', submodulePath],
{
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -362,7 +362,7 @@ export const gitRenamedFiles = async ({
{
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -434,7 +434,7 @@ export const gitDiff = async ({
{
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -486,7 +486,7 @@ export const gitLog = async ({
}): Promise<string> => {
const {stdout} = await exec.getExecOutput('git', ['log', ...args], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
})
return stdout.trim()
@ -495,7 +495,7 @@ export const gitLog = async ({
export const getHeadSha = async ({cwd}: {cwd: string}): Promise<string> => {
const {stdout} = await exec.getExecOutput('git', ['rev-parse', 'HEAD'], {
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
})
return stdout.trim()
@ -513,7 +513,7 @@ export const gitLsRemote = async ({
['ls-remote', 'origin', ...args],
{
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
const output = stdout.trim().split('\t')
@ -531,7 +531,7 @@ export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
['rev-list', '-n', '1', 'HEAD^'],
{
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -553,7 +553,7 @@ export const verifyCommitSha = async ({
{
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -583,7 +583,7 @@ export const getPreviousGitTag = async ({
['tag', '--sort=-version:refname'],
{
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -601,7 +601,7 @@ export const getPreviousGitTag = async ({
['rev-parse', previousTag],
{
cwd,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)
@ -627,7 +627,7 @@ export const canDiffCommits = async ({
{
cwd,
ignoreReturnCode: true,
silent: process.env.ACTION_DEBUG === 'false'
silent: process.env.RUNNER_DEBUG !== '1'
}
)