mirror of
https://github.com/tj-actions/changed-files
synced 2025-02-06 09:41:22 +00:00
feat: add support for failing on error (#1511)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
2f6d66af9d
commit
f1b3c2fa8b
7 changed files with 83 additions and 11 deletions
|
@ -188,6 +188,14 @@ inputs:
|
||||||
description: "Github API URL."
|
description: "Github API URL."
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.api_url }}
|
default: ${{ github.api_url }}
|
||||||
|
fail_on_initial_diff_error:
|
||||||
|
description: "Fail when the initial diff fails."
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
|
fail_on_submodule_diff_error:
|
||||||
|
description: "Fail when the submodule diff fails."
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
added_files:
|
added_files:
|
||||||
|
|
32
dist/index.js
generated
vendored
32
dist/index.js
generated
vendored
|
@ -125,13 +125,14 @@ var ChangeTypeEnum;
|
||||||
ChangeTypeEnum["Unmerged"] = "U";
|
ChangeTypeEnum["Unmerged"] = "U";
|
||||||
ChangeTypeEnum["Unknown"] = "X";
|
ChangeTypeEnum["Unknown"] = "X";
|
||||||
})(ChangeTypeEnum || (exports.ChangeTypeEnum = ChangeTypeEnum = {}));
|
})(ChangeTypeEnum || (exports.ChangeTypeEnum = ChangeTypeEnum = {}));
|
||||||
const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodulePaths, outputRenamedFilesAsDeletedAndAdded, fetchSubmoduleHistory }) => __awaiter(void 0, void 0, void 0, function* () {
|
const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodulePaths, outputRenamedFilesAsDeletedAndAdded, fetchSubmoduleHistory, failOnInitialDiffError, failOnSubmoduleDiffError }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const files = yield (0, utils_1.getAllChangedFiles)({
|
const files = yield (0, utils_1.getAllChangedFiles)({
|
||||||
cwd: workingDirectory,
|
cwd: workingDirectory,
|
||||||
sha1: diffResult.previousSha,
|
sha1: diffResult.previousSha,
|
||||||
sha2: diffResult.currentSha,
|
sha2: diffResult.currentSha,
|
||||||
diff: diffResult.diff,
|
diff: diffResult.diff,
|
||||||
outputRenamedFilesAsDeletedAndAdded
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
|
failOnInitialDiffError
|
||||||
});
|
});
|
||||||
if (hasSubmodule) {
|
if (hasSubmodule) {
|
||||||
for (const submodulePath of submodulePaths) {
|
for (const submodulePath of submodulePaths) {
|
||||||
|
@ -165,7 +166,8 @@ const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodule
|
||||||
diff,
|
diff,
|
||||||
isSubmodule: true,
|
isSubmodule: true,
|
||||||
parentDir: submodulePath,
|
parentDir: submodulePath,
|
||||||
outputRenamedFilesAsDeletedAndAdded
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
|
failOnSubmoduleDiffError
|
||||||
});
|
});
|
||||||
for (const changeType of Object.keys(submoduleFiles)) {
|
for (const changeType of Object.keys(submoduleFiles)) {
|
||||||
if (!files[changeType]) {
|
if (!files[changeType]) {
|
||||||
|
@ -1331,6 +1333,12 @@ const getInputs = () => {
|
||||||
const fetchSubmoduleHistory = core.getBooleanInput('fetch_additional_submodule_history', {
|
const fetchSubmoduleHistory = core.getBooleanInput('fetch_additional_submodule_history', {
|
||||||
required: false
|
required: false
|
||||||
});
|
});
|
||||||
|
const failOnInitialDiffError = core.getBooleanInput('fail_on_initial_diff_error', {
|
||||||
|
required: false
|
||||||
|
});
|
||||||
|
const failOnSubmoduleDiffError = core.getBooleanInput('fail_on_submodule_diff_error', {
|
||||||
|
required: false
|
||||||
|
});
|
||||||
const inputs = {
|
const inputs = {
|
||||||
files,
|
files,
|
||||||
filesSeparator,
|
filesSeparator,
|
||||||
|
@ -1346,6 +1354,8 @@ const getInputs = () => {
|
||||||
filesIgnoreYaml,
|
filesIgnoreYaml,
|
||||||
filesIgnoreYamlFromSourceFile,
|
filesIgnoreYamlFromSourceFile,
|
||||||
filesIgnoreYamlFromSourceFileSeparator,
|
filesIgnoreYamlFromSourceFileSeparator,
|
||||||
|
failOnInitialDiffError,
|
||||||
|
failOnSubmoduleDiffError,
|
||||||
separator,
|
separator,
|
||||||
// Not Supported via REST API
|
// Not Supported via REST API
|
||||||
sha,
|
sha,
|
||||||
|
@ -1541,7 +1551,9 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
|
||||||
diffResult,
|
diffResult,
|
||||||
submodulePaths,
|
submodulePaths,
|
||||||
outputRenamedFilesAsDeletedAndAdded,
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
fetchSubmoduleHistory: inputs.fetchSubmoduleHistory
|
fetchSubmoduleHistory: inputs.fetchSubmoduleHistory,
|
||||||
|
failOnInitialDiffError: inputs.failOnInitialDiffError,
|
||||||
|
failOnSubmoduleDiffError: inputs.failOnSubmoduleDiffError
|
||||||
});
|
});
|
||||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
||||||
core.info('All Done!');
|
core.info('All Done!');
|
||||||
|
@ -2114,8 +2126,10 @@ exports.gitRenamedFiles = gitRenamedFiles;
|
||||||
* @param isSubmodule - is the repo a submodule
|
* @param isSubmodule - is the repo a submodule
|
||||||
* @param parentDir - parent directory of the submodule
|
* @param parentDir - parent directory of the submodule
|
||||||
* @param outputRenamedFilesAsDeletedAndAdded - output renamed files as deleted and added
|
* @param outputRenamedFilesAsDeletedAndAdded - output renamed files as deleted and added
|
||||||
|
* @param failOnInitialDiffError - fail if the initial diff fails
|
||||||
|
* @param failOnSubmoduleDiffError - fail if the submodule diff fails
|
||||||
*/
|
*/
|
||||||
const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parentDir = '', outputRenamedFilesAsDeletedAndAdded = false }) => __awaiter(void 0, void 0, void 0, function* () {
|
const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parentDir = '', outputRenamedFilesAsDeletedAndAdded = false, failOnInitialDiffError = false, failOnSubmoduleDiffError = false }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', [
|
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', [
|
||||||
'diff',
|
'diff',
|
||||||
'--name-status',
|
'--name-status',
|
||||||
|
@ -2137,6 +2151,14 @@ const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parent
|
||||||
[changedFiles_1.ChangeTypeEnum.Unmerged]: [],
|
[changedFiles_1.ChangeTypeEnum.Unmerged]: [],
|
||||||
[changedFiles_1.ChangeTypeEnum.Unknown]: []
|
[changedFiles_1.ChangeTypeEnum.Unknown]: []
|
||||||
};
|
};
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
if (failOnInitialDiffError && !isSubmodule) {
|
||||||
|
throw new Error(`Failed to get changed files between: ${sha1}${diff}${sha2}: ${stderr}`);
|
||||||
|
}
|
||||||
|
else if (failOnSubmoduleDiffError && isSubmodule) {
|
||||||
|
throw new Error(`Failed to get changed files for submodule between: ${sha1}${diff}${sha2}: ${stderr}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
if (isSubmodule) {
|
if (isSubmodule) {
|
||||||
core.warning(stderr ||
|
core.warning(stderr ||
|
||||||
|
|
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
|
@ -121,7 +121,9 @@ export const getAllDiffFiles = async ({
|
||||||
diffResult,
|
diffResult,
|
||||||
submodulePaths,
|
submodulePaths,
|
||||||
outputRenamedFilesAsDeletedAndAdded,
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
fetchSubmoduleHistory
|
fetchSubmoduleHistory,
|
||||||
|
failOnInitialDiffError,
|
||||||
|
failOnSubmoduleDiffError
|
||||||
}: {
|
}: {
|
||||||
workingDirectory: string
|
workingDirectory: string
|
||||||
hasSubmodule: boolean
|
hasSubmodule: boolean
|
||||||
|
@ -129,13 +131,16 @@ export const getAllDiffFiles = async ({
|
||||||
submodulePaths: string[]
|
submodulePaths: string[]
|
||||||
outputRenamedFilesAsDeletedAndAdded: boolean
|
outputRenamedFilesAsDeletedAndAdded: boolean
|
||||||
fetchSubmoduleHistory: boolean
|
fetchSubmoduleHistory: boolean
|
||||||
|
failOnInitialDiffError: boolean
|
||||||
|
failOnSubmoduleDiffError: boolean
|
||||||
}): Promise<ChangedFiles> => {
|
}): Promise<ChangedFiles> => {
|
||||||
const files = await getAllChangedFiles({
|
const files = await getAllChangedFiles({
|
||||||
cwd: workingDirectory,
|
cwd: workingDirectory,
|
||||||
sha1: diffResult.previousSha,
|
sha1: diffResult.previousSha,
|
||||||
sha2: diffResult.currentSha,
|
sha2: diffResult.currentSha,
|
||||||
diff: diffResult.diff,
|
diff: diffResult.diff,
|
||||||
outputRenamedFilesAsDeletedAndAdded
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
|
failOnInitialDiffError
|
||||||
})
|
})
|
||||||
|
|
||||||
if (hasSubmodule) {
|
if (hasSubmodule) {
|
||||||
|
@ -179,7 +184,8 @@ export const getAllDiffFiles = async ({
|
||||||
diff,
|
diff,
|
||||||
isSubmodule: true,
|
isSubmodule: true,
|
||||||
parentDir: submodulePath,
|
parentDir: submodulePath,
|
||||||
outputRenamedFilesAsDeletedAndAdded
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
|
failOnSubmoduleDiffError
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const changeType of Object.keys(
|
for (const changeType of Object.keys(
|
||||||
|
|
|
@ -48,6 +48,8 @@ export type Inputs = {
|
||||||
token: string
|
token: string
|
||||||
apiUrl: string
|
apiUrl: string
|
||||||
skipInitialFetch: boolean
|
skipInitialFetch: boolean
|
||||||
|
failOnInitialDiffError: boolean
|
||||||
|
failOnSubmoduleDiffError: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getInputs = (): Inputs => {
|
export const getInputs = (): Inputs => {
|
||||||
|
@ -196,6 +198,18 @@ export const getInputs = (): Inputs => {
|
||||||
required: false
|
required: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
const failOnInitialDiffError = core.getBooleanInput(
|
||||||
|
'fail_on_initial_diff_error',
|
||||||
|
{
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const failOnSubmoduleDiffError = core.getBooleanInput(
|
||||||
|
'fail_on_submodule_diff_error',
|
||||||
|
{
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const inputs: Inputs = {
|
const inputs: Inputs = {
|
||||||
files,
|
files,
|
||||||
|
@ -212,6 +226,8 @@ export const getInputs = (): Inputs => {
|
||||||
filesIgnoreYaml,
|
filesIgnoreYaml,
|
||||||
filesIgnoreYamlFromSourceFile,
|
filesIgnoreYamlFromSourceFile,
|
||||||
filesIgnoreYamlFromSourceFileSeparator,
|
filesIgnoreYamlFromSourceFileSeparator,
|
||||||
|
failOnInitialDiffError,
|
||||||
|
failOnSubmoduleDiffError,
|
||||||
separator,
|
separator,
|
||||||
// Not Supported via REST API
|
// Not Supported via REST API
|
||||||
sha,
|
sha,
|
||||||
|
|
|
@ -191,7 +191,9 @@ const getChangedFilesFromLocalGit = async ({
|
||||||
diffResult,
|
diffResult,
|
||||||
submodulePaths,
|
submodulePaths,
|
||||||
outputRenamedFilesAsDeletedAndAdded,
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
fetchSubmoduleHistory: inputs.fetchSubmoduleHistory
|
fetchSubmoduleHistory: inputs.fetchSubmoduleHistory,
|
||||||
|
failOnInitialDiffError: inputs.failOnInitialDiffError,
|
||||||
|
failOnSubmoduleDiffError: inputs.failOnSubmoduleDiffError
|
||||||
})
|
})
|
||||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
|
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
|
||||||
core.info('All Done!')
|
core.info('All Done!')
|
||||||
|
|
20
src/utils.ts
20
src/utils.ts
|
@ -490,6 +490,8 @@ export const gitRenamedFiles = async ({
|
||||||
* @param isSubmodule - is the repo a submodule
|
* @param isSubmodule - is the repo a submodule
|
||||||
* @param parentDir - parent directory of the submodule
|
* @param parentDir - parent directory of the submodule
|
||||||
* @param outputRenamedFilesAsDeletedAndAdded - output renamed files as deleted and added
|
* @param outputRenamedFilesAsDeletedAndAdded - output renamed files as deleted and added
|
||||||
|
* @param failOnInitialDiffError - fail if the initial diff fails
|
||||||
|
* @param failOnSubmoduleDiffError - fail if the submodule diff fails
|
||||||
*/
|
*/
|
||||||
export const getAllChangedFiles = async ({
|
export const getAllChangedFiles = async ({
|
||||||
cwd,
|
cwd,
|
||||||
|
@ -498,7 +500,9 @@ export const getAllChangedFiles = async ({
|
||||||
diff,
|
diff,
|
||||||
isSubmodule = false,
|
isSubmodule = false,
|
||||||
parentDir = '',
|
parentDir = '',
|
||||||
outputRenamedFilesAsDeletedAndAdded = false
|
outputRenamedFilesAsDeletedAndAdded = false,
|
||||||
|
failOnInitialDiffError = false,
|
||||||
|
failOnSubmoduleDiffError = false
|
||||||
}: {
|
}: {
|
||||||
cwd: string
|
cwd: string
|
||||||
sha1: string
|
sha1: string
|
||||||
|
@ -507,6 +511,8 @@ export const getAllChangedFiles = async ({
|
||||||
isSubmodule?: boolean
|
isSubmodule?: boolean
|
||||||
parentDir?: string
|
parentDir?: string
|
||||||
outputRenamedFilesAsDeletedAndAdded?: boolean
|
outputRenamedFilesAsDeletedAndAdded?: boolean
|
||||||
|
failOnInitialDiffError?: boolean
|
||||||
|
failOnSubmoduleDiffError?: boolean
|
||||||
}): Promise<ChangedFiles> => {
|
}): Promise<ChangedFiles> => {
|
||||||
const {exitCode, stdout, stderr} = await exec.getExecOutput(
|
const {exitCode, stdout, stderr} = await exec.getExecOutput(
|
||||||
'git',
|
'git',
|
||||||
|
@ -534,6 +540,18 @@ export const getAllChangedFiles = async ({
|
||||||
[ChangeTypeEnum.Unknown]: []
|
[ChangeTypeEnum.Unknown]: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
if (failOnInitialDiffError && !isSubmodule) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to get changed files between: ${sha1}${diff}${sha2}: ${stderr}`
|
||||||
|
)
|
||||||
|
} else if (failOnSubmoduleDiffError && isSubmodule) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to get changed files for submodule between: ${sha1}${diff}${sha2}: ${stderr}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
if (isSubmodule) {
|
if (isSubmodule) {
|
||||||
core.warning(
|
core.warning(
|
||||||
|
|
Loading…
Add table
Reference in a new issue