mirror of
https://github.com/tj-actions/changed-files
synced 2025-03-06 05:17:44 +00:00
fix: error detecting initial commits (#1181)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
88fb02bd31
commit
9ad1a5b96a
5 changed files with 39 additions and 29 deletions
30
dist/index.js
generated
vendored
30
dist/index.js
generated
vendored
|
@ -315,22 +315,14 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
||||||
cwd: workingDirectory
|
cwd: workingDirectory
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (previousSha === currentSha) {
|
if (!previousSha || previousSha === currentSha) {
|
||||||
if (!(yield (0, utils_1.getParentSha)({ cwd: workingDirectory }))) {
|
|
||||||
core.warning('Initial commit detected no previous commit found.');
|
|
||||||
initialCommit = true;
|
|
||||||
previousSha = currentSha;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
previousSha = yield (0, utils_1.getParentSha)({
|
previousSha = yield (0, utils_1.getParentSha)({
|
||||||
cwd: workingDirectory
|
cwd: workingDirectory
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!previousSha) {
|
if (!previousSha) {
|
||||||
core.error('Unable to locate a previous commit.');
|
core.warning('Initial commit detected no previous commit found.');
|
||||||
throw new Error('Unable to locate a previous commit.');
|
initialCommit = true;
|
||||||
|
previousSha = currentSha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,7 +341,8 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
||||||
currentSha,
|
currentSha,
|
||||||
currentBranch,
|
currentBranch,
|
||||||
targetBranch,
|
targetBranch,
|
||||||
diff
|
diff,
|
||||||
|
initialCommit
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
exports.getSHAForPushEvent = getSHAForPushEvent;
|
exports.getSHAForPushEvent = getSHAForPushEvent;
|
||||||
|
@ -824,6 +817,11 @@ function run() {
|
||||||
core.info('Running on a pull request event...');
|
core.info('Running on a pull request event...');
|
||||||
diffResult = yield (0, commitSha_1.getSHAForPullRequestEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitExtraArgs);
|
diffResult = yield (0, commitSha_1.getSHAForPullRequestEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitExtraArgs);
|
||||||
}
|
}
|
||||||
|
if (diffResult.initialCommit) {
|
||||||
|
core.info('This is the first commit for this repository; exiting...');
|
||||||
|
core.endGroup();
|
||||||
|
return;
|
||||||
|
}
|
||||||
core.info(`Retrieving changes between ${diffResult.previousSha} (${diffResult.targetBranch}) → ${diffResult.currentSha} (${diffResult.currentBranch})`);
|
core.info(`Retrieving changes between ${diffResult.previousSha} (${diffResult.targetBranch}) → ${diffResult.currentSha} (${diffResult.currentBranch})`);
|
||||||
const filePatterns = yield (0, utils_1.getFilePatterns)({
|
const filePatterns = yield (0, utils_1.getFilePatterns)({
|
||||||
inputs,
|
inputs,
|
||||||
|
@ -1531,10 +1529,14 @@ const gitLsRemote = ({ cwd, args }) => __awaiter(void 0, void 0, void 0, functio
|
||||||
});
|
});
|
||||||
exports.gitLsRemote = gitLsRemote;
|
exports.gitLsRemote = gitLsRemote;
|
||||||
const getParentSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
|
const getParentSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const { stdout } = yield exec.getExecOutput('git', ['rev-list', '-n', '1', 'HEAD^'], {
|
const { stdout, exitCode } = yield exec.getExecOutput('git', ['rev-list', '-n', '1', 'HEAD^'], {
|
||||||
cwd,
|
cwd,
|
||||||
|
ignoreReturnCode: true,
|
||||||
silent: process.env.RUNNER_DEBUG !== '1'
|
silent: process.env.RUNNER_DEBUG !== '1'
|
||||||
});
|
});
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
return stdout.trim();
|
return stdout.trim();
|
||||||
});
|
});
|
||||||
exports.getParentSha = getParentSha;
|
exports.getParentSha = getParentSha;
|
||||||
|
|
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
|
@ -63,6 +63,7 @@ export interface DiffResult {
|
||||||
currentBranch: string
|
currentBranch: string
|
||||||
targetBranch: string
|
targetBranch: string
|
||||||
diff: string
|
diff: string
|
||||||
|
initialCommit?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getSHAForPushEvent = async (
|
export const getSHAForPushEvent = async (
|
||||||
|
@ -201,20 +202,15 @@ export const getSHAForPushEvent = async (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previousSha === currentSha) {
|
if (!previousSha || previousSha === currentSha) {
|
||||||
if (!(await getParentSha({cwd: workingDirectory}))) {
|
|
||||||
core.warning('Initial commit detected no previous commit found.')
|
|
||||||
initialCommit = true
|
|
||||||
previousSha = currentSha
|
|
||||||
} else {
|
|
||||||
previousSha = await getParentSha({
|
previousSha = await getParentSha({
|
||||||
cwd: workingDirectory
|
cwd: workingDirectory
|
||||||
})
|
})
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!previousSha) {
|
if (!previousSha) {
|
||||||
core.error('Unable to locate a previous commit.')
|
core.warning('Initial commit detected no previous commit found.')
|
||||||
throw new Error('Unable to locate a previous commit.')
|
initialCommit = true
|
||||||
|
previousSha = currentSha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,7 +237,8 @@ export const getSHAForPushEvent = async (
|
||||||
currentSha,
|
currentSha,
|
||||||
currentBranch,
|
currentBranch,
|
||||||
targetBranch,
|
targetBranch,
|
||||||
diff
|
diff,
|
||||||
|
initialCommit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,12 @@ export async function run(): Promise<void> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (diffResult.initialCommit) {
|
||||||
|
core.info('This is the first commit for this repository; exiting...')
|
||||||
|
core.endGroup()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`Retrieving changes between ${diffResult.previousSha} (${diffResult.targetBranch}) → ${diffResult.currentSha} (${diffResult.currentBranch})`
|
`Retrieving changes between ${diffResult.previousSha} (${diffResult.targetBranch}) → ${diffResult.currentSha} (${diffResult.currentBranch})`
|
||||||
)
|
)
|
||||||
|
|
|
@ -526,15 +526,20 @@ export const gitLsRemote = async ({
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
|
export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
|
||||||
const {stdout} = await exec.getExecOutput(
|
const {stdout, exitCode} = await exec.getExecOutput(
|
||||||
'git',
|
'git',
|
||||||
['rev-list', '-n', '1', 'HEAD^'],
|
['rev-list', '-n', '1', 'HEAD^'],
|
||||||
{
|
{
|
||||||
cwd,
|
cwd,
|
||||||
|
ignoreReturnCode: true,
|
||||||
silent: process.env.RUNNER_DEBUG !== '1'
|
silent: process.env.RUNNER_DEBUG !== '1'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
return stdout.trim()
|
return stdout.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue