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
it('should return only the files that match the file patterns', async () => {
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.Deleted]: [],
[ChangeTypeEnum.Modified]: [],

View file

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

View file

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