Skip to content

Commit

Permalink
test table
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed May 2, 2024
1 parent 958f0a9 commit 3d1eb0d
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {getExpiration} from '@actions/artifact/lib/internal/upload/retention';
import {InvalidResponseError, NetworkError} from '@actions/artifact';
import * as core from '@actions/core';
import * as github from '@actions/github';
import {SummaryTableCell} from '@actions/core/lib/summary';
import {GitHub as Octokit} from '@actions/github/lib/utils';
import {Context} from '@actions/github/lib/context';
import {TransferProgressEvent} from '@azure/core-http';
Expand Down Expand Up @@ -217,13 +218,14 @@ export class GitHub {
.addBreak()
.addRaw(`This will give you insights of your build, such as timing, dependencies, results, logs, traces and more!</p>`);

if (Object.keys(opts.exportRes.summaries).length > 1) {
const summarySize = Object.keys(opts.exportRes.summaries).length;
if (summarySize > 1) {
sum.addRaw(downloadText);
}

sum.addHeading('Details preview', 2);

if (Object.keys(opts.exportRes.summaries).length === 1) {
if (summarySize === 1) {
const [ref, summary] = Object.entries(opts.exportRes.summaries)[0];
sum.addHeading(`<code>${summary.name}</code>`, 3);
const summaryTableData: Array<Array<string>> = [
Expand All @@ -239,7 +241,7 @@ export class GitHub {
sum.addHeading('Error', 4);
sum.addCodeBlock(summary.error, 'text');
}
} else {
} else if (summarySize < 4) {
for (const ref in opts.exportRes.summaries) {
if (Object.prototype.hasOwnProperty.call(opts.exportRes.summaries, ref)) {
const summary = opts.exportRes.summaries[ref];
Expand All @@ -257,6 +259,33 @@ export class GitHub {
}
}
}
} else {
const summaryTableData: Array<Array<SummaryTableCell>> = [
[
{header: true, data: 'ID'},
{header: true, data: 'Name'},
{header: true, data: 'Status'},
{header: true, data: 'Duration'},
{header: true, data: 'Cached'}
]
];
for (const ref in opts.exportRes.summaries) {
if (Object.prototype.hasOwnProperty.call(opts.exportRes.summaries, ref)) {
const summary = opts.exportRes.summaries[ref];
summaryTableData.push([
{data: `<img src="https://img.shields.io/badge/${ref.substring(0, 6).toUpperCase()}-7B91A7">`},
{data: `<code>${summary.name}</code>`},
{data: `${summary.status === 'completed' ? ':white_check_mark:' : summary.status === 'canceled' ? ':no_entry_sign:' : ':x:'} ${summary.status}`},
{data: summary.duration},
{data: `${summary.numCachedSteps > 0 ? Math.round((summary.numCachedSteps / summary.numTotalSteps) * 100) : 0}%`}
]);
sum.addTable([...summaryTableData]);
if (summary.error) {
sum.addHeading('Error', 4);
sum.addCodeBlock(summary.error, 'text');
}
}
}
}

if (opts.inputs) {
Expand Down

0 comments on commit 3d1eb0d

Please sign in to comment.