Skip to content

Commit

Permalink
Fixed bug with count
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Jun 17, 2023
1 parent c17fdb5 commit e0f028b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 45 deletions.
36 changes: 27 additions & 9 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const getRenamedFiles = async ({
hasSubmodule: boolean
diffResult: DiffResult
submodulePaths: string[]
}): Promise<string> => {
}): Promise<{paths: string; count: string}> => {
const renamedFiles = await gitRenamedFiles({
cwd: workingDirectory,
sha1: diffResult.previousSha,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -180,16 +186,22 @@ export const getChangeTypeFiles = async ({
inputs: Inputs
changedFiles: ChangedFiles
changeTypes: ChangeTypeEnum[]
}): Promise<string> => {
}): 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({
Expand Down Expand Up @@ -219,14 +231,20 @@ export const getAllChangeTypeFiles = async ({
}: {
inputs: Inputs
changedFiles: ChangedFiles
}): Promise<string> => {
}): 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()
}
}
68 changes: 34 additions & 34 deletions src/changedFilesOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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
})

Expand All @@ -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({
Expand Down Expand Up @@ -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
})

Expand All @@ -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({
Expand Down Expand Up @@ -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
})

Expand All @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ export async function run(): Promise<void> {
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!')
Expand Down

0 comments on commit e0f028b

Please sign in to comment.