Skip to content

Commit

Permalink
Merge c98e6d2 into 0b947ed
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Sep 22, 2023
2 parents 0b947ed + c98e6d2 commit 0ad71b9
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 19 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ inputs:
description: "Separator used to split the `dir_names_include_files` input"
default: "\n"
required: false
dir_names_deleted_files_include_only_deleted_dirs:
description: "Include only deleted directories in the `deleted_files` output when `dir_names` is set to `true`."
required: false
default: "false"
json:
description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs. [Example](https://github.com/tj-actions/changed-files/blob/main/.github/workflows/matrix-test.yml)"
required: false
Expand Down
67 changes: 57 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export const processChangedFiles = async ({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
yamlFilePatterns,
workingDirectory
}: {
filePatterns: string[]
allDiffFiles: ChangedFiles
inputs: Inputs
yamlFilePatterns: Record<string, string[]>
workingDirectory?: string
}): Promise<void> => {
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns')
Expand All @@ -44,7 +46,8 @@ export const processChangedFiles = async ({
allDiffFiles,
allFilteredDiffFiles,
inputs,
filePatterns
filePatterns,
workingDirectory
})
core.info('All Done!')
core.endGroup()
Expand All @@ -71,7 +74,8 @@ export const processChangedFiles = async ({
allFilteredDiffFiles,
inputs,
filePatterns: yamlFilePatterns[key],
outputPrefix: key
outputPrefix: key,
workingDirectory
})
if (anyModified) {
modifiedKeys.push(key)
Expand Down Expand Up @@ -106,7 +110,8 @@ export const processChangedFiles = async ({
await setOutputsAndGetModifiedAndChangedFilesStatus({
allDiffFiles,
allFilteredDiffFiles: allDiffFiles,
inputs
inputs,
workingDirectory
})
core.info('All Done!')
core.endGroup()
Expand Down
25 changes: 23 additions & 2 deletions src/changedFilesOutput.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as core from '@actions/core'
import path from 'path'
import {
ChangedFiles,
ChangeTypeEnum,
getAllChangeTypeFiles,
getChangeTypeFiles
} from './changedFiles'
import {Inputs} from './inputs'
import {getOutputKey, setArrayOutput, setOutput} from './utils'
import {getOutputKey, setArrayOutput, setOutput, exists} from './utils'

const getArrayFromPaths = (
paths: string | string[],
Expand All @@ -20,13 +21,15 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
allFilteredDiffFiles,
inputs,
filePatterns = [],
outputPrefix = ''
outputPrefix = '',
workingDirectory
}: {
allDiffFiles: ChangedFiles
allFilteredDiffFiles: ChangedFiles
inputs: Inputs
filePatterns?: string[]
outputPrefix?: string
workingDirectory?: string
}): Promise<{anyModified: boolean; anyChanged: boolean}> => {
const addedFiles = await getChangeTypeFiles({
inputs,
Expand Down Expand Up @@ -388,6 +391,24 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
changeTypes: [ChangeTypeEnum.Deleted]
})
core.debug(`Deleted files: ${JSON.stringify(deletedFiles)}`)

if (
inputs.dirNamesDeletedFilesIncludeOnlyDeletedDirs &&
inputs.dirNames &&
workingDirectory
) {
const newDeletedFilesPaths: string[] = []
for (const deletedPath of getArrayFromPaths(deletedFiles.paths, inputs)) {
if (!(await exists(path.join(workingDirectory, deletedPath)))) {
newDeletedFilesPaths.push(deletedPath)
}
}
deletedFiles.paths = inputs.json
? newDeletedFilesPaths
: newDeletedFilesPaths.join(inputs.separator)
deletedFiles.count = newDeletedFilesPaths.length.toString()
}

await setOutput({
key: getOutputKey('deleted_files', outputPrefix),
value: deletedFiles.paths,
Expand Down
8 changes: 8 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type Inputs = {
dirNamesExcludeCurrentDir: boolean
dirNamesIncludeFiles: string
dirNamesIncludeFilesSeparator: string
dirNamesDeletedFilesIncludeOnlyDeletedDirs: boolean
json: boolean
escapeJson: boolean
fetchDepth?: number
Expand Down Expand Up @@ -210,6 +211,12 @@ export const getInputs = (): Inputs => {
required: false
}
)
const dirNamesDeletedFilesIncludeOnlyDeletedDirs = core.getBooleanInput(
'dir_names_deleted_files_include_only_deleted_dirs',
{
required: false
}
)

const inputs: Inputs = {
files,
Expand Down Expand Up @@ -254,6 +261,7 @@ export const getInputs = (): Inputs => {
dirNamesExcludeCurrentDir,
dirNamesIncludeFiles,
dirNamesIncludeFilesSeparator,
dirNamesDeletedFilesIncludeOnlyDeletedDirs,
json,
escapeJson,
writeOutputFiles,
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ const getChangedFilesFromLocalGitHistory = async ({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
yamlFilePatterns,
workingDirectory
})

if (inputs.includeAllOldNewRenamedFiles) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const verifyMinimumGitVersion = async (): Promise<void> => {
* @param filePath - path to check
* @returns path exists
*/
const exists = async (filePath: string): Promise<boolean> => {
export const exists = async (filePath: string): Promise<boolean> => {
try {
await fs.access(filePath)
return true
Expand Down

0 comments on commit 0ad71b9

Please sign in to comment.