3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-01-29 13:34:51 +00:00

feat: add support for returning changed file counts (#1273)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack 2023-06-16 21:13:40 -06:00 committed by GitHub
parent c3c3db7fee
commit f573054697
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 169 additions and 33 deletions

View file

@ -157,46 +157,76 @@ inputs:
outputs:
added_files:
description: "Returns only files that are Added (A)."
added_files_count:
description: "Returns the number of `added_files`"
copied_files:
description: "Returns only files that are Copied (C)."
copied_files_count:
description: "Returns the number of `copied_files`"
deleted_files:
description: "Returns only files that are Deleted (D)."
deleted_files_count:
description: "Returns the number of `deleted_files`"
modified_files:
description: "Returns only files that are Modified (M)."
modified_files_count:
description: "Returns the number of `modified_files`"
renamed_files:
description: "Returns only files that are Renamed (R)."
renamed_files_count:
description: "Returns the number of `renamed_files`"
all_old_new_renamed_files:
description: "Returns only files that are Renamed and lists their old and new names. **NOTE:** This requires setting `include_all_old_new_renamed_files` to `true`. Also, keep in mind that this output is global and wouldn't be nested in outputs generated when the `*_yaml_*` input is used. (R)"
all_old_new_renamed_files_count:
description: "Returns the number of `all_old_new_renamed_files`"
type_changed_files:
description: "Returns only files that have their file type changed (T)."
type_changed_files_count:
description: "Returns the number of `type_changed_files`"
unmerged_files:
description: "Returns only files that are Unmerged (U)."
unmerged_files_count:
description: "Returns the number of `unmerged_files`"
unknown_files:
description: "Returns only files that are Unknown (X)."
unknown_files_count:
description: "Returns the number of `unknown_files`"
all_changed_and_modified_files:
description: "Returns all changed and modified files i.e. *a combination of (ACMRDTUX)*"
all_changed_and_modified_files_count:
description: "Returns the number of `all_changed_and_modified_files`"
all_changed_files:
description: "Returns all changed files i.e. *a combination of all added, copied, modified and renamed files (ACMR)*"
all_changed_files_count:
description: "Returns the number of `all_changed_files`"
any_changed:
description: "Returns `true` when any of the filenames provided using the `files*` or `files_ignore*` inputs has changed. i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*."
only_changed:
description: "Returns `true` when only files provided using the `files*` or `files_ignore*` inputs has changed. i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*."
other_changed_files:
description: "Returns all other changed files not listed in the files input i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*."
other_changed_files_count:
description: "Returns the number of `other_changed_files`"
all_modified_files:
description: "Returns all changed files i.e. *a combination of all added, copied, modified, renamed and deleted files (ACMRD)*."
all_modified_files_count:
description: "Returns the number of `all_modified_files`"
any_modified:
description: "Returns `true` when any of the filenames provided using the `files*` or `files_ignore*` inputs has been modified. i.e. *using a combination of all added, copied, modified, renamed, and deleted files (ACMRD)*."
only_modified:
description: "Returns `true` when only files provided using the `files*` or `files_ignore*` inputs has been modified. (ACMRD)."
other_modified_files:
description: "Returns all other modified files not listed in the files input i.e. *a combination of all added, copied, modified, and deleted files (ACMRD)*"
other_modified_files_count:
description: "Returns the number of `other_modified_files`"
any_deleted:
description: "Returns `true` when any of the filenames provided using the `files*` or `files_ignore*` inputs has been deleted. (D)"
only_deleted:
description: "Returns `true` when only files provided using the `files*` or `files_ignore*` inputs has been deleted. (D)"
other_deleted_files:
description: "Returns all other deleted files not listed in the files input i.e. *a combination of all deleted files (D)*"
other_deleted_files_count:
description: "Returns the number of `other_deleted_files`"
runs:
using: 'node16'

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View file

@ -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,
@ -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<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({
@ -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()
}
}

View file

@ -49,7 +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.count,
inputs
})
@ -61,7 +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.count,
inputs
})
@ -73,7 +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.count,
inputs
})
@ -85,7 +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.count,
inputs
})
@ -97,7 +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.count,
inputs
})
@ -109,7 +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.count,
inputs
})
@ -121,7 +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.count,
inputs
})
@ -132,7 +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.count,
inputs
})
@ -149,13 +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.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
})
@ -171,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({
@ -195,6 +248,12 @@ export const setChangedFilesOutput = async ({
inputs
})
await setOutput({
key: getOutputKey('other_changed_files_count', outputPrefix),
value: otherChangedFiles.length.toString(),
inputs
})
const allModifiedFiles = await getChangeTypeFiles({
inputs,
changedFiles: allFilteredDiffFiles,
@ -209,13 +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.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
})
@ -231,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({
@ -255,6 +320,12 @@ export const setChangedFilesOutput = async ({
inputs
})
await setOutput({
key: getOutputKey('other_modified_files_count', outputPrefix),
value: otherModifiedFiles.length.toString(),
inputs
})
const deletedFiles = await getChangeTypeFiles({
inputs,
changedFiles: allFilteredDiffFiles,
@ -263,13 +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.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
})
@ -279,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({
@ -301,4 +378,10 @@ export const setChangedFilesOutput = async ({
value: otherDeletedFiles.join(inputs.separator),
inputs
})
await setOutput({
key: getOutputKey('other_deleted_files_count', outputPrefix),
value: otherDeletedFiles.length.toString(),
inputs
})
}

View file

@ -183,7 +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.count,
inputs
})
core.info('All Done!')