mirror of
https://github.com/tj-actions/changed-files
synced 2025-03-05 21:06:25 +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
32
dist/index.js
generated
vendored
32
dist/index.js
generated
vendored
|
@ -315,23 +315,15 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
|||
cwd: workingDirectory
|
||||
});
|
||||
}
|
||||
if (previousSha === currentSha) {
|
||||
if (!(yield (0, utils_1.getParentSha)({ cwd: workingDirectory }))) {
|
||||
if (!previousSha || previousSha === currentSha) {
|
||||
previousSha = yield (0, utils_1.getParentSha)({
|
||||
cwd: workingDirectory
|
||||
});
|
||||
if (!previousSha) {
|
||||
core.warning('Initial commit detected no previous commit found.');
|
||||
initialCommit = true;
|
||||
previousSha = currentSha;
|
||||
}
|
||||
else {
|
||||
previousSha = yield (0, utils_1.getParentSha)({
|
||||
cwd: workingDirectory
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!previousSha) {
|
||||
core.error('Unable to locate a previous commit.');
|
||||
throw new Error('Unable to locate a previous commit.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +341,8 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
|||
currentSha,
|
||||
currentBranch,
|
||||
targetBranch,
|
||||
diff
|
||||
diff,
|
||||
initialCommit
|
||||
};
|
||||
});
|
||||
exports.getSHAForPushEvent = getSHAForPushEvent;
|
||||
|
@ -824,6 +817,11 @@ function run() {
|
|||
core.info('Running on a pull request event...');
|
||||
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})`);
|
||||
const filePatterns = yield (0, utils_1.getFilePatterns)({
|
||||
inputs,
|
||||
|
@ -1531,10 +1529,14 @@ const gitLsRemote = ({ cwd, args }) => __awaiter(void 0, void 0, void 0, functio
|
|||
});
|
||||
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^'], {
|
||||
const { stdout, exitCode } = yield exec.getExecOutput('git', ['rev-list', '-n', '1', 'HEAD^'], {
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: process.env.RUNNER_DEBUG !== '1'
|
||||
});
|
||||
if (exitCode !== 0) {
|
||||
return '';
|
||||
}
|
||||
return stdout.trim();
|
||||
});
|
||||
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
|
||||
targetBranch: string
|
||||
diff: string
|
||||
initialCommit?: boolean
|
||||
}
|
||||
|
||||
export const getSHAForPushEvent = async (
|
||||
|
@ -201,20 +202,15 @@ export const getSHAForPushEvent = async (
|
|||
})
|
||||
}
|
||||
|
||||
if (previousSha === currentSha) {
|
||||
if (!(await getParentSha({cwd: workingDirectory}))) {
|
||||
if (!previousSha || previousSha === currentSha) {
|
||||
previousSha = await getParentSha({
|
||||
cwd: workingDirectory
|
||||
})
|
||||
|
||||
if (!previousSha) {
|
||||
core.warning('Initial commit detected no previous commit found.')
|
||||
initialCommit = true
|
||||
previousSha = currentSha
|
||||
} else {
|
||||
previousSha = await getParentSha({
|
||||
cwd: workingDirectory
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (!previousSha) {
|
||||
core.error('Unable to locate a previous commit.')
|
||||
throw new Error('Unable to locate a previous commit.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +237,8 @@ export const getSHAForPushEvent = async (
|
|||
currentSha,
|
||||
currentBranch,
|
||||
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(
|
||||
`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> => {
|
||||
const {stdout} = await exec.getExecOutput(
|
||||
const {stdout, exitCode} = await exec.getExecOutput(
|
||||
'git',
|
||||
['rev-list', '-n', '1', 'HEAD^'],
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: process.env.RUNNER_DEBUG !== '1'
|
||||
}
|
||||
)
|
||||
|
||||
if (exitCode !== 0) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return stdout.trim()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue