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) => {
|
const getOutputKey = (key, outputPrefix) => {
|
||||||
return outputPrefix ? `${outputPrefix}_${key}` : key;
|
return outputPrefix ? `${outputPrefix}_${key}` : key;
|
||||||
};
|
};
|
||||||
const setChangedFilesOutput = ({ allDiffFiles, inputs, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () {
|
const setChangedFilesOutput = ({ allDiffFiles, allFilteredDiffFiles, 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 addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
|
const addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
|
||||||
inputs,
|
inputs,
|
||||||
changedFiles: allFilteredDiffFiles,
|
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* () {
|
const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
if (filePatterns.length > 0) {
|
if (filePatterns.length > 0) {
|
||||||
core.startGroup('changed-files-patterns');
|
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)({
|
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
filePatterns,
|
allFilteredDiffFiles,
|
||||||
inputs
|
inputs,
|
||||||
|
filePatterns
|
||||||
});
|
});
|
||||||
core.info('All Done!');
|
core.info('All Done!');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
@ -1375,11 +1376,17 @@ const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatter
|
|||||||
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 = 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)({
|
yield (0, changedFilesOutput_1.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();
|
||||||
@ -1389,6 +1396,7 @@ const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatter
|
|||||||
core.startGroup('changed-files-all');
|
core.startGroup('changed-files-all');
|
||||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
|
allFilteredDiffFiles: allDiffFiles,
|
||||||
inputs
|
inputs
|
||||||
});
|
});
|
||||||
core.info('All Done!');
|
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
|
// 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]: [],
|
||||||
|
@ -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,
|
||||||
|
28
src/main.ts
28
src/main.ts
@ -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!')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user