diff --git a/src/changedFiles.ts b/src/changedFiles.ts index aacb330f358..10aa795e5f9 100644 --- a/src/changedFiles.ts +++ b/src/changedFiles.ts @@ -23,7 +23,7 @@ export const getRenamedFiles = async ({ hasSubmodule: boolean diffResult: DiffResult submodulePaths: string[] -}): Promise => { +}): Promise<{paths: string; count: string}> => { const renamedFiles = await gitRenamedFiles({ cwd: workingDirectory, sha1: diffResult.previousSha, @@ -63,10 +63,16 @@ export const getRenamedFiles = async ({ } if (inputs.json) { - return jsonOutput({value: renamedFiles, shouldEscape: inputs.escapeJson}) + return { + paths: jsonOutput({value: renamedFiles, shouldEscape: inputs.escapeJson}), + count: renamedFiles.length.toString() + } } - return renamedFiles.join(inputs.oldNewFilesSeparator) + return { + paths: renamedFiles.join(inputs.oldNewFilesSeparator), + count: renamedFiles.length.toString() + } } export enum ChangeTypeEnum { @@ -180,16 +186,22 @@ export const getChangeTypeFiles = async ({ inputs: Inputs changedFiles: ChangedFiles changeTypes: ChangeTypeEnum[] -}): Promise => { +}): Promise<{paths: string; count: string}> => { const files = [ ...new Set(getChangeTypeFilesGenerator({inputs, changedFiles, changeTypes})) ] if (inputs.json) { - return jsonOutput({value: files, shouldEscape: inputs.escapeJson}) + return { + paths: jsonOutput({value: files, shouldEscape: inputs.escapeJson}), + count: files.length.toString() + } } - return files.join(inputs.separator) + return { + paths: files.join(inputs.separator), + count: files.length.toString() + } } function* getAllChangeTypeFilesGenerator({ @@ -219,14 +231,20 @@ export const getAllChangeTypeFiles = async ({ }: { inputs: Inputs changedFiles: ChangedFiles -}): Promise => { +}): Promise<{paths: string; count: string}> => { const files = [ ...new Set(getAllChangeTypeFilesGenerator({inputs, changedFiles})) ] if (inputs.json) { - return jsonOutput({value: files, shouldEscape: inputs.escapeJson}) + return { + paths: jsonOutput({value: files, shouldEscape: inputs.escapeJson}), + count: files.length.toString() + } } - return files.join(inputs.separator) + return { + paths: files.join(inputs.separator), + count: files.length.toString() + } } diff --git a/src/changedFilesOutput.ts b/src/changedFilesOutput.ts index a593e0cb26d..41b88d90200 100644 --- a/src/changedFilesOutput.ts +++ b/src/changedFilesOutput.ts @@ -49,12 +49,12 @@ export const setChangedFilesOutput = async ({ core.debug(`Added files: ${addedFiles}`) await setOutput({ key: getOutputKey('added_files', outputPrefix), - value: addedFiles, + value: addedFiles.paths, inputs }) await setOutput({ key: getOutputKey('added_files_count', outputPrefix), - value: addedFiles.length.toString(), + value: addedFiles.count, inputs }) @@ -66,13 +66,13 @@ export const setChangedFilesOutput = async ({ core.debug(`Copied files: ${copiedFiles}`) await setOutput({ key: getOutputKey('copied_files', outputPrefix), - value: copiedFiles, + value: copiedFiles.paths, inputs }) await setOutput({ key: getOutputKey('copied_files_count', outputPrefix), - value: copiedFiles.length.toString(), + value: copiedFiles.count, inputs }) @@ -84,13 +84,13 @@ export const setChangedFilesOutput = async ({ core.debug(`Modified files: ${modifiedFiles}`) await setOutput({ key: getOutputKey('modified_files', outputPrefix), - value: modifiedFiles, + value: modifiedFiles.paths, inputs }) await setOutput({ key: getOutputKey('modified_files_count', outputPrefix), - value: modifiedFiles.length.toString(), + value: modifiedFiles.count, inputs }) @@ -102,13 +102,13 @@ export const setChangedFilesOutput = async ({ core.debug(`Renamed files: ${renamedFiles}`) await setOutput({ key: getOutputKey('renamed_files', outputPrefix), - value: renamedFiles, + value: renamedFiles.paths, inputs }) await setOutput({ key: getOutputKey('renamed_files_count', outputPrefix), - value: renamedFiles.length.toString(), + value: renamedFiles.count, inputs }) @@ -120,13 +120,13 @@ export const setChangedFilesOutput = async ({ core.debug(`Type changed files: ${typeChangedFiles}`) await setOutput({ key: getOutputKey('type_changed_files', outputPrefix), - value: typeChangedFiles, + value: typeChangedFiles.paths, inputs }) await setOutput({ key: getOutputKey('type_changed_files_count', outputPrefix), - value: typeChangedFiles.length.toString(), + value: typeChangedFiles.count, inputs }) @@ -138,13 +138,13 @@ export const setChangedFilesOutput = async ({ core.debug(`Unmerged files: ${unmergedFiles}`) await setOutput({ key: getOutputKey('unmerged_files', outputPrefix), - value: unmergedFiles, + value: unmergedFiles.paths, inputs }) await setOutput({ key: getOutputKey('unmerged_files_count', outputPrefix), - value: unmergedFiles.length.toString(), + value: unmergedFiles.count, inputs }) @@ -156,13 +156,13 @@ export const setChangedFilesOutput = async ({ core.debug(`Unknown files: ${unknownFiles}`) await setOutput({ key: getOutputKey('unknown_files', outputPrefix), - value: unknownFiles, + value: unknownFiles.paths, inputs }) await setOutput({ key: getOutputKey('unknown_files_count', outputPrefix), - value: unknownFiles.length.toString(), + value: unknownFiles.count, inputs }) @@ -173,13 +173,13 @@ export const setChangedFilesOutput = async ({ core.debug(`All changed and modified files: ${allChangedAndModifiedFiles}`) await setOutput({ key: getOutputKey('all_changed_and_modified_files', outputPrefix), - value: allChangedAndModifiedFiles, + value: allChangedAndModifiedFiles.paths, inputs }) await setOutput({ key: getOutputKey('all_changed_and_modified_files_count', outputPrefix), - value: allChangedAndModifiedFiles.length.toString(), + value: allChangedAndModifiedFiles.count, inputs }) @@ -196,19 +196,19 @@ export const setChangedFilesOutput = async ({ core.debug(`All changed files: ${allChangedFiles}`) await setOutput({ key: getOutputKey('all_changed_files', outputPrefix), - value: allChangedFiles, + value: allChangedFiles.paths, inputs }) await setOutput({ key: getOutputKey('all_changed_files_count', outputPrefix), - value: allChangedFiles.length.toString(), + value: allChangedFiles.count, inputs }) await setOutput({ key: getOutputKey('any_changed', outputPrefix), - value: allChangedFiles.length > 0 && filePatterns.length > 0, + value: allChangedFiles.paths.length > 0 && filePatterns.length > 0, inputs }) @@ -224,16 +224,16 @@ export const setChangedFilesOutput = async ({ }) core.debug(`All other changed files: ${allOtherChangedFiles}`) - const otherChangedFiles = allOtherChangedFiles + const otherChangedFiles = allOtherChangedFiles.paths .split(inputs.separator) .filter( (filePath: string) => - !allChangedFiles.split(inputs.separator).includes(filePath) + !allChangedFiles.paths.split(inputs.separator).includes(filePath) ) const onlyChanged = otherChangedFiles.length === 0 && - allChangedFiles.length > 0 && + allChangedFiles.paths.length > 0 && filePatterns.length > 0 await setOutput({ @@ -268,19 +268,19 @@ export const setChangedFilesOutput = async ({ core.debug(`All modified files: ${allModifiedFiles}`) await setOutput({ key: getOutputKey('all_modified_files', outputPrefix), - value: allModifiedFiles, + value: allModifiedFiles.paths, inputs }) await setOutput({ key: getOutputKey('all_modified_files_count', outputPrefix), - value: allModifiedFiles.length.toString(), + value: allModifiedFiles.count, inputs }) await setOutput({ key: getOutputKey('any_modified', outputPrefix), - value: allModifiedFiles.length > 0 && filePatterns.length > 0, + value: allModifiedFiles.paths.length > 0 && filePatterns.length > 0, inputs }) @@ -296,16 +296,16 @@ export const setChangedFilesOutput = async ({ ] }) - const otherModifiedFiles = allOtherModifiedFiles + const otherModifiedFiles = allOtherModifiedFiles.paths .split(inputs.separator) .filter( (filePath: string) => - !allModifiedFiles.split(inputs.separator).includes(filePath) + !allModifiedFiles.paths.split(inputs.separator).includes(filePath) ) const onlyModified = otherModifiedFiles.length === 0 && - allModifiedFiles.length > 0 && + allModifiedFiles.paths.length > 0 && filePatterns.length > 0 await setOutput({ @@ -334,19 +334,19 @@ export const setChangedFilesOutput = async ({ core.debug(`Deleted files: ${deletedFiles}`) await setOutput({ key: getOutputKey('deleted_files', outputPrefix), - value: deletedFiles, + value: deletedFiles.paths, inputs }) await setOutput({ key: getOutputKey('deleted_files_count', outputPrefix), - value: deletedFiles.length.toString(), + value: deletedFiles.count, inputs }) await setOutput({ key: getOutputKey('any_deleted', outputPrefix), - value: deletedFiles.length > 0 && filePatterns.length > 0, + value: deletedFiles.paths.length > 0 && filePatterns.length > 0, inputs }) @@ -356,15 +356,15 @@ export const setChangedFilesOutput = async ({ changeTypes: [ChangeTypeEnum.Deleted] }) - const otherDeletedFiles = allOtherDeletedFiles + const otherDeletedFiles = allOtherDeletedFiles.paths .split(inputs.separator) .filter( - filePath => !deletedFiles.split(inputs.separator).includes(filePath) + filePath => !deletedFiles.paths.split(inputs.separator).includes(filePath) ) const onlyDeleted = otherDeletedFiles.length === 0 && - deletedFiles.length > 0 && + deletedFiles.paths.length > 0 && filePatterns.length > 0 await setOutput({ diff --git a/src/main.ts b/src/main.ts index 4dd33d59744..36b4df28e15 100644 --- a/src/main.ts +++ b/src/main.ts @@ -183,12 +183,12 @@ export async function run(): Promise { core.debug(`All old new renamed files: ${allOldNewRenamedFiles}`) await setOutput({ key: 'all_old_new_renamed_files', - value: allOldNewRenamedFiles, + value: allOldNewRenamedFiles.paths, inputs }) await setOutput({ key: 'all_old_new_renamed_files_count', - value: allOldNewRenamedFiles.length.toString(), + value: allOldNewRenamedFiles.count, inputs }) core.info('All Done!')