3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-02-06 09:41:22 +00:00

fix: bug with outputs when json is set to true (#1531)

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
Tonye Jack 2023-09-04 14:03:32 -06:00 committed by GitHub
parent fd460fa3ba
commit 8d335b7b7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 362 additions and 150 deletions

View file

@ -1029,7 +1029,8 @@ jobs:
if: | if: |
( (
!contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test/test rename-1.txt') || !contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test/test rename-1.txt') ||
!contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test') !contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test') ||
steps.changed-files-dir-names-specific-include-files.outputs.any_changed == 'false'
) && runner.os != 'Windows' ) && runner.os != 'Windows'
run: | run: |
echo "Invalid output: Expected to include (test/test rename-1.txt) and (test) got (${{ steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files }})" echo "Invalid output: Expected to include (test/test rename-1.txt) and (test) got (${{ steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files }})"
@ -1040,13 +1041,41 @@ jobs:
if: | if: |
( (
!contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test\\test rename-1.txt') || !contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test\\test rename-1.txt') ||
!contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test') !contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test') ||
steps.changed-files-dir-names-specific-include-files.outputs.any_changed == 'false'
) && runner.os == 'Windows' ) && runner.os == 'Windows'
run: | run: |
echo "Invalid output: Expected to include (test\\test rename-1.txt) and (test) got (${{ steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files }})" echo "Invalid output: Expected to include (test\\test rename-1.txt) and (test) got (${{ steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files }})"
exit 1 exit 1
shell: shell:
bash bash
- name: Run changed-files with dir_names for specific files and an unmatched path
id: changed-files-dir-names-specific-unmatched-path
uses: ./
with:
base_sha: d1c0ee4
sha: 4d04215
fetch_depth: 60000
dir_names: true
files: unknown/**
json: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-dir-names-specific-unmatched-path.outputs) }}'
shell:
bash
- name: Check dir_names output
if: |
(
steps.changed-files-dir-names-specific-unmatched-path.outputs.all_changed_files != '[]' ||
steps.changed-files-dir-names-specific-unmatched-path.outputs.any_changed == 'true' ||
steps.changed-files-dir-names-specific-unmatched-path.outputs.all_changed_files_count != '0'
)
run: |
echo "Invalid output: Expected empty array and any_changed to be false got (${{ steps.changed-files-dir-names-specific-unmatched-path.outputs.all_changed_files }}) and (${{ steps.changed-files-dir-names-specific-unmatched-path.outputs.any_changed }})"
exit 1
shell:
bash
- name: Run changed-files with forward slash separator - name: Run changed-files with forward slash separator
id: changed-files-forward-slash id: changed-files-forward-slash
uses: ./ uses: ./

210
dist/index.js generated vendored
View file

@ -220,14 +220,9 @@ const getChangeTypeFiles = ({ inputs, changedFiles, changeTypes }) => __awaiter(
const files = [ const files = [
...new Set(getChangeTypeFilesGenerator({ inputs, changedFiles, changeTypes })) ...new Set(getChangeTypeFilesGenerator({ inputs, changedFiles, changeTypes }))
].filter(Boolean); ].filter(Boolean);
if (inputs.json) { const paths = inputs.json ? files : files.join(inputs.separator);
return { return {
paths: (0, utils_1.jsonOutput)({ value: files, shouldEscape: inputs.escapeJson }), paths,
count: files.length.toString()
};
}
return {
paths: files.join(inputs.separator),
count: files.length.toString() count: files.length.toString()
}; };
}); });
@ -248,14 +243,9 @@ const getAllChangeTypeFiles = ({ inputs, changedFiles }) => __awaiter(void 0, vo
const files = [ const files = [
...new Set(getAllChangeTypeFilesGenerator({ inputs, changedFiles })) ...new Set(getAllChangeTypeFilesGenerator({ inputs, changedFiles }))
].filter(Boolean); ].filter(Boolean);
if (inputs.json) { const paths = inputs.json ? files : files.join(inputs.separator);
return { return {
paths: (0, utils_1.jsonOutput)({ value: files, shouldEscape: inputs.escapeJson }), paths,
count: files.length.toString()
};
}
return {
paths: files.join(inputs.separator),
count: files.length.toString() count: files.length.toString()
}; };
}); });
@ -373,6 +363,9 @@ const utils_1 = __nccwpck_require__(918);
const getOutputKey = (key, outputPrefix) => { const getOutputKey = (key, outputPrefix) => {
return outputPrefix ? `${outputPrefix}_${key}` : key; return outputPrefix ? `${outputPrefix}_${key}` : key;
}; };
const getArrayFromPaths = (paths, inputs) => {
return Array.isArray(paths) ? paths : paths.split(inputs.separator);
};
const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () { const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () {
const addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -383,12 +376,16 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('added_files', outputPrefix), key: getOutputKey('added_files', outputPrefix),
value: addedFiles.paths, value: addedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('added_files_count', outputPrefix), key: getOutputKey('added_files_count', outputPrefix),
value: addedFiles.count, value: addedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const copiedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const copiedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -399,12 +396,16 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('copied_files', outputPrefix), key: getOutputKey('copied_files', outputPrefix),
value: copiedFiles.paths, value: copiedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('copied_files_count', outputPrefix), key: getOutputKey('copied_files_count', outputPrefix),
value: copiedFiles.count, value: copiedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const modifiedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const modifiedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -415,12 +416,16 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('modified_files', outputPrefix), key: getOutputKey('modified_files', outputPrefix),
value: modifiedFiles.paths, value: modifiedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('modified_files_count', outputPrefix), key: getOutputKey('modified_files_count', outputPrefix),
value: modifiedFiles.count, value: modifiedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const renamedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const renamedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -431,12 +436,16 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('renamed_files', outputPrefix), key: getOutputKey('renamed_files', outputPrefix),
value: renamedFiles.paths, value: renamedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('renamed_files_count', outputPrefix), key: getOutputKey('renamed_files_count', outputPrefix),
value: renamedFiles.count, value: renamedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const typeChangedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const typeChangedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -447,12 +456,16 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('type_changed_files', outputPrefix), key: getOutputKey('type_changed_files', outputPrefix),
value: typeChangedFiles.paths, value: typeChangedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('type_changed_files_count', outputPrefix), key: getOutputKey('type_changed_files_count', outputPrefix),
value: typeChangedFiles.count, value: typeChangedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const unmergedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const unmergedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -463,12 +476,16 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('unmerged_files', outputPrefix), key: getOutputKey('unmerged_files', outputPrefix),
value: unmergedFiles.paths, value: unmergedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('unmerged_files_count', outputPrefix), key: getOutputKey('unmerged_files_count', outputPrefix),
value: unmergedFiles.count, value: unmergedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const unknownFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const unknownFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -479,12 +496,16 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('unknown_files', outputPrefix), key: getOutputKey('unknown_files', outputPrefix),
value: unknownFiles.paths, value: unknownFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('unknown_files_count', outputPrefix), key: getOutputKey('unknown_files_count', outputPrefix),
value: unknownFiles.count, value: unknownFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const allChangedAndModifiedFiles = yield (0, changedFiles_1.getAllChangeTypeFiles)({ const allChangedAndModifiedFiles = yield (0, changedFiles_1.getAllChangeTypeFiles)({
inputs, inputs,
@ -494,12 +515,16 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('all_changed_and_modified_files', outputPrefix), key: getOutputKey('all_changed_and_modified_files', outputPrefix),
value: allChangedAndModifiedFiles.paths, value: allChangedAndModifiedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('all_changed_and_modified_files_count', outputPrefix), key: getOutputKey('all_changed_and_modified_files_count', outputPrefix),
value: allChangedAndModifiedFiles.count, value: allChangedAndModifiedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const allChangedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const allChangedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -515,17 +540,23 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('all_changed_files', outputPrefix), key: getOutputKey('all_changed_files', outputPrefix),
value: allChangedFiles.paths, value: allChangedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('all_changed_files_count', outputPrefix), key: getOutputKey('all_changed_files_count', outputPrefix),
value: allChangedFiles.count, value: allChangedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('any_changed', outputPrefix), key: getOutputKey('any_changed', outputPrefix),
value: allChangedFiles.paths.length > 0 && filePatterns.length > 0, value: allChangedFiles.paths.length > 0 && filePatterns.length > 0,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}); });
const allOtherChangedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const allOtherChangedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -538,26 +569,34 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
] ]
}); });
core.debug(`All other changed files: ${JSON.stringify(allOtherChangedFiles)}`); core.debug(`All other changed files: ${JSON.stringify(allOtherChangedFiles)}`);
const otherChangedFiles = allOtherChangedFiles.paths const allOtherChangedFilesPaths = getArrayFromPaths(allOtherChangedFiles.paths, inputs);
.split(inputs.separator) const allChangedFilesPaths = getArrayFromPaths(allChangedFiles.paths, inputs);
.filter((filePath) => !allChangedFiles.paths.split(inputs.separator).includes(filePath)); const otherChangedFiles = allOtherChangedFilesPaths.filter((filePath) => !allChangedFilesPaths.includes(filePath));
const onlyChanged = otherChangedFiles.length === 0 && const onlyChanged = otherChangedFiles.length === 0 &&
allChangedFiles.paths.length > 0 && allChangedFiles.paths.length > 0 &&
filePatterns.length > 0; filePatterns.length > 0;
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('only_changed', outputPrefix), key: getOutputKey('only_changed', outputPrefix),
value: onlyChanged, value: onlyChanged,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('other_changed_files', outputPrefix), key: getOutputKey('other_changed_files', outputPrefix),
value: otherChangedFiles.join(inputs.separator), value: inputs.json
inputs ? otherChangedFiles
: otherChangedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('other_changed_files_count', outputPrefix), key: getOutputKey('other_changed_files_count', outputPrefix),
value: otherChangedFiles.length.toString(), value: otherChangedFiles.length.toString(),
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const allModifiedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const allModifiedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -574,17 +613,23 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('all_modified_files', outputPrefix), key: getOutputKey('all_modified_files', outputPrefix),
value: allModifiedFiles.paths, value: allModifiedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('all_modified_files_count', outputPrefix), key: getOutputKey('all_modified_files_count', outputPrefix),
value: allModifiedFiles.count, value: allModifiedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('any_modified', outputPrefix), key: getOutputKey('any_modified', outputPrefix),
value: allModifiedFiles.paths.length > 0 && filePatterns.length > 0, value: allModifiedFiles.paths.length > 0 && filePatterns.length > 0,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}); });
const allOtherModifiedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const allOtherModifiedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -597,26 +642,34 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
changedFiles_1.ChangeTypeEnum.Deleted changedFiles_1.ChangeTypeEnum.Deleted
] ]
}); });
const otherModifiedFiles = allOtherModifiedFiles.paths const allOtherModifiedFilesPaths = getArrayFromPaths(allOtherModifiedFiles.paths, inputs);
.split(inputs.separator) const allModifiedFilesPaths = getArrayFromPaths(allModifiedFiles.paths, inputs);
.filter((filePath) => !allModifiedFiles.paths.split(inputs.separator).includes(filePath)); const otherModifiedFiles = allOtherModifiedFilesPaths.filter((filePath) => !allModifiedFilesPaths.includes(filePath));
const onlyModified = otherModifiedFiles.length === 0 && const onlyModified = otherModifiedFiles.length === 0 &&
allModifiedFiles.paths.length > 0 && allModifiedFiles.paths.length > 0 &&
filePatterns.length > 0; filePatterns.length > 0;
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('only_modified', outputPrefix), key: getOutputKey('only_modified', outputPrefix),
value: onlyModified, value: onlyModified,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('other_modified_files', outputPrefix), key: getOutputKey('other_modified_files', outputPrefix),
value: otherModifiedFiles.join(inputs.separator), value: inputs.json
inputs ? otherModifiedFiles
: otherModifiedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('other_modified_files_count', outputPrefix), key: getOutputKey('other_modified_files_count', outputPrefix),
value: otherModifiedFiles.length.toString(), value: otherModifiedFiles.length.toString(),
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
const deletedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const deletedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
@ -627,43 +680,57 @@ const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, fil
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('deleted_files', outputPrefix), key: getOutputKey('deleted_files', outputPrefix),
value: deletedFiles.paths, value: deletedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('deleted_files_count', outputPrefix), key: getOutputKey('deleted_files_count', outputPrefix),
value: deletedFiles.count, value: deletedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('any_deleted', outputPrefix), key: getOutputKey('any_deleted', outputPrefix),
value: deletedFiles.paths.length > 0 && filePatterns.length > 0, value: deletedFiles.paths.length > 0 && filePatterns.length > 0,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}); });
const allOtherDeletedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({ const allOtherDeletedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs, inputs,
changedFiles: allDiffFiles, changedFiles: allDiffFiles,
changeTypes: [changedFiles_1.ChangeTypeEnum.Deleted] changeTypes: [changedFiles_1.ChangeTypeEnum.Deleted]
}); });
const otherDeletedFiles = allOtherDeletedFiles.paths const allOtherDeletedFilesPaths = getArrayFromPaths(allOtherDeletedFiles.paths, inputs);
.split(inputs.separator) const deletedFilesPaths = getArrayFromPaths(deletedFiles.paths, inputs);
.filter(filePath => !deletedFiles.paths.split(inputs.separator).includes(filePath)); const otherDeletedFiles = allOtherDeletedFilesPaths.filter(filePath => !deletedFilesPaths.includes(filePath));
const onlyDeleted = otherDeletedFiles.length === 0 && const onlyDeleted = otherDeletedFiles.length === 0 &&
deletedFiles.paths.length > 0 && deletedFiles.paths.length > 0 &&
filePatterns.length > 0; filePatterns.length > 0;
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('only_deleted', outputPrefix), key: getOutputKey('only_deleted', outputPrefix),
value: onlyDeleted, value: onlyDeleted,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('other_deleted_files', outputPrefix), key: getOutputKey('other_deleted_files', outputPrefix),
value: otherDeletedFiles.join(inputs.separator), value: inputs.json
inputs ? otherDeletedFiles
: otherDeletedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: getOutputKey('other_deleted_files_count', outputPrefix), key: getOutputKey('other_deleted_files_count', outputPrefix),
value: otherDeletedFiles.length.toString(), value: otherDeletedFiles.length.toString(),
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}); });
}); });
exports.setChangedFilesOutput = setChangedFilesOutput; exports.setChangedFilesOutput = setChangedFilesOutput;
@ -1597,12 +1664,16 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: 'all_old_new_renamed_files', key: 'all_old_new_renamed_files',
value: allOldNewRenamedFiles.paths, value: allOldNewRenamedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}); });
yield (0, utils_1.setOutput)({ yield (0, utils_1.setOutput)({
key: 'all_old_new_renamed_files_count', key: 'all_old_new_renamed_files_count',
value: allOldNewRenamedFiles.count, value: allOldNewRenamedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}); });
core.info('All Done!'); core.info('All Done!');
core.endGroup(); core.endGroup();
@ -2582,12 +2653,17 @@ const getRecoverFilePatterns = ({ inputs }) => {
return filePatterns.filter(Boolean); return filePatterns.filter(Boolean);
}; };
exports.getRecoverFilePatterns = getRecoverFilePatterns; exports.getRecoverFilePatterns = getRecoverFilePatterns;
const setOutput = ({ key, value, inputs }) => __awaiter(void 0, void 0, void 0, function* () { const setOutput = ({ key, value, writeOutputFiles, outputDir, json = false, shouldEscape = false }) => __awaiter(void 0, void 0, void 0, function* () {
const cleanedValue = value.toString().trim(); let cleanedValue;
if (json) {
cleanedValue = (0, exports.jsonOutput)({ value, shouldEscape });
}
else {
cleanedValue = value.toString().trim();
}
core.setOutput(key, cleanedValue); core.setOutput(key, cleanedValue);
if (inputs.writeOutputFiles) { if (writeOutputFiles) {
const outputDir = inputs.outputDir; const extension = json ? 'json' : 'txt';
const extension = inputs.json ? 'json' : 'txt';
const outputFilePath = path.join(outputDir, `${key}.${extension}`); const outputFilePath = path.join(outputDir, `${key}.${extension}`);
if (!(yield exists(outputDir))) { if (!(yield exists(outputDir))) {
yield fs_1.promises.mkdir(outputDir, { recursive: true }); yield fs_1.promises.mkdir(outputDir, { recursive: true });

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -268,20 +268,15 @@ export const getChangeTypeFiles = async ({
inputs: Inputs inputs: Inputs
changedFiles: ChangedFiles changedFiles: ChangedFiles
changeTypes: ChangeTypeEnum[] changeTypes: ChangeTypeEnum[]
}): Promise<{paths: string; count: string}> => { }): Promise<{paths: string[] | string; count: string}> => {
const files = [ const files = [
...new Set(getChangeTypeFilesGenerator({inputs, changedFiles, changeTypes})) ...new Set(getChangeTypeFilesGenerator({inputs, changedFiles, changeTypes}))
].filter(Boolean) ].filter(Boolean)
if (inputs.json) { const paths = inputs.json ? files : files.join(inputs.separator)
return {
paths: jsonOutput({value: files, shouldEscape: inputs.escapeJson}),
count: files.length.toString()
}
}
return { return {
paths: files.join(inputs.separator), paths,
count: files.length.toString() count: files.length.toString()
} }
} }
@ -317,20 +312,15 @@ export const getAllChangeTypeFiles = async ({
}: { }: {
inputs: Inputs inputs: Inputs
changedFiles: ChangedFiles changedFiles: ChangedFiles
}): Promise<{paths: string; count: string}> => { }): Promise<{paths: string[] | string; count: string}> => {
const files = [ const files = [
...new Set(getAllChangeTypeFilesGenerator({inputs, changedFiles})) ...new Set(getAllChangeTypeFilesGenerator({inputs, changedFiles}))
].filter(Boolean) ].filter(Boolean)
if (inputs.json) { const paths = inputs.json ? files : files.join(inputs.separator)
return {
paths: jsonOutput({value: files, shouldEscape: inputs.escapeJson}),
count: files.length.toString()
}
}
return { return {
paths: files.join(inputs.separator), paths,
count: files.length.toString() count: files.length.toString()
} }
} }

View file

@ -12,6 +12,13 @@ const getOutputKey = (key: string, outputPrefix: string): string => {
return outputPrefix ? `${outputPrefix}_${key}` : key return outputPrefix ? `${outputPrefix}_${key}` : key
} }
const getArrayFromPaths = (
paths: string | string[],
inputs: Inputs
): string[] => {
return Array.isArray(paths) ? paths : paths.split(inputs.separator)
}
export const setChangedFilesOutput = async ({ export const setChangedFilesOutput = async ({
allDiffFiles, allDiffFiles,
allFilteredDiffFiles, allFilteredDiffFiles,
@ -34,12 +41,16 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('added_files', outputPrefix), key: getOutputKey('added_files', outputPrefix),
value: addedFiles.paths, value: addedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('added_files_count', outputPrefix), key: getOutputKey('added_files_count', outputPrefix),
value: addedFiles.count, value: addedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const copiedFiles = await getChangeTypeFiles({ const copiedFiles = await getChangeTypeFiles({
@ -51,13 +62,17 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('copied_files', outputPrefix), key: getOutputKey('copied_files', outputPrefix),
value: copiedFiles.paths, value: copiedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('copied_files_count', outputPrefix), key: getOutputKey('copied_files_count', outputPrefix),
value: copiedFiles.count, value: copiedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const modifiedFiles = await getChangeTypeFiles({ const modifiedFiles = await getChangeTypeFiles({
@ -69,13 +84,17 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('modified_files', outputPrefix), key: getOutputKey('modified_files', outputPrefix),
value: modifiedFiles.paths, value: modifiedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('modified_files_count', outputPrefix), key: getOutputKey('modified_files_count', outputPrefix),
value: modifiedFiles.count, value: modifiedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const renamedFiles = await getChangeTypeFiles({ const renamedFiles = await getChangeTypeFiles({
@ -87,13 +106,17 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('renamed_files', outputPrefix), key: getOutputKey('renamed_files', outputPrefix),
value: renamedFiles.paths, value: renamedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('renamed_files_count', outputPrefix), key: getOutputKey('renamed_files_count', outputPrefix),
value: renamedFiles.count, value: renamedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const typeChangedFiles = await getChangeTypeFiles({ const typeChangedFiles = await getChangeTypeFiles({
@ -105,13 +128,17 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('type_changed_files', outputPrefix), key: getOutputKey('type_changed_files', outputPrefix),
value: typeChangedFiles.paths, value: typeChangedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('type_changed_files_count', outputPrefix), key: getOutputKey('type_changed_files_count', outputPrefix),
value: typeChangedFiles.count, value: typeChangedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const unmergedFiles = await getChangeTypeFiles({ const unmergedFiles = await getChangeTypeFiles({
@ -123,13 +150,17 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('unmerged_files', outputPrefix), key: getOutputKey('unmerged_files', outputPrefix),
value: unmergedFiles.paths, value: unmergedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('unmerged_files_count', outputPrefix), key: getOutputKey('unmerged_files_count', outputPrefix),
value: unmergedFiles.count, value: unmergedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const unknownFiles = await getChangeTypeFiles({ const unknownFiles = await getChangeTypeFiles({
@ -141,13 +172,17 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('unknown_files', outputPrefix), key: getOutputKey('unknown_files', outputPrefix),
value: unknownFiles.paths, value: unknownFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('unknown_files_count', outputPrefix), key: getOutputKey('unknown_files_count', outputPrefix),
value: unknownFiles.count, value: unknownFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const allChangedAndModifiedFiles = await getAllChangeTypeFiles({ const allChangedAndModifiedFiles = await getAllChangeTypeFiles({
@ -162,13 +197,17 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('all_changed_and_modified_files', outputPrefix), key: getOutputKey('all_changed_and_modified_files', outputPrefix),
value: allChangedAndModifiedFiles.paths, value: allChangedAndModifiedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('all_changed_and_modified_files_count', outputPrefix), key: getOutputKey('all_changed_and_modified_files_count', outputPrefix),
value: allChangedAndModifiedFiles.count, value: allChangedAndModifiedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const allChangedFiles = await getChangeTypeFiles({ const allChangedFiles = await getChangeTypeFiles({
@ -185,19 +224,25 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('all_changed_files', outputPrefix), key: getOutputKey('all_changed_files', outputPrefix),
value: allChangedFiles.paths, value: allChangedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('all_changed_files_count', outputPrefix), key: getOutputKey('all_changed_files_count', outputPrefix),
value: allChangedFiles.count, value: allChangedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
await setOutput({ await setOutput({
key: getOutputKey('any_changed', outputPrefix), key: getOutputKey('any_changed', outputPrefix),
value: allChangedFiles.paths.length > 0 && filePatterns.length > 0, value: allChangedFiles.paths.length > 0 && filePatterns.length > 0,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}) })
const allOtherChangedFiles = await getChangeTypeFiles({ const allOtherChangedFiles = await getChangeTypeFiles({
@ -212,11 +257,17 @@ export const setChangedFilesOutput = async ({
}) })
core.debug(`All other changed files: ${JSON.stringify(allOtherChangedFiles)}`) core.debug(`All other changed files: ${JSON.stringify(allOtherChangedFiles)}`)
const otherChangedFiles = allOtherChangedFiles.paths const allOtherChangedFilesPaths: string[] = getArrayFromPaths(
.split(inputs.separator) allOtherChangedFiles.paths,
.filter( inputs
(filePath: string) => )
!allChangedFiles.paths.split(inputs.separator).includes(filePath) const allChangedFilesPaths: string[] = getArrayFromPaths(
allChangedFiles.paths,
inputs
)
const otherChangedFiles = allOtherChangedFilesPaths.filter(
(filePath: string) => !allChangedFilesPaths.includes(filePath)
) )
const onlyChanged = const onlyChanged =
@ -227,19 +278,27 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('only_changed', outputPrefix), key: getOutputKey('only_changed', outputPrefix),
value: onlyChanged, value: onlyChanged,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}) })
await setOutput({ await setOutput({
key: getOutputKey('other_changed_files', outputPrefix), key: getOutputKey('other_changed_files', outputPrefix),
value: otherChangedFiles.join(inputs.separator), value: inputs.json
inputs ? otherChangedFiles
: otherChangedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('other_changed_files_count', outputPrefix), key: getOutputKey('other_changed_files_count', outputPrefix),
value: otherChangedFiles.length.toString(), value: otherChangedFiles.length.toString(),
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const allModifiedFiles = await getChangeTypeFiles({ const allModifiedFiles = await getChangeTypeFiles({
@ -257,19 +316,25 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('all_modified_files', outputPrefix), key: getOutputKey('all_modified_files', outputPrefix),
value: allModifiedFiles.paths, value: allModifiedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('all_modified_files_count', outputPrefix), key: getOutputKey('all_modified_files_count', outputPrefix),
value: allModifiedFiles.count, value: allModifiedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
await setOutput({ await setOutput({
key: getOutputKey('any_modified', outputPrefix), key: getOutputKey('any_modified', outputPrefix),
value: allModifiedFiles.paths.length > 0 && filePatterns.length > 0, value: allModifiedFiles.paths.length > 0 && filePatterns.length > 0,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}) })
const allOtherModifiedFiles = await getChangeTypeFiles({ const allOtherModifiedFiles = await getChangeTypeFiles({
@ -284,11 +349,18 @@ export const setChangedFilesOutput = async ({
] ]
}) })
const otherModifiedFiles = allOtherModifiedFiles.paths const allOtherModifiedFilesPaths: string[] = getArrayFromPaths(
.split(inputs.separator) allOtherModifiedFiles.paths,
.filter( inputs
(filePath: string) => )
!allModifiedFiles.paths.split(inputs.separator).includes(filePath)
const allModifiedFilesPaths: string[] = getArrayFromPaths(
allModifiedFiles.paths,
inputs
)
const otherModifiedFiles = allOtherModifiedFilesPaths.filter(
(filePath: string) => !allModifiedFilesPaths.includes(filePath)
) )
const onlyModified = const onlyModified =
@ -299,19 +371,27 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('only_modified', outputPrefix), key: getOutputKey('only_modified', outputPrefix),
value: onlyModified, value: onlyModified,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}) })
await setOutput({ await setOutput({
key: getOutputKey('other_modified_files', outputPrefix), key: getOutputKey('other_modified_files', outputPrefix),
value: otherModifiedFiles.join(inputs.separator), value: inputs.json
inputs ? otherModifiedFiles
: otherModifiedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('other_modified_files_count', outputPrefix), key: getOutputKey('other_modified_files_count', outputPrefix),
value: otherModifiedFiles.length.toString(), value: otherModifiedFiles.length.toString(),
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
const deletedFiles = await getChangeTypeFiles({ const deletedFiles = await getChangeTypeFiles({
@ -323,19 +403,25 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('deleted_files', outputPrefix), key: getOutputKey('deleted_files', outputPrefix),
value: deletedFiles.paths, value: deletedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('deleted_files_count', outputPrefix), key: getOutputKey('deleted_files_count', outputPrefix),
value: deletedFiles.count, value: deletedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
await setOutput({ await setOutput({
key: getOutputKey('any_deleted', outputPrefix), key: getOutputKey('any_deleted', outputPrefix),
value: deletedFiles.paths.length > 0 && filePatterns.length > 0, value: deletedFiles.paths.length > 0 && filePatterns.length > 0,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}) })
const allOtherDeletedFiles = await getChangeTypeFiles({ const allOtherDeletedFiles = await getChangeTypeFiles({
@ -344,10 +430,18 @@ export const setChangedFilesOutput = async ({
changeTypes: [ChangeTypeEnum.Deleted] changeTypes: [ChangeTypeEnum.Deleted]
}) })
const otherDeletedFiles = allOtherDeletedFiles.paths const allOtherDeletedFilesPaths: string[] = getArrayFromPaths(
.split(inputs.separator) allOtherDeletedFiles.paths,
.filter( inputs
filePath => !deletedFiles.paths.split(inputs.separator).includes(filePath) )
const deletedFilesPaths: string[] = getArrayFromPaths(
deletedFiles.paths,
inputs
)
const otherDeletedFiles = allOtherDeletedFilesPaths.filter(
filePath => !deletedFilesPaths.includes(filePath)
) )
const onlyDeleted = const onlyDeleted =
@ -358,18 +452,26 @@ export const setChangedFilesOutput = async ({
await setOutput({ await setOutput({
key: getOutputKey('only_deleted', outputPrefix), key: getOutputKey('only_deleted', outputPrefix),
value: onlyDeleted, value: onlyDeleted,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}) })
await setOutput({ await setOutput({
key: getOutputKey('other_deleted_files', outputPrefix), key: getOutputKey('other_deleted_files', outputPrefix),
value: otherDeletedFiles.join(inputs.separator), value: inputs.json
inputs ? otherDeletedFiles
: otherDeletedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
}) })
await setOutput({ await setOutput({
key: getOutputKey('other_deleted_files_count', outputPrefix), key: getOutputKey('other_deleted_files_count', outputPrefix),
value: otherDeletedFiles.length.toString(), value: otherDeletedFiles.length.toString(),
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir
}) })
} }

View file

@ -236,12 +236,16 @@ const getChangedFilesFromLocalGit = async ({
await setOutput({ await setOutput({
key: 'all_old_new_renamed_files', key: 'all_old_new_renamed_files',
value: allOldNewRenamedFiles.paths, value: allOldNewRenamedFiles.paths,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}) })
await setOutput({ await setOutput({
key: 'all_old_new_renamed_files_count', key: 'all_old_new_renamed_files_count',
value: allOldNewRenamedFiles.count, value: allOldNewRenamedFiles.count,
inputs writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
}) })
core.info('All Done!') core.info('All Done!')
core.endGroup() core.endGroup()

View file

@ -892,7 +892,7 @@ export const jsonOutput = ({
value, value,
shouldEscape shouldEscape
}: { }: {
value: string | string[] value: string | string[] | boolean
shouldEscape: boolean shouldEscape: boolean
}): string => { }): string => {
const result = JSON.stringify(value) const result = JSON.stringify(value)
@ -1226,18 +1226,29 @@ export const getRecoverFilePatterns = ({
export const setOutput = async ({ export const setOutput = async ({
key, key,
value, value,
inputs writeOutputFiles,
outputDir,
json = false,
shouldEscape = false
}: { }: {
key: string key: string
value: string | boolean value: string | string[] | boolean
inputs: Inputs writeOutputFiles: boolean
outputDir: string
json?: boolean
shouldEscape?: boolean
}): Promise<void> => { }): Promise<void> => {
const cleanedValue = value.toString().trim() let cleanedValue
if (json) {
cleanedValue = jsonOutput({value, shouldEscape})
} else {
cleanedValue = value.toString().trim()
}
core.setOutput(key, cleanedValue) core.setOutput(key, cleanedValue)
if (inputs.writeOutputFiles) { if (writeOutputFiles) {
const outputDir = inputs.outputDir const extension = json ? 'json' : 'txt'
const extension = inputs.json ? 'json' : 'txt'
const outputFilePath = path.join(outputDir, `${key}.${extension}`) const outputFilePath = path.join(outputDir, `${key}.${extension}`)
if (!(await exists(outputDir))) { if (!(await exists(outputDir))) {