chore: simplify code (#1439)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
312a3d8003
commit
0acc1c308e
28
dist/index.js
generated
vendored
28
dist/index.js
generated
vendored
@ -326,12 +326,7 @@ const utils_1 = __nccwpck_require__(918);
|
||||
const getOutputKey = (key, outputPrefix) => {
|
||||
return outputPrefix ? `${outputPrefix}_${key}` : key;
|
||||
};
|
||||
const setChangedFilesOutput = ({ allDiffFiles, inputs, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||
allDiffFiles,
|
||||
filePatterns
|
||||
});
|
||||
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`);
|
||||
const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, inputs, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
|
||||
inputs,
|
||||
changedFiles: allFilteredDiffFiles,
|
||||
@ -1364,10 +1359,16 @@ const utils_1 = __nccwpck_require__(918);
|
||||
const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
if (filePatterns.length > 0) {
|
||||
core.startGroup('changed-files-patterns');
|
||||
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||
allDiffFiles,
|
||||
filePatterns
|
||||
});
|
||||
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`);
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
filePatterns,
|
||||
inputs
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns
|
||||
});
|
||||
core.info('All Done!');
|
||||
core.endGroup();
|
||||
@ -1375,11 +1376,17 @@ const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatter
|
||||
if (Object.keys(yamlFilePatterns).length > 0) {
|
||||
for (const key of Object.keys(yamlFilePatterns)) {
|
||||
core.startGroup(`changed-files-yaml-${key}`);
|
||||
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||
allDiffFiles,
|
||||
filePatterns: yamlFilePatterns[key]
|
||||
});
|
||||
core.debug(`All filtered diff files for ${key}: ${JSON.stringify(allFilteredDiffFiles)}`);
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns: yamlFilePatterns[key],
|
||||
outputPrefix: key,
|
||||
inputs
|
||||
outputPrefix: key
|
||||
});
|
||||
core.info('All Done!');
|
||||
core.endGroup();
|
||||
@ -1389,6 +1396,7 @@ const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatter
|
||||
core.startGroup('changed-files-all');
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles: allDiffFiles,
|
||||
inputs
|
||||
});
|
||||
core.info('All Done!');
|
||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -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]: [],
|
||||
|
@ -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,
|
||||
|
28
src/main.ts
28
src/main.ts
@ -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!')
|
||||
|
Loading…
x
Reference in New Issue
Block a user