Skip to content

Commit

Permalink
Fixed bug setting output
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Sep 4, 2023
1 parent 61f6505 commit b0de00e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,15 @@ export const getChangeTypeFiles = async ({
inputs: Inputs
changedFiles: ChangedFiles
changeTypes: ChangeTypeEnum[]
}): Promise<{paths: string; count: string}> => {
}): Promise<{paths: string[] | string; count: string}> => {
const files = [
...new Set(getChangeTypeFilesGenerator({inputs, changedFiles, changeTypes}))
].filter(Boolean)

const paths = inputs.json ? files : files.join(inputs.separator)

return {
paths: files.join(inputs.separator),
paths,
count: files.length.toString()
}
}
Expand Down
62 changes: 45 additions & 17 deletions src/changedFilesOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const getOutputKey = (key: string, outputPrefix: string): string => {
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 ({
allDiffFiles,
allFilteredDiffFiles,
Expand Down Expand Up @@ -221,12 +228,18 @@ export const setChangedFilesOutput = async ({
})
core.debug(`All other changed files: ${JSON.stringify(allOtherChangedFiles)}`)

const otherChangedFiles = allOtherChangedFiles.paths
.split(inputs.separator)
.filter(
(filePath: string) =>
!allChangedFiles.paths.split(inputs.separator).includes(filePath)
)
const allOtherChangedFilesPaths: string[] = getArrayFromPaths(
allOtherChangedFiles.paths,
inputs
)
const allChangedFilesPaths: string[] = getArrayFromPaths(
allChangedFiles.paths,
inputs
)

const otherChangedFiles = allOtherChangedFilesPaths.filter(
(filePath: string) => !allChangedFilesPaths.includes(filePath)
)

const onlyChanged =
otherChangedFiles.length === 0 &&
Expand Down Expand Up @@ -295,12 +308,19 @@ export const setChangedFilesOutput = async ({
]
})

const otherModifiedFiles = allOtherModifiedFiles.paths
.split(inputs.separator)
.filter(
(filePath: string) =>
!allModifiedFiles.paths.split(inputs.separator).includes(filePath)
)
const allOtherModifiedFilesPaths: string[] = getArrayFromPaths(
allOtherModifiedFiles.paths,
inputs
)

const allModifiedFilesPaths: string[] = getArrayFromPaths(
allModifiedFiles.paths,
inputs
)

const otherModifiedFiles = allOtherModifiedFilesPaths.filter(
(filePath: string) => !allModifiedFilesPaths.includes(filePath)
)

const onlyModified =
otherModifiedFiles.length === 0 &&
Expand Down Expand Up @@ -357,11 +377,19 @@ export const setChangedFilesOutput = async ({
changeTypes: [ChangeTypeEnum.Deleted]
})

const otherDeletedFiles = allOtherDeletedFiles.paths
.split(inputs.separator)
.filter(
filePath => !deletedFiles.paths.split(inputs.separator).includes(filePath)
)
const allOtherDeletedFilesPaths: string[] = getArrayFromPaths(
allOtherDeletedFiles.paths,
inputs
)

const deletedFilesPaths: string[] = getArrayFromPaths(
deletedFiles.paths,
inputs
)

const otherDeletedFiles = allOtherDeletedFilesPaths.filter(
filePath => !deletedFilesPaths.includes(filePath)
)

const onlyDeleted =
otherDeletedFiles.length === 0 &&
Expand Down

0 comments on commit b0de00e

Please sign in to comment.