3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-01-06 23:50:50 +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:
Tonye Jack 2023-09-18 14:17:46 -06:00 committed by GitHub
parent a17e8c5252
commit 5db7b578d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 14 deletions

View file

@ -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 }}" echo "Expected: (test/test deleted.txt) got ${{ steps.changed-files-recover-deleted-files-with-files-yaml.outputs.test_deleted_files }}"
exit 1 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 - name: Verify that test/test deleted.txt is restored
run: | run: |
if [ ! -f "test/test deleted.txt" ]; then if [ ! -f "test/test deleted.txt" ]; then

View file

@ -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)*" 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: other_deleted_files_count:
description: "Returns the number of `other_deleted_files`" 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: runs:
using: 'node20' using: 'node20'

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View file

@ -4,7 +4,7 @@ import type {RestEndpointMethodTypes} from '@octokit/rest'
import flatten from 'lodash/flatten' import flatten from 'lodash/flatten'
import mm from 'micromatch' import mm from 'micromatch'
import * as path from 'path' import * as path from 'path'
import {setChangedFilesOutput} from './changedFilesOutput' import {setOutputsAndGetModifiedAndChangedFilesStatus} from './changedFilesOutput'
import {DiffResult} from './commitSha' import {DiffResult} from './commitSha'
import {Inputs} from './inputs' import {Inputs} from './inputs'
import { import {
@ -16,7 +16,8 @@ import {
gitRenamedFiles, gitRenamedFiles,
gitSubmoduleDiffSHA, gitSubmoduleDiffSHA,
isWindows, isWindows,
jsonOutput jsonOutput,
setOutput
} from './utils' } from './utils'
export const processChangedFiles = async ({ export const processChangedFiles = async ({
@ -39,7 +40,7 @@ export const processChangedFiles = async ({
core.debug( core.debug(
`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}` `All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`
) )
await setChangedFilesOutput({ await setOutputsAndGetModifiedAndChangedFilesStatus({
allDiffFiles, allDiffFiles,
allFilteredDiffFiles, allFilteredDiffFiles,
inputs, inputs,
@ -49,6 +50,9 @@ export const processChangedFiles = async ({
core.endGroup() core.endGroup()
} }
const modifiedKeys: string[] = []
const changedKeys: string[] = []
if (Object.keys(yamlFilePatterns).length > 0) { if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) { for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`) core.startGroup(`changed-files-yaml-${key}`)
@ -61,21 +65,49 @@ export const processChangedFiles = async ({
allFilteredDiffFiles allFilteredDiffFiles
)}` )}`
) )
await setChangedFilesOutput({ const {anyChanged, anyModified} =
await setOutputsAndGetModifiedAndChangedFilesStatus({
allDiffFiles, allDiffFiles,
allFilteredDiffFiles, allFilteredDiffFiles,
inputs, inputs,
filePatterns: yamlFilePatterns[key], filePatterns: yamlFilePatterns[key],
outputPrefix: key outputPrefix: key
}) })
if (anyModified) {
modifiedKeys.push(key)
}
if (anyChanged) {
changedKeys.push(key)
}
core.info('All Done!') core.info('All Done!')
core.endGroup() 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) { if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all') core.startGroup('changed-files-all')
await setChangedFilesOutput({ await setOutputsAndGetModifiedAndChangedFilesStatus({
allDiffFiles, allDiffFiles,
allFilteredDiffFiles: allDiffFiles, allFilteredDiffFiles: allDiffFiles,
inputs inputs

View file

@ -19,7 +19,7 @@ const getArrayFromPaths = (
return Array.isArray(paths) ? paths : paths.split(inputs.separator) return Array.isArray(paths) ? paths : paths.split(inputs.separator)
} }
export const setChangedFilesOutput = async ({ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
allDiffFiles, allDiffFiles,
allFilteredDiffFiles, allFilteredDiffFiles,
inputs, inputs,
@ -31,7 +31,7 @@ export const setChangedFilesOutput = async ({
inputs: Inputs inputs: Inputs
filePatterns?: string[] filePatterns?: string[]
outputPrefix?: string outputPrefix?: string
}): Promise<void> => { }): Promise<{anyModified: boolean; anyChanged: boolean}> => {
const addedFiles = await getChangeTypeFiles({ const addedFiles = await getChangeTypeFiles({
inputs, inputs,
changedFiles: allFilteredDiffFiles, changedFiles: allFilteredDiffFiles,
@ -474,4 +474,9 @@ export const setChangedFilesOutput = async ({
writeOutputFiles: inputs.writeOutputFiles, writeOutputFiles: inputs.writeOutputFiles,
outputDir: inputs.outputDir outputDir: inputs.outputDir
}) })
return {
anyModified: allModifiedFiles.paths.length > 0 && filePatterns.length > 0,
anyChanged: allChangedFiles.paths.length > 0 && filePatterns.length > 0
}
} }