2023-06-16 06:17:13 +00:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import {
|
|
|
|
ChangedFiles,
|
|
|
|
ChangeTypeEnum,
|
|
|
|
getAllChangeTypeFiles,
|
|
|
|
getChangeTypeFiles
|
|
|
|
} from './changedFiles'
|
2023-06-17 02:33:42 +00:00
|
|
|
import {DiffResult} from './commitSha'
|
2023-06-16 06:17:13 +00:00
|
|
|
import {Inputs} from './inputs'
|
2023-06-17 02:33:42 +00:00
|
|
|
import {getFilteredChangedFiles, recoverDeletedFiles, setOutput} from './utils'
|
2023-06-16 06:17:13 +00:00
|
|
|
|
|
|
|
const getOutputKey = (key: string, outputPrefix: string): string => {
|
|
|
|
return outputPrefix ? `${outputPrefix}_${key}` : key
|
|
|
|
}
|
|
|
|
|
|
|
|
export const setChangedFilesOutput = async ({
|
|
|
|
allDiffFiles,
|
|
|
|
inputs,
|
2023-06-17 02:33:42 +00:00
|
|
|
workingDirectory,
|
|
|
|
diffResult,
|
2023-06-16 06:17:13 +00:00
|
|
|
filePatterns = [],
|
|
|
|
outputPrefix = ''
|
|
|
|
}: {
|
|
|
|
allDiffFiles: ChangedFiles
|
|
|
|
inputs: Inputs
|
2023-06-17 02:33:42 +00:00
|
|
|
workingDirectory: string
|
2023-06-23 17:20:13 +00:00
|
|
|
diffResult?: DiffResult
|
|
|
|
filePatterns?: string[]
|
2023-06-16 06:17:13 +00:00
|
|
|
outputPrefix?: string
|
|
|
|
}): Promise<void> => {
|
|
|
|
const allFilteredDiffFiles = await getFilteredChangedFiles({
|
|
|
|
allDiffFiles,
|
|
|
|
filePatterns
|
|
|
|
})
|
|
|
|
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`)
|
|
|
|
|
2023-06-23 17:20:13 +00:00
|
|
|
if (diffResult) {
|
|
|
|
await recoverDeletedFiles({
|
|
|
|
inputs,
|
|
|
|
workingDirectory,
|
|
|
|
deletedFiles: allFilteredDiffFiles[ChangeTypeEnum.Deleted],
|
|
|
|
sha: diffResult.previousSha
|
|
|
|
})
|
|
|
|
}
|
2023-06-17 02:33:42 +00:00
|
|
|
|
2023-06-16 06:17:13 +00:00
|
|
|
const addedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Added]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`Added files: ${JSON.stringify(addedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('added_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: addedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('added_files_count', outputPrefix),
|
|
|
|
value: addedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const copiedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Copied]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`Copied files: ${JSON.stringify(copiedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('copied_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: copiedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('copied_files_count', outputPrefix),
|
|
|
|
value: copiedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const modifiedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Modified]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`Modified files: ${JSON.stringify(modifiedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('modified_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: modifiedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('modified_files_count', outputPrefix),
|
|
|
|
value: modifiedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const renamedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Renamed]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`Renamed files: ${JSON.stringify(renamedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('renamed_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: renamedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('renamed_files_count', outputPrefix),
|
|
|
|
value: renamedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const typeChangedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.TypeChanged]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`Type changed files: ${JSON.stringify(typeChangedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('type_changed_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: typeChangedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('type_changed_files_count', outputPrefix),
|
|
|
|
value: typeChangedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const unmergedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Unmerged]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`Unmerged files: ${JSON.stringify(unmergedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('unmerged_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: unmergedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('unmerged_files_count', outputPrefix),
|
|
|
|
value: unmergedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const unknownFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Unknown]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`Unknown files: ${JSON.stringify(unknownFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('unknown_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: unknownFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('unknown_files_count', outputPrefix),
|
|
|
|
value: unknownFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const allChangedAndModifiedFiles = await getAllChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(
|
|
|
|
`All changed and modified files: ${JSON.stringify(
|
|
|
|
allChangedAndModifiedFiles
|
|
|
|
)}`
|
|
|
|
)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('all_changed_and_modified_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: allChangedAndModifiedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('all_changed_and_modified_files_count', outputPrefix),
|
|
|
|
value: allChangedAndModifiedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const allChangedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [
|
|
|
|
ChangeTypeEnum.Added,
|
|
|
|
ChangeTypeEnum.Copied,
|
|
|
|
ChangeTypeEnum.Modified,
|
|
|
|
ChangeTypeEnum.Renamed
|
|
|
|
]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`All changed files: ${JSON.stringify(allChangedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('all_changed_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: allChangedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('all_changed_files_count', outputPrefix),
|
|
|
|
value: allChangedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('any_changed', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: allChangedFiles.paths.length > 0 && filePatterns.length > 0,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const allOtherChangedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allDiffFiles,
|
|
|
|
changeTypes: [
|
|
|
|
ChangeTypeEnum.Added,
|
|
|
|
ChangeTypeEnum.Copied,
|
|
|
|
ChangeTypeEnum.Modified,
|
|
|
|
ChangeTypeEnum.Renamed
|
|
|
|
]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`All other changed files: ${JSON.stringify(allOtherChangedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
|
2023-06-17 03:13:40 +00:00
|
|
|
const otherChangedFiles = allOtherChangedFiles.paths
|
2023-06-16 06:17:13 +00:00
|
|
|
.split(inputs.separator)
|
|
|
|
.filter(
|
|
|
|
(filePath: string) =>
|
2023-06-17 03:13:40 +00:00
|
|
|
!allChangedFiles.paths.split(inputs.separator).includes(filePath)
|
2023-06-16 06:17:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const onlyChanged =
|
|
|
|
otherChangedFiles.length === 0 &&
|
2023-06-17 03:13:40 +00:00
|
|
|
allChangedFiles.paths.length > 0 &&
|
2023-06-16 06:17:13 +00:00
|
|
|
filePatterns.length > 0
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('only_changed', outputPrefix),
|
|
|
|
value: onlyChanged,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('other_changed_files', outputPrefix),
|
|
|
|
value: otherChangedFiles.join(inputs.separator),
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-17 03:13:40 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('other_changed_files_count', outputPrefix),
|
|
|
|
value: otherChangedFiles.length.toString(),
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-16 06:17:13 +00:00
|
|
|
const allModifiedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [
|
|
|
|
ChangeTypeEnum.Added,
|
|
|
|
ChangeTypeEnum.Copied,
|
|
|
|
ChangeTypeEnum.Modified,
|
|
|
|
ChangeTypeEnum.Renamed,
|
|
|
|
ChangeTypeEnum.Deleted
|
|
|
|
]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`All modified files: ${JSON.stringify(allModifiedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('all_modified_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: allModifiedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('all_modified_files_count', outputPrefix),
|
|
|
|
value: allModifiedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('any_modified', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: allModifiedFiles.paths.length > 0 && filePatterns.length > 0,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const allOtherModifiedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allDiffFiles,
|
|
|
|
changeTypes: [
|
|
|
|
ChangeTypeEnum.Added,
|
|
|
|
ChangeTypeEnum.Copied,
|
|
|
|
ChangeTypeEnum.Modified,
|
|
|
|
ChangeTypeEnum.Renamed,
|
|
|
|
ChangeTypeEnum.Deleted
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2023-06-17 03:13:40 +00:00
|
|
|
const otherModifiedFiles = allOtherModifiedFiles.paths
|
2023-06-16 06:17:13 +00:00
|
|
|
.split(inputs.separator)
|
|
|
|
.filter(
|
|
|
|
(filePath: string) =>
|
2023-06-17 03:13:40 +00:00
|
|
|
!allModifiedFiles.paths.split(inputs.separator).includes(filePath)
|
2023-06-16 06:17:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const onlyModified =
|
|
|
|
otherModifiedFiles.length === 0 &&
|
2023-06-17 03:13:40 +00:00
|
|
|
allModifiedFiles.paths.length > 0 &&
|
2023-06-16 06:17:13 +00:00
|
|
|
filePatterns.length > 0
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('only_modified', outputPrefix),
|
|
|
|
value: onlyModified,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('other_modified_files', outputPrefix),
|
|
|
|
value: otherModifiedFiles.join(inputs.separator),
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-17 03:13:40 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('other_modified_files_count', outputPrefix),
|
|
|
|
value: otherModifiedFiles.length.toString(),
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-16 06:17:13 +00:00
|
|
|
const deletedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Deleted]
|
|
|
|
})
|
2023-07-18 09:44:59 +00:00
|
|
|
core.debug(`Deleted files: ${JSON.stringify(deletedFiles)}`)
|
2023-06-16 06:17:13 +00:00
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('deleted_files', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: deletedFiles.paths,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('deleted_files_count', outputPrefix),
|
|
|
|
value: deletedFiles.count,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('any_deleted', outputPrefix),
|
2023-06-17 03:13:40 +00:00
|
|
|
value: deletedFiles.paths.length > 0 && filePatterns.length > 0,
|
2023-06-16 06:17:13 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
const allOtherDeletedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Deleted]
|
|
|
|
})
|
|
|
|
|
2023-06-17 03:13:40 +00:00
|
|
|
const otherDeletedFiles = allOtherDeletedFiles.paths
|
2023-06-16 06:17:13 +00:00
|
|
|
.split(inputs.separator)
|
|
|
|
.filter(
|
2023-06-17 03:13:40 +00:00
|
|
|
filePath => !deletedFiles.paths.split(inputs.separator).includes(filePath)
|
2023-06-16 06:17:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const onlyDeleted =
|
|
|
|
otherDeletedFiles.length === 0 &&
|
2023-06-17 03:13:40 +00:00
|
|
|
deletedFiles.paths.length > 0 &&
|
2023-06-16 06:17:13 +00:00
|
|
|
filePatterns.length > 0
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('only_deleted', outputPrefix),
|
|
|
|
value: onlyDeleted,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('other_deleted_files', outputPrefix),
|
|
|
|
value: otherDeletedFiles.join(inputs.separator),
|
|
|
|
inputs
|
|
|
|
})
|
2023-06-17 03:13:40 +00:00
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: getOutputKey('other_deleted_files_count', outputPrefix),
|
|
|
|
value: otherDeletedFiles.length.toString(),
|
|
|
|
inputs
|
|
|
|
})
|
2023-06-16 06:17:13 +00:00
|
|
|
}
|