Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder job summary sections #176

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading