3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-01-17 19:17:45 +00:00

chore: simplify code (#1439)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack 2023-08-07 00:00:11 -06:00 committed by GitHub
parent 312a3d8003
commit 0acc1c308e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 12 deletions

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View file

@ -315,7 +315,14 @@ describe('utils test', () => {
// Tests that the function returns only the files that match the file patterns // Tests that the function returns only the files that match the file patterns
it('should return only the files that match the file patterns', async () => { it('should return only the files that match the file patterns', async () => {
const allDiffFiles = { const allDiffFiles = {
[ChangeTypeEnum.Added]: ['file1.txt', 'file2.md', 'file3.txt'], [ChangeTypeEnum.Added]: [
'file1.txt',
'file2.md',
'file3.txt',
'test/dir/file4.txt',
'/test/dir/file5.txt',
'dir/file6.md'
],
[ChangeTypeEnum.Copied]: [], [ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [], [ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [], [ChangeTypeEnum.Modified]: [],

View file

@ -6,7 +6,7 @@ import {
getChangeTypeFiles getChangeTypeFiles
} from './changedFiles' } from './changedFiles'
import {Inputs} from './inputs' import {Inputs} from './inputs'
import {getFilteredChangedFiles, setOutput} from './utils' import {setOutput} from './utils'
const getOutputKey = (key: string, outputPrefix: string): string => { const getOutputKey = (key: string, outputPrefix: string): string => {
return outputPrefix ? `${outputPrefix}_${key}` : key return outputPrefix ? `${outputPrefix}_${key}` : key
@ -14,21 +14,17 @@ const getOutputKey = (key: string, outputPrefix: string): string => {
export const setChangedFilesOutput = async ({ export const setChangedFilesOutput = async ({
allDiffFiles, allDiffFiles,
allFilteredDiffFiles,
inputs, inputs,
filePatterns = [], filePatterns = [],
outputPrefix = '' outputPrefix = ''
}: { }: {
allDiffFiles: ChangedFiles allDiffFiles: ChangedFiles
allFilteredDiffFiles: ChangedFiles
inputs: Inputs inputs: Inputs
filePatterns?: string[] filePatterns?: string[]
outputPrefix?: string outputPrefix?: string
}): Promise<void> => { }): Promise<void> => {
const allFilteredDiffFiles = await getFilteredChangedFiles({
allDiffFiles,
filePatterns
})
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`)
const addedFiles = await getChangeTypeFiles({ const addedFiles = await getChangeTypeFiles({
inputs, inputs,
changedFiles: allFilteredDiffFiles, changedFiles: allFilteredDiffFiles,

View file

@ -18,6 +18,7 @@ import {Env, getEnv} from './env'
import {getInputs, Inputs} from './inputs' import {getInputs, Inputs} from './inputs'
import { import {
getFilePatterns, getFilePatterns,
getFilteredChangedFiles,
getRecoverFilePatterns, getRecoverFilePatterns,
getSubmodulePath, getSubmodulePath,
getYamlFilePatterns, getYamlFilePatterns,
@ -43,10 +44,18 @@ const changedFilesOutput = async ({
}): Promise<void> => { }): Promise<void> => {
if (filePatterns.length > 0) { if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns') core.startGroup('changed-files-patterns')
const allFilteredDiffFiles = await getFilteredChangedFiles({
allDiffFiles,
filePatterns
})
core.debug(
`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`
)
await setChangedFilesOutput({ await setChangedFilesOutput({
allDiffFiles, allDiffFiles,
filePatterns, allFilteredDiffFiles,
inputs inputs,
filePatterns
}) })
core.info('All Done!') core.info('All Done!')
core.endGroup() core.endGroup()
@ -55,11 +64,21 @@ const changedFilesOutput = async ({
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}`)
const allFilteredDiffFiles = await getFilteredChangedFiles({
allDiffFiles,
filePatterns: yamlFilePatterns[key]
})
core.debug(
`All filtered diff files for ${key}: ${JSON.stringify(
allFilteredDiffFiles
)}`
)
await setChangedFilesOutput({ await setChangedFilesOutput({
allDiffFiles, allDiffFiles,
allFilteredDiffFiles,
inputs,
filePatterns: yamlFilePatterns[key], filePatterns: yamlFilePatterns[key],
outputPrefix: key, outputPrefix: key
inputs
}) })
core.info('All Done!') core.info('All Done!')
core.endGroup() core.endGroup()
@ -70,6 +89,7 @@ const changedFilesOutput = async ({
core.startGroup('changed-files-all') core.startGroup('changed-files-all')
await setChangedFilesOutput({ await setChangedFilesOutput({
allDiffFiles, allDiffFiles,
allFilteredDiffFiles: allDiffFiles,
inputs inputs
}) })
core.info('All Done!') core.info('All Done!')