github: support multiple refs with build URL for summary
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -284,10 +284,10 @@ export class History {
|
|||||||
return {
|
return {
|
||||||
dockerbuildFilename: dockerbuildPath,
|
dockerbuildFilename: dockerbuildPath,
|
||||||
dockerbuildSize: dockerbuildStats.size,
|
dockerbuildSize: dockerbuildStats.size,
|
||||||
summaries: summaries,
|
|
||||||
builderName: builderName,
|
builderName: builderName,
|
||||||
nodeName: nodeName,
|
nodeName: nodeName,
|
||||||
refs: refs
|
refs: refs,
|
||||||
|
summaries: summaries
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,16 +234,20 @@ export class GitHub {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const refsSize = Object.keys(opts.exportRes.refs).length;
|
const refsSize = Object.keys(opts.exportRes.refs).length;
|
||||||
|
const singleRef = refsSize === 1 ? Object.keys(opts.exportRes.refs)[0] : undefined;
|
||||||
|
const singleSummary = singleRef && opts.exportRes.summaries?.[singleRef];
|
||||||
|
const dbcAccount = opts.driver === 'cloud' && opts.endpoint?.split('/')[0];
|
||||||
|
|
||||||
const sum = core.summary.addHeading('Docker Build summary', 2);
|
const sum = core.summary.addHeading('Docker Build summary', 2);
|
||||||
|
|
||||||
if (opts.buildURL) {
|
if (dbcAccount && singleRef && singleSummary) {
|
||||||
|
const buildURL = GitHub.formatDBCBuildURL(dbcAccount, singleRef, singleSummary.defaultPlatform);
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
sum.addRaw(`<p>`)
|
sum.addRaw(`<p>`)
|
||||||
.addRaw(`For a detailed look at the build, you can check the results at:`)
|
.addRaw(`For a detailed look at the build, you can check the results at:`)
|
||||||
.addRaw('</p>')
|
.addRaw('</p>')
|
||||||
.addRaw(`<p>`)
|
.addRaw(`<p>`)
|
||||||
.addRaw(`:whale: ${addLink(`<strong>${opts.buildURL}</strong>`, opts.buildURL)}`)
|
.addRaw(`:whale: ${addLink(`<strong>${buildURL}</strong>`, buildURL)}`)
|
||||||
.addRaw(`</p>`);
|
.addRaw(`</p>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +260,7 @@ export class GitHub {
|
|||||||
// https://github.com/docker/actions-toolkit/issues/367
|
// https://github.com/docker/actions-toolkit/issues/367
|
||||||
const artifactRelativeURL = `./${GitHub.runId}/${opts.uploadRes.url.split('/').slice(-2).join('/')}`;
|
const artifactRelativeURL = `./${GitHub.runId}/${opts.uploadRes.url.split('/').slice(-2).join('/')}`;
|
||||||
|
|
||||||
if (opts.buildURL) {
|
if (dbcAccount && refsSize === 1) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
sum.addRaw(`<p>`)
|
sum.addRaw(`<p>`)
|
||||||
.addRaw(`You can also download the following build record archive and import it into Docker Desktop's Builds view. `)
|
.addRaw(`You can also download the following build record archive and import it into Docker Desktop's Builds view. `)
|
||||||
@@ -295,12 +299,14 @@ export class GitHub {
|
|||||||
// Preview
|
// Preview
|
||||||
sum.addRaw('<p>');
|
sum.addRaw('<p>');
|
||||||
const summaryTableData: Array<Array<SummaryTableCell>> = [
|
const summaryTableData: Array<Array<SummaryTableCell>> = [
|
||||||
|
// prettier-ignore
|
||||||
[
|
[
|
||||||
{header: true, data: 'ID'},
|
{header: true, data: 'ID'},
|
||||||
{header: true, data: 'Name'},
|
{header: true, data: 'Name'},
|
||||||
{header: true, data: 'Status'},
|
{header: true, data: 'Status'},
|
||||||
{header: true, data: 'Cached'},
|
{header: true, data: 'Cached'},
|
||||||
{header: true, data: 'Duration'}
|
{header: true, data: 'Duration'},
|
||||||
|
...(dbcAccount && refsSize > 1 ? [{header: true, data: 'Build result URL'}] : [])
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
let buildError: string | undefined;
|
let buildError: string | undefined;
|
||||||
@@ -309,12 +315,13 @@ export class GitHub {
|
|||||||
const summary = opts.exportRes.summaries[ref];
|
const summary = opts.exportRes.summaries[ref];
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
summaryTableData.push([
|
summaryTableData.push([
|
||||||
{data: `<code>${ref.substring(0, 6).toUpperCase()}</code>`},
|
{data: `<code>${ref.substring(0, 6).toUpperCase()}</code>`},
|
||||||
{data: `<strong>${Util.stringToUnicodeEntities(summary.name)}</strong>`},
|
{data: `<strong>${Util.stringToUnicodeEntities(summary.name)}</strong>`},
|
||||||
{data: `${summary.status === 'completed' ? ':white_check_mark:' : summary.status === 'canceled' ? ':no_entry_sign:' : ':x:'} ${summary.status}`},
|
{data: `${summary.status === 'completed' ? ':white_check_mark:' : summary.status === 'canceled' ? ':no_entry_sign:' : ':x:'} ${summary.status}`},
|
||||||
{data: `${summary.numCachedSteps > 0 ? Math.round((summary.numCachedSteps / summary.numTotalSteps) * 100) : 0}%`},
|
{data: `${summary.numCachedSteps > 0 ? Math.round((summary.numCachedSteps / summary.numTotalSteps) * 100) : 0}%`},
|
||||||
{data: summary.duration}
|
{data: summary.duration},
|
||||||
]);
|
...(dbcAccount && refsSize > 1 ? [{data: addLink(':whale: Open', GitHub.formatDBCBuildURL(dbcAccount, ref, summary.defaultPlatform))}] : [])
|
||||||
|
]);
|
||||||
if (summary.error) {
|
if (summary.error) {
|
||||||
buildError = summary.error;
|
buildError = summary.error;
|
||||||
}
|
}
|
||||||
@@ -369,4 +376,8 @@ export class GitHub {
|
|||||||
core.info(`Writing summary`);
|
core.info(`Writing summary`);
|
||||||
await sum.addSeparator().write();
|
await sum.addSeparator().write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static formatDBCBuildURL(account: string, ref: string, platform?: string): string {
|
||||||
|
return `https://app.docker.com/build/accounts/${account}/builds/${(platform ?? 'linux/amd64').replace('/', '-')}/${ref}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,10 @@ export interface UploadArtifactResponse {
|
|||||||
export interface BuildSummaryOpts {
|
export interface BuildSummaryOpts {
|
||||||
exportRes: ExportResponse;
|
exportRes: ExportResponse;
|
||||||
uploadRes?: UploadArtifactResponse;
|
uploadRes?: UploadArtifactResponse;
|
||||||
buildURL?: string;
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
inputs?: any;
|
inputs?: any;
|
||||||
bakeDefinition?: BakeDefinition;
|
bakeDefinition?: BakeDefinition;
|
||||||
|
// builder options
|
||||||
|
driver?: string;
|
||||||
|
endpoint?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user