mirror of
https://github.com/tj-actions/changed-files
synced 2024-12-17 03:47:20 +00:00
feat: add support for returning YAML keys for paths that have changed (#1581)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
a17e8c5252
commit
5db7b578d5
6 changed files with 61 additions and 14 deletions
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
|
@ -765,6 +765,12 @@ jobs:
|
|||
echo "Expected: (test/test deleted.txt) got ${{ steps.changed-files-recover-deleted-files-with-files-yaml.outputs.test_deleted_files }}"
|
||||
exit 1
|
||||
|
||||
- name: Verify that the modified_keys is correct
|
||||
if: "!contains(steps.changed-files-recover-deleted-files-with-files-yaml.outputs.modified_keys, 'test')"
|
||||
run: |
|
||||
echo "Expected: (test) got ${{ steps.changed-files-recover-deleted-files-with-files-yaml.outputs.modified_keys }}"
|
||||
exit 1
|
||||
|
||||
- name: Verify that test/test deleted.txt is restored
|
||||
run: |
|
||||
if [ ! -f "test/test deleted.txt" ]; then
|
||||
|
|
|
@ -259,7 +259,7 @@ outputs:
|
|||
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)*"
|
||||
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:
|
||||
|
@ -270,6 +270,10 @@ outputs:
|
|||
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`"
|
||||
modified_keys:
|
||||
description: "Returns all modified YAML keys when the `files_yaml` input is used. i.e. *key that contains any path that has either been added, copied, modified, and deleted (ACMRD)*"
|
||||
changed_keys:
|
||||
description: "Returns all changed YAML keys when the `files_yaml` input is used. i.e. *key that contains any path that has either been added, copied, modified, and renamed (ACMR)*"
|
||||
|
||||
runs:
|
||||
using: 'node20'
|
||||
|
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
|
@ -4,7 +4,7 @@ import type {RestEndpointMethodTypes} from '@octokit/rest'
|
|||
import flatten from 'lodash/flatten'
|
||||
import mm from 'micromatch'
|
||||
import * as path from 'path'
|
||||
import {setChangedFilesOutput} from './changedFilesOutput'
|
||||
import {setOutputsAndGetModifiedAndChangedFilesStatus} from './changedFilesOutput'
|
||||
import {DiffResult} from './commitSha'
|
||||
import {Inputs} from './inputs'
|
||||
import {
|
||||
|
@ -16,7 +16,8 @@ import {
|
|||
gitRenamedFiles,
|
||||
gitSubmoduleDiffSHA,
|
||||
isWindows,
|
||||
jsonOutput
|
||||
jsonOutput,
|
||||
setOutput
|
||||
} from './utils'
|
||||
|
||||
export const processChangedFiles = async ({
|
||||
|
@ -39,7 +40,7 @@ export const processChangedFiles = async ({
|
|||
core.debug(
|
||||
`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`
|
||||
)
|
||||
await setChangedFilesOutput({
|
||||
await setOutputsAndGetModifiedAndChangedFilesStatus({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
|
@ -49,6 +50,9 @@ export const processChangedFiles = async ({
|
|||
core.endGroup()
|
||||
}
|
||||
|
||||
const modifiedKeys: string[] = []
|
||||
const changedKeys: string[] = []
|
||||
|
||||
if (Object.keys(yamlFilePatterns).length > 0) {
|
||||
for (const key of Object.keys(yamlFilePatterns)) {
|
||||
core.startGroup(`changed-files-yaml-${key}`)
|
||||
|
@ -61,21 +65,49 @@ export const processChangedFiles = async ({
|
|||
allFilteredDiffFiles
|
||||
)}`
|
||||
)
|
||||
await setChangedFilesOutput({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns: yamlFilePatterns[key],
|
||||
outputPrefix: key
|
||||
})
|
||||
const {anyChanged, anyModified} =
|
||||
await setOutputsAndGetModifiedAndChangedFilesStatus({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns: yamlFilePatterns[key],
|
||||
outputPrefix: key
|
||||
})
|
||||
if (anyModified) {
|
||||
modifiedKeys.push(key)
|
||||
}
|
||||
if (anyChanged) {
|
||||
changedKeys.push(key)
|
||||
}
|
||||
|
||||
core.info('All Done!')
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
if (modifiedKeys.length > 0) {
|
||||
await setOutput({
|
||||
key: 'modified_keys',
|
||||
value: modifiedKeys.join(inputs.separator),
|
||||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json
|
||||
})
|
||||
}
|
||||
|
||||
if (changedKeys.length > 0) {
|
||||
await setOutput({
|
||||
key: 'changed_keys',
|
||||
value: changedKeys.join(inputs.separator),
|
||||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir,
|
||||
json: inputs.json
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
|
||||
core.startGroup('changed-files-all')
|
||||
await setChangedFilesOutput({
|
||||
await setOutputsAndGetModifiedAndChangedFilesStatus({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles: allDiffFiles,
|
||||
inputs
|
||||
|
|
|
@ -19,7 +19,7 @@ const getArrayFromPaths = (
|
|||
return Array.isArray(paths) ? paths : paths.split(inputs.separator)
|
||||
}
|
||||
|
||||
export const setChangedFilesOutput = async ({
|
||||
export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
|
@ -31,7 +31,7 @@ export const setChangedFilesOutput = async ({
|
|||
inputs: Inputs
|
||||
filePatterns?: string[]
|
||||
outputPrefix?: string
|
||||
}): Promise<void> => {
|
||||
}): Promise<{anyModified: boolean; anyChanged: boolean}> => {
|
||||
const addedFiles = await getChangeTypeFiles({
|
||||
inputs,
|
||||
changedFiles: allFilteredDiffFiles,
|
||||
|
@ -474,4 +474,9 @@ export const setChangedFilesOutput = async ({
|
|||
writeOutputFiles: inputs.writeOutputFiles,
|
||||
outputDir: inputs.outputDir
|
||||
})
|
||||
|
||||
return {
|
||||
anyModified: allModifiedFiles.paths.length > 0 && filePatterns.length > 0,
|
||||
anyChanged: allChangedFiles.paths.length > 0 && filePatterns.length > 0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue