Skip to content

Commit 70ae405

Browse files
committed
Improve
1 parent 8ec19b9 commit 70ae405

File tree

11 files changed

+123
-74
lines changed

11 files changed

+123
-74
lines changed

.github/actions/reports-group/create/dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/reports-group/create/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/reports-group/create/index.js

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !
2-
const io = require('@actions/io'); // @TODO move to 'imports from' when moved to TS !
31
const path = require('path'); // @TODO move to 'imports from' when moved to TS !
42
const fs = require('fs'); // @TODO move to 'imports from' when moved to TS !
53

6-
const {path: pathSDK, glob: globSDK, CONSTANTS: SDK_CONSTANTS} = require('./node-sdk');
4+
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !
5+
const io = require('@actions/io'); // @TODO move to 'imports from' when moved to TS !
6+
7+
const {path: pathSDK, glob: globSDK, CONSTANTS: SDK_CONSTANTS} = require('./node-sdk'); // @TODO move to 'imports from' when moved to TS !
78

89
async function run() {
910
/** INPUTS **/
@@ -15,18 +16,16 @@ async function run() {
1516
const FLAG_LIST_INPUT = core.getMultilineInput('flags', {required: true});
1617
const FOLLOW_SYMLINK_INPUT = core.getBooleanInput('follow-symbolic-links', {required: true});
1718

18-
/** resolve-directory **/
1919
const groupDirectory = await core.group(
2020
'Resolve group directory path',
2121
async () => {
22-
const dir = path.resolve(PATH_INPUT, NAME_INPUT)
23-
core.info('group directory=' + dir);
22+
const res = path.resolve(PATH_INPUT, NAME_INPUT);
23+
core.info('group directory=' + res);
2424

25-
return dir;
25+
return res;
2626
}
2727
);
2828

29-
/** resolve-files **/
3029
const originalReportPaths = await core.group(
3130
'Resolve reports',
3231
async () => {
@@ -40,11 +39,11 @@ async function run() {
4039
}
4140
);
4241
core.debug('reports to copy=' + JSON.stringify(originalReportPaths));
42+
4343
if (0 === originalReportPaths.length) {
4444
core.setFailed('You must provide at least one report !');
4545
}
4646

47-
/** build-reports-map */
4847
const reportsMap = await core.group(
4948
'Build reports map',
5049
async () => {
@@ -60,19 +59,30 @@ async function run() {
6059
);
6160
core.debug('reports map=' + JSON.stringify(reportsMap));
6261

63-
/** build-metadata */
6462
const metadata = await core.group(
6563
'Build group metadata',
66-
async () => ({name: NAME_INPUT, format: FORMAT_INPUT, reports: reportsMap.map(v => v.filename), flags: FLAG_LIST_INPUT})
64+
async () => {
65+
return {
66+
name: NAME_INPUT,
67+
format: FORMAT_INPUT,
68+
reports: reportsMap.map(v => v.filename),
69+
flags: FLAG_LIST_INPUT
70+
};
71+
}
6772
);
6873
core.debug('metadata=' + JSON.stringify(metadata));
6974

70-
await core.group('Create group directory', () => io.mkdirP(groupDirectory));
75+
await core.group('Create group directory', () => {
76+
core.info('Create group directory at ' + groupDirectory);
77+
78+
return io.mkdirP(groupDirectory)
79+
});
7180

7281
await core.group(
7382
'Copy reports',
7483
async () => reportsMap.map(async ({source, dest}) => {
7584
core.info(source + ' => ' + dest);
85+
7686
return io.cp(source, dest);
7787
})
7888
);
@@ -85,12 +95,26 @@ async function run() {
8595
fs.writeFileSync(filepath, JSON.stringify(metadata));
8696
});
8797

88-
/** build-outputs */
89-
await core.group('Build outputs', () => {
90-
core.setOutput('path', groupDirectory);
91-
core.setOutput('reports', metadata.reports.join('\n'));
92-
core.setOutput('files', originalReportPaths.join('\n'));
93-
})
98+
const outputs = await core.group(
99+
'Build action outputs',
100+
async () => {
101+
const res = {};
102+
103+
core.info('Build path output');
104+
res.path = groupDirectory;
105+
core.info('Build reports output');
106+
res.reports = metadata.reports.join('\n');
107+
core.info('Build files output');
108+
res.files = originalReportPaths.join('\n');
109+
110+
return res;
111+
}
112+
);
113+
core.debug('outputs=' + JSON.stringify(outputs));
114+
Object.entries(outputs).map(([outputName, outputValue]) => {
115+
core.debug('Output ' + outputName + '=' +outputValue);
116+
core.setOutput(outputName, outputValue);
117+
});
94118
}
95119

96120
run();

.github/actions/reports-group/find/dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/reports-group/find/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/reports-group/find/index.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,37 @@ async function run() {
99
const GLUE_STRING_INPUT = core.getInput('glue-string', {required: true, trimWhitespace: false});
1010
const FOLLOW_SYMLINK_INPUT = core.getBooleanInput('follow-symbolic-links', {required: true});
1111

12-
/** Resolve paths **/
13-
const groupDirPathList = await findSdk.groupPaths(PATH_INPUT, {followSymbolicLinks: FOLLOW_SYMLINK_INPUT});
12+
const groupDirPathList = await core.group(
13+
'Find groups',
14+
async () => {
15+
const groupDirPathList = await findSdk.groupPaths(PATH_INPUT, {followSymbolicLinks: FOLLOW_SYMLINK_INPUT});
16+
17+
groupDirPathList.forEach(p => core.info('Found a reports group directory at ' + p));
18+
19+
return groupDirPathList;
20+
}
21+
);
22+
core.debug('groupDirPathList=' + JSON.stringify(groupDirPathList));
1423
if (0 === groupDirPathList.length) {
1524
core.setFailed('Unable to retrieve any group. Something wrong most likely happened !');
1625
}
17-
groupDirPathList.forEach(p => core.info('Found a reports group directory at ' + p));
18-
19-
/** Build action output **/
20-
core.setOutput(
21-
'list',
22-
'json' === FORMAT_INPUT
23-
? JSON.stringify(groupDirPathList)
24-
: groupDirPathList.join(GLUE_STRING_INPUT)
26+
27+
const outputs = await core.group(
28+
'Build action outputs',
29+
async () => {
30+
const res = {};
31+
32+
core.info('Build list output');
33+
res.list = 'json' === FORMAT_INPUT ? JSON.stringify(groupDirPathList) : groupDirPathList.join(GLUE_STRING_INPUT)
34+
35+
return res;
36+
}
2537
);
38+
core.debug('outputs=' + JSON.stringify(outputs));
39+
Object.entries(outputs).map(([outputName, outputValue]) => {
40+
core.debug('Output ' + outputName + '=' +outputValue);
41+
core.setOutput(outputName, outputValue);
42+
});
2643
}
2744

2845
run();

.github/actions/reports-group/load-metadata/dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/reports-group/load-metadata/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/reports-group/load-metadata/index.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ async function run() {
1111
const GLUE_STRING_INPUT = core.getInput('glue-string', {required: true, trimWhitespace: false});
1212
const FOLLOW_SYMLINK_INPUT = core.getBooleanInput('follow-symbolic-links', {required: true});
1313

14-
/** build-metadata **/
1514
const metadataList = await core.group(
1615
'Build metadata list',
1716
async () => {
@@ -20,43 +19,49 @@ async function run() {
2019
core.setFailed('Unable to retrieve any group. Something wrong most likely happened !');
2120
}
2221

23-
const res = Promise.all(
22+
return Promise.all(
2423
metadataPathList.map(async (fp) => {
2524
core.info('Load '+ fp);
2625

27-
const res = await loadSDK.metadataFile(fp);
28-
core.info('DEBUG RES FOR ' + fp + ' => ' + JSON.stringify(res));
29-
30-
return res;
26+
return loadSDK.metadataFile(fp);
3127
})
3228
);
29+
}
30+
);
31+
core.debug('metadataList=' + JSON.stringify(metadataList));
3332

34-
core.info('DEBUG RES => ' + JSON.stringify(res));
33+
const outputs = await core.group(
34+
'Build action outputs',
35+
async () => {
36+
const res = {};
37+
38+
core.info('Build metadata output');
39+
if ('json' === FORMAT_INPUT) {
40+
// Detect if provided `paths` was a group directory
41+
const isSingleMetadata = metadataList.length === 1 && path.resolve(metadataList[0].path) === path.resolve(PATH_INPUT);
42+
res.metadata = isSingleMetadata ? metadataList.shift() : metadataList;
43+
} else {
44+
const formatScalar = (key) => [...(new Set(metadataList.map(m => m[key]))).values()].join(GLUE_STRING_INPUT);
45+
const formatList = (key) => [...(new Set(metadataList.map(m => m[key]).flat())).values()].join(GLUE_STRING_INPUT);
46+
47+
res.metadata = {
48+
name: formatScalar('name'),
49+
format: formatScalar('format'),
50+
reports: formatList('reports'),
51+
flags: formatList('flags'),
52+
path: formatScalar('path'),
53+
reportPaths: formatList('reportPaths')
54+
};
55+
}
3556

3657
return res;
3758
}
3859
);
39-
core.info('DEBUG ' + JSON.stringify(metadataList));
40-
41-
/** Build action output **/
42-
if ('json' === FORMAT_INPUT) {
43-
// Detect if provided `paths` was a group directory
44-
const isSingleMetadata = metadataList.length === 1 && path.resolve(metadataList[0].path) === path.resolve(PATH_INPUT);
45-
const result = isSingleMetadata ? metadataList.shift() : metadataList;
46-
core.setOutput('metadata', JSON.stringify(result));
47-
} else {
48-
const formatScalar = (key) => [...(new Set(metadataList.map(m => m[key]))).values()].join(GLUE_STRING_INPUT);
49-
const formatList = (key) => [...(new Set(metadataList.map(m => m[key]).flat())).values()].join(GLUE_STRING_INPUT);
50-
const result = {
51-
name: formatScalar('name'),
52-
format: formatScalar('format'),
53-
reports: formatList('reports'),
54-
flags: formatList('flags'),
55-
path: formatScalar('path'),
56-
reportPaths: formatList('reportPaths')
57-
};
58-
core.setOutput('metadata', JSON.stringify(result));
59-
}
60+
core.debug('outputs=' + JSON.stringify(outputs));
61+
Object.entries(outputs).map(([outputName, outputValue]) => {
62+
core.debug('Output ' + outputName + '=' +outputValue);
63+
core.setOutput(outputName, outputValue);
64+
});
6065
}
6166

6267
run();

.github/actions/reports-group/node-sdk/src/find.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !
21
const path = require('path'); // @TODO move to 'imports from' when moved to TS !
32

3+
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !
4+
45
const {METADATA_FILENAME} = require('./constants');
56
const globHelper = require('./glob-helper');
67
const pathHelper = require('./path-helper');
@@ -17,7 +18,7 @@ export async function groupPaths(globPattern, options = undefined) {
1718

1819
export async function metadataPaths(globPattern, options = undefined) {
1920
const finalPattern = globPattern.split('\n').map(item => path.join(item.trim(), '**', METADATA_FILENAME)).join('\n');
20-
core.debug('findGroupPaths glob: ' + globPattern);
21+
core.debug('Find metadata paths with ' + globPattern);
2122

2223
const list = [];
2324
for await (const fp of globHelper.lookup(finalPattern, options)) {

0 commit comments

Comments
 (0)