Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changed_keys and modified_keys output to handle json and escape_json inputs #1585

Merged
merged 8 commits into from
Sep 19, 2023
12 changes: 8 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
gitSubmoduleDiffSHA,
isWindows,
jsonOutput,
setOutput
setArrayOutput
} from './utils'

export const processChangedFiles = async ({
Expand Down Expand Up @@ -85,22 +85,18 @@ export const processChangedFiles = async ({
}

if (modifiedKeys.length > 0) {
await setOutput({
await setArrayOutput({
key: 'modified_keys',
value: modifiedKeys.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
inputs,
value: modifiedKeys
})
}

if (changedKeys.length > 0) {
await setOutput({
await setArrayOutput({
key: 'changed_keys',
value: changedKeys.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json
inputs,
value: changedKeys
})
}
}
Expand Down
48 changes: 16 additions & 32 deletions src/changedFilesOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import {
getChangeTypeFiles
} from './changedFiles'
import {Inputs} from './inputs'
import {setOutput} from './utils'

const getOutputKey = (key: string, outputPrefix: string): string => {
return outputPrefix ? `${outputPrefix}_${key}` : key
}
import {getOutputKey, setArrayOutput, setOutput} from './utils'

const getArrayFromPaths = (
paths: string | string[],
Expand Down Expand Up @@ -283,15 +279,11 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
json: inputs.json
})

await setOutput({
key: getOutputKey('other_changed_files', outputPrefix),
value: inputs.json
? otherChangedFiles
: otherChangedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
await setArrayOutput({
key: 'other_changed_files',
inputs,
value: otherChangedFiles,
outputPrefix
})

await setOutput({
Expand Down Expand Up @@ -376,15 +368,11 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
json: inputs.json
})

await setOutput({
key: getOutputKey('other_modified_files', outputPrefix),
value: inputs.json
? otherModifiedFiles
: otherModifiedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
await setArrayOutput({
key: 'other_modified_files',
inputs,
value: otherModifiedFiles,
outputPrefix
})

await setOutput({
Expand Down Expand Up @@ -457,15 +445,11 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
json: inputs.json
})

await setOutput({
key: getOutputKey('other_deleted_files', outputPrefix),
value: inputs.json
? otherDeletedFiles
: otherDeletedFiles.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
await setArrayOutput({
key: 'other_deleted_files',
inputs,
value: otherDeletedFiles,
outputPrefix
})

await setOutput({
Expand Down
26 changes: 26 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,32 @@ export const getRecoverFilePatterns = ({
return filePatterns.filter(Boolean)
}

export const getOutputKey = (key: string, outputPrefix: string): string => {
return outputPrefix ? `${outputPrefix}_${key}` : key
}

export const setArrayOutput = async ({
key,
inputs,
value,
outputPrefix
}: {
key: string
inputs: Inputs
value: string[]
outputPrefix?: string
}): Promise<void> => {
core.debug(`${key}: ${JSON.stringify(value)}`)
await setOutput({
key: outputPrefix ? getOutputKey(key, outputPrefix) : key,
value: inputs.json ? value : value.join(inputs.separator),
writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir,
json: inputs.json,
shouldEscape: inputs.escapeJson
})
}

export const setOutput = async ({
key,
value,
Expand Down