From 58235081c9622146a117a10a13e8366978cbe0c9 Mon Sep 17 00:00:00 2001 From: Robi Nino Date: Mon, 29 Jul 2024 09:37:39 +0300 Subject: [PATCH] Reorder job summary sections (#176) --- lib/utils.js | 26 +++++++++++++++----------- src/utils.ts | 27 ++++++++++++++++----------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 536471130..ad1bca7d3 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -494,19 +494,23 @@ class Utils { return __awaiter(this, void 0, void 0, function* () { const outputDir = Utils.getJobOutputDirectoryPath(); let markdownContent = ''; + const sectionContents = {}; + // Read all sections. for (const sectionName of Utils.JOB_SUMMARY_MARKDOWN_SECTIONS_NAMES) { const fullPath = path.join(outputDir, sectionName, 'markdown.md'); - // Check file exists - if (!(0, fs_1.existsSync)(fullPath)) { - continue; + if ((0, fs_1.existsSync)(fullPath)) { + sectionContents[sectionName] = yield Utils.readSummarySection(fullPath, sectionName); } - markdownContent += yield Utils.readSummarySection(fullPath, sectionName); } - // No section was added, return empty string - if (markdownContent == '') { - return ''; + // If build info was published, remove generic upload section to avoid duplications with generic modules. + if (sectionContents[MarkdownSection.BuildInfo] != '') { + sectionContents[MarkdownSection.Upload] = ''; } - return Utils.wrapContent(markdownContent); + // Append sections in order. + for (const sectionName of Utils.JOB_SUMMARY_MARKDOWN_SECTIONS_NAMES) { + markdownContent += sectionContents[sectionName] || ''; + } + return markdownContent ? Utils.wrapContent(markdownContent) : ''; }); } static readSummarySection(fullPath, section) { @@ -623,11 +627,11 @@ Utils.LATEST_RELEASE_VERSION = '[RELEASE]'; Utils.SETUP_JFROG_CLI_SERVER_ID = 'setup-jfrog-cli-server'; // Directory name which holds markdown files for the Workflow summary Utils.JOB_SUMMARY_DIR_NAME = 'jfrog-command-summary'; -// Workflow summary section files +// Workflow summary section files. Order of sections in this array impacts the order in the final markdown. Utils.JOB_SUMMARY_MARKDOWN_SECTIONS_NAMES = [ - MarkdownSection.Upload, - MarkdownSection.BuildInfo, MarkdownSection.Security, + MarkdownSection.BuildInfo, + MarkdownSection.Upload, ]; // Inputs // Version input diff --git a/src/utils.ts b/src/utils.ts index 50da05623..0c540f705 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -36,11 +36,11 @@ export class Utils { public static readonly SETUP_JFROG_CLI_SERVER_ID: string = 'setup-jfrog-cli-server'; // Directory name which holds markdown files for the Workflow summary private static readonly JOB_SUMMARY_DIR_NAME: string = 'jfrog-command-summary'; - // Workflow summary section files + // Workflow summary section files. Order of sections in this array impacts the order in the final markdown. public static JOB_SUMMARY_MARKDOWN_SECTIONS_NAMES: MarkdownSection[] = [ - MarkdownSection.Upload, - MarkdownSection.BuildInfo, MarkdownSection.Security, + MarkdownSection.BuildInfo, + MarkdownSection.Upload, ]; // Inputs @@ -533,22 +533,27 @@ export class Utils { private static async readCLIMarkdownSectionsAndWrap(): Promise { const outputDir: string = Utils.getJobOutputDirectoryPath(); let markdownContent: string = ''; + const sectionContents: { [key: string]: string } = {}; + // Read all sections. for (const sectionName of Utils.JOB_SUMMARY_MARKDOWN_SECTIONS_NAMES) { const fullPath: string = path.join(outputDir, sectionName, 'markdown.md'); - // Check file exists - if (!existsSync(fullPath)) { - continue; + if (existsSync(fullPath)) { + sectionContents[sectionName] = await Utils.readSummarySection(fullPath, sectionName); } - markdownContent += await Utils.readSummarySection(fullPath, sectionName); } - // No section was added, return empty string - if (markdownContent == '') { - return ''; + // If build info was published, remove generic upload section to avoid duplications with generic modules. + if (sectionContents[MarkdownSection.BuildInfo] != '') { + sectionContents[MarkdownSection.Upload] = ''; + } + + // Append sections in order. + for (const sectionName of Utils.JOB_SUMMARY_MARKDOWN_SECTIONS_NAMES) { + markdownContent += sectionContents[sectionName] || ''; } - return Utils.wrapContent(markdownContent); + return markdownContent ? Utils.wrapContent(markdownContent) : ''; } private static async readSummarySection(fullPath: string, section: MarkdownSection) {