Skip to content

Commit

Permalink
Reorder job summary sections (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNino authored Jul 29, 2024
1 parent 9a326ad commit 5823508
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
26 changes: 15 additions & 11 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -533,22 +533,27 @@ export class Utils {
private static async readCLIMarkdownSectionsAndWrap(): Promise<string> {
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) {
Expand Down

0 comments on commit 5823508

Please sign in to comment.