Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanm committed Mar 19, 2024
1 parent 8ec19b9 commit 3e8f2cf
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/actions/reports-group/create/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/actions/reports-group/create/dist/index.js.map

Large diffs are not rendered by default.

62 changes: 43 additions & 19 deletions .github/actions/reports-group/create/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !
const io = require('@actions/io'); // @TODO move to 'imports from' when moved to TS !
const path = require('path'); // @TODO move to 'imports from' when moved to TS !
const fs = require('fs'); // @TODO move to 'imports from' when moved to TS !

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

const {path: pathSDK, glob: globSDK, outputs: outputsSDK, CONSTANTS: SDK_CONSTANTS} = require('./node-sdk'); // @TODO move to 'imports from' when moved to TS !

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

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

return dir;
return res;
}
);

/** resolve-files **/
const originalReportPaths = await core.group(
'Resolve reports',
async () => {
Expand All @@ -40,11 +39,11 @@ async function run() {
}
);
core.debug('reports to copy=' + JSON.stringify(originalReportPaths));

if (0 === originalReportPaths.length) {
core.setFailed('You must provide at least one report !');
}

/** build-reports-map */
const reportsMap = await core.group(
'Build reports map',
async () => {
Expand All @@ -60,19 +59,33 @@ async function run() {
);
core.debug('reports map=' + JSON.stringify(reportsMap));

/** build-metadata */
const metadata = await core.group(
'Build group metadata',
async () => ({name: NAME_INPUT, format: FORMAT_INPUT, reports: reportsMap.map(v => v.filename), flags: FLAG_LIST_INPUT})
async () => {
const res = {
name: NAME_INPUT,
format: FORMAT_INPUT,
reports: reportsMap.map(v => v.filename),
flags: FLAG_LIST_INPUT
};
core.info('Created');

return res;
}
);
core.debug('metadata=' + JSON.stringify(metadata));

await core.group('Create group directory', () => io.mkdirP(groupDirectory));
await core.group('Create group directory', () => {
core.info('Create group directory at ' + groupDirectory);

return io.mkdirP(groupDirectory)
});

await core.group(
'Copy reports',
async () => reportsMap.map(async ({source, dest}) => {
core.info(source + ' => ' + dest);

return io.cp(source, dest);
})
);
Expand All @@ -81,16 +94,27 @@ async function run() {
'Create metadata file',
async () => {
const filepath = path.join(groupDirectory, SDK_CONSTANTS.METADATA_FILENAME);
core.debug('Create metadata file at ' + filepath + ' with: ' + JSON.stringify(metadata));
core.info('Create metadata file at ' + filepath + ' with: ' + JSON.stringify(metadata));
fs.writeFileSync(filepath, JSON.stringify(metadata));
});

/** build-outputs */
await core.group('Build outputs', () => {
core.setOutput('path', groupDirectory);
core.setOutput('reports', metadata.reports.join('\n'));
core.setOutput('files', originalReportPaths.join('\n'));
})
const outputs = await core.group(
'Build action outputs',
async () => {
const res = {};

core.info("Build 'path' output");
res.path = groupDirectory;
core.info("Build 'reports' output");
res.reports = metadata.reports.join('\n');
core.info("Build 'files' output");
res.files = originalReportPaths.join('\n');

return res;
}
);
core.debug('outputs=' + JSON.stringify(outputs));
outputsSDK.bindActionOutputs(outputs);
}

run();
4 changes: 2 additions & 2 deletions .github/actions/reports-group/find/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/actions/reports-group/find/dist/index.js.map

Large diffs are not rendered by default.

37 changes: 26 additions & 11 deletions .github/actions/reports-group/find/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !
const {find: findSdk} = require('./node-sdk'); // @TODO move to 'imports from' when moved to TS !

const {find: findSdk, outputs: outputsSDK} = require('./node-sdk'); // @TODO move to 'imports from' when moved to TS !

async function run() {
/** INPUTS **/
Expand All @@ -9,20 +10,34 @@ async function run() {
const GLUE_STRING_INPUT = core.getInput('glue-string', {required: true, trimWhitespace: false});
const FOLLOW_SYMLINK_INPUT = core.getBooleanInput('follow-symbolic-links', {required: true});

/** Resolve paths **/
const groupDirPathList = await findSdk.groupPaths(PATH_INPUT, {followSymbolicLinks: FOLLOW_SYMLINK_INPUT});
const groupDirPathList = await core.group(
'Find groups',
async () => {
const groupDirPathList = await findSdk.groupPaths(PATH_INPUT, {followSymbolicLinks: FOLLOW_SYMLINK_INPUT});

groupDirPathList.forEach(p => core.info('Found a reports group directory at ' + p));

return groupDirPathList;
}
);
core.debug('groupDirPathList=' + JSON.stringify(groupDirPathList));
if (0 === groupDirPathList.length) {
core.setFailed('Unable to retrieve any group. Something wrong most likely happened !');
}
groupDirPathList.forEach(p => core.info('Found a reports group directory at ' + p));

/** Build action output **/
core.setOutput(
'list',
'json' === FORMAT_INPUT
? JSON.stringify(groupDirPathList)
: groupDirPathList.join(GLUE_STRING_INPUT)

const outputs = await core.group(
'Build action outputs',
async () => {
const res = {};

core.info("Build 'list' output");
res.list = 'json' === FORMAT_INPUT ? JSON.stringify(groupDirPathList) : groupDirPathList.join(GLUE_STRING_INPUT)

return res;
}
);
core.debug('outputs=' + JSON.stringify(outputs));
outputsSDK.bindActionOutputs(outputs);
}

run();
4 changes: 2 additions & 2 deletions .github/actions/reports-group/load-metadata/dist/index.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

63 changes: 33 additions & 30 deletions .github/actions/reports-group/load-metadata/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !
const path = require('path'); // @TODO move to 'imports from' when moved to TS !

const {find: findSDK, load: loadSDK} = require('./node-sdk');
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !

const {find: findSDK, load: loadSDK, outputs: outputsSDK} = require('./node-sdk');

async function run() {
/** INPUTS **/
Expand All @@ -11,7 +12,6 @@ async function run() {
const GLUE_STRING_INPUT = core.getInput('glue-string', {required: true, trimWhitespace: false});
const FOLLOW_SYMLINK_INPUT = core.getBooleanInput('follow-symbolic-links', {required: true});

/** build-metadata **/
const metadataList = await core.group(
'Build metadata list',
async () => {
Expand All @@ -20,43 +20,46 @@ async function run() {
core.setFailed('Unable to retrieve any group. Something wrong most likely happened !');
}

const res = Promise.all(
return Promise.all(
metadataPathList.map(async (fp) => {
core.info('Load '+ fp);

const res = await loadSDK.metadataFile(fp);
core.info('DEBUG RES FOR ' + fp + ' => ' + JSON.stringify(res));

return res;
return loadSDK.metadataFile(fp);
})
);
}
);
core.debug('metadataList=' + JSON.stringify(metadataList));

const outputs = await core.group(
'Build action outputs',
async () => {
const res = {};

core.info('DEBUG RES => ' + JSON.stringify(res));
core.info("Build 'metadata' output");
if ('json' === FORMAT_INPUT) {
// Detect if provided `paths` was a group directory
const isSingleMetadata = metadataList.length === 1 && path.resolve(metadataList[0].path) === path.resolve(PATH_INPUT);
res.metadata = isSingleMetadata ? metadataList.shift() : metadataList;
} else {
const formatScalar = (key) => [...(new Set(metadataList.map(m => m[key]))).values()].join(GLUE_STRING_INPUT);
const formatList = (key) => [...(new Set(metadataList.map(m => m[key]).flat())).values()].join(GLUE_STRING_INPUT);

res.metadata = {
name: formatScalar('name'),
format: formatScalar('format'),
reports: formatList('reports'),
flags: formatList('flags'),
path: formatScalar('path'),
reportPaths: formatList('reportPaths')
};
}

return res;
}
);
core.info('DEBUG ' + JSON.stringify(metadataList));

/** Build action output **/
if ('json' === FORMAT_INPUT) {
// Detect if provided `paths` was a group directory
const isSingleMetadata = metadataList.length === 1 && path.resolve(metadataList[0].path) === path.resolve(PATH_INPUT);
const result = isSingleMetadata ? metadataList.shift() : metadataList;
core.setOutput('metadata', JSON.stringify(result));
} else {
const formatScalar = (key) => [...(new Set(metadataList.map(m => m[key]))).values()].join(GLUE_STRING_INPUT);
const formatList = (key) => [...(new Set(metadataList.map(m => m[key]).flat())).values()].join(GLUE_STRING_INPUT);
const result = {
name: formatScalar('name'),
format: formatScalar('format'),
reports: formatList('reports'),
flags: formatList('flags'),
path: formatScalar('path'),
reportPaths: formatList('reportPaths')
};
core.setOutput('metadata', JSON.stringify(result));
}
core.debug('outputs=' + JSON.stringify(outputs));
outputsSDK.bindActionOutputs(outputs);
}

run();
1 change: 1 addition & 0 deletions .github/actions/reports-group/node-sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as glob from './src/glob-helper'
export * as path from './src/path-helper'
export * as find from './src/find'
export * as load from './src/load'
export * as outputs from './src/outputs'
5 changes: 3 additions & 2 deletions .github/actions/reports-group/node-sdk/src/find.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !
const path = require('path'); // @TODO move to 'imports from' when moved to TS !

const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !

const {METADATA_FILENAME} = require('./constants');
const globHelper = require('./glob-helper');
const pathHelper = require('./path-helper');
Expand All @@ -17,7 +18,7 @@ export async function groupPaths(globPattern, options = undefined) {

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

const list = [];
for await (const fp of globHelper.lookup(finalPattern, options)) {
Expand Down
15 changes: 9 additions & 6 deletions .github/actions/reports-group/node-sdk/src/load.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const fs = require('fs'); // @TODO move to 'imports from' when moved to TS !
const path = require('path'); // @TODO move to 'imports from' when moved to TS !

const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !

export async function metadataFile(fp) {
const content = fs.readFileSync(fp);
console.log('DEBUG metadataFile(' + fp + ') => content=' + content);
core.debug(fp + ' content=' + content);

const metadata = JSON.parse(content);
const groupPath = path.dirname(fp);
console.log('DEBUG metadataFile(' + fp + ') => group path=' + groupPath);

const res = {...metadata, path: groupPath, reportPaths: metadata.reports.map(r => path.join(groupPath, r))};
console.log('DEBUG metadataFile(' + fp + ') => res=' + JSON.stringify(res));

return res;
return {
...metadata,
path: groupPath,
reportPaths: metadata.reports.map(r => path.join(groupPath, r))
};
}
8 changes: 8 additions & 0 deletions .github/actions/reports-group/node-sdk/src/outputs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const core = require('@actions/core'); // @TODO move to 'imports from' when moved to TS !

export function bindActionOutputs(outputs) {
Object.entries(outputs).map(([outputName, outputValue]) => {
core.debug('Output ' + outputName + '=' +outputValue);
core.setOutput(outputName, outputValue);
});
}
2 changes: 1 addition & 1 deletion .github/workflows/codacy-upload-from-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
echo 'outcome='"'"'${{ steps.upload.outcome }}'"'"
echo 'conclusion='"'"'${{ steps.upload.conclusion }}'"'"
echo 'outputs='"'"'${{ toJson(steps.upload.outputs) }}'"'"
echo 'uploaded-reports='"'"'${{ steps.upload.outputs.reports }}'"'"
echo 'reports='"'"'${{ steps.upload.outputs.reports }}'"'"

0 comments on commit 3e8f2cf

Please sign in to comment.