Compare commits

...

2 Commits

Author SHA1 Message Date
Tonye Jack
9ad1a5b96a fix: error detecting initial commits (#1181)
Co-authored-by: GitHub Action <action@github.com>
2023-05-26 10:48:32 -06:00
tj-actions[bot]
88fb02bd31 Upgraded to v36.0.4 (#1180)
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
2023-05-26 15:20:16 +00:00
6 changed files with 55 additions and 29 deletions

View File

@@ -1,5 +1,21 @@
# Changelog
# [36.0.4](https://github.com/tj-actions/changed-files/compare/v36.0.3...v36.0.4) - (2023-05-26)
## <!-- 1 -->🐛 Bug Fixes
- Bug not using the path for source file inputs ([#1179](https://github.com/tj-actions/changed-files/issues/1179)) ([c798a4e](https://github.com/tj-actions/changed-files/commit/c798a4ea57f0e0a9d2b5374853c9c479ebb435a2)) - (Tonye Jack)
## <!-- 7 -->⚙️ Miscellaneous Tasks
- **deps:** Lock file maintenance ([#1178](https://github.com/tj-actions/changed-files/issues/1178)) ([e82d391](https://github.com/tj-actions/changed-files/commit/e82d3911ce25632baf10067a87543332d022f6f3)) - (renovate[bot])
## <!-- 9 -->⬆️ Upgrades
- Upgraded to v36.0.3 ([#1177](https://github.com/tj-actions/changed-files/issues/1177))
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([de2b6e4](https://github.com/tj-actions/changed-files/commit/de2b6e43f70bc5ad965dd5e8db9d437c1496b8e0)) - (tj-actions[bot])
# [36.0.3](https://github.com/tj-actions/changed-files/compare/v36.0.2...v36.0.3) - (2023-05-26)
## <!-- 1 -->🐛 Bug Fixes

32
dist/index.js generated vendored
View File

@@ -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

File diff suppressed because one or more lines are too long

View File

@@ -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
}
}

View File

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

View File

@@ -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()
}