mirror of
https://github.com/tj-actions/changed-files
synced 2025-01-29 13:34:51 +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:
parent
fd460fa3ba
commit
8d335b7b7d
7 changed files with 218 additions and 82 deletions
33
.github/workflows/test.yml
vendored
33
.github/workflows/test.yml
vendored
|
@ -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: ./
|
||||||
|
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,12 +257,18 @@ 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 =
|
||||||
otherChangedFiles.length === 0 &&
|
otherChangedFiles.length === 0 &&
|
||||||
|
@ -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,12 +349,19 @@ 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 =
|
||||||
otherModifiedFiles.length === 0 &&
|
otherModifiedFiles.length === 0 &&
|
||||||
|
@ -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,11 +430,19 @@ 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 =
|
||||||
otherDeletedFiles.length === 0 &&
|
otherDeletedFiles.length === 0 &&
|
||||||
|
@ -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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
27
src/utils.ts
27
src/utils.ts
|
@ -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))) {
|
||||||
|
|
Loading…
Reference in a new issue