Skip to content

Commit 6691b2b

Browse files
authored
Merge pull request #686 from crazy-max/gh-summary-cloud-driver
github: support cloud build URL when writing summary
2 parents ee9866a + b16fac0 commit 6691b2b

File tree

4 files changed

+54
-16
lines changed

4 files changed

+54
-16
lines changed

src/buildx/history.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class History {
130130
numCachedSteps: res.NumCachedSteps,
131131
numTotalSteps: res.NumTotalSteps,
132132
numCompletedSteps: res.NumCompletedSteps,
133+
defaultPlatform: res.Platform?.[0],
133134
error: errorLogs
134135
};
135136
});
@@ -283,10 +284,10 @@ export class History {
283284
return {
284285
dockerbuildFilename: dockerbuildPath,
285286
dockerbuildSize: dockerbuildStats.size,
286-
summaries: summaries,
287287
builderName: builderName,
288288
nodeName: nodeName,
289-
refs: refs
289+
refs: refs,
290+
summaries: summaries
290291
};
291292
}
292293

src/github.ts

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,23 @@ export class GitHub {
234234
};
235235

236236
const refsSize = Object.keys(opts.exportRes.refs).length;
237+
const singleRef = refsSize === 1 ? Object.keys(opts.exportRes.refs)[0] : undefined;
238+
const singleSummary = singleRef && opts.exportRes.summaries?.[singleRef];
239+
const dbcAccount = opts.driver === 'cloud' && opts.endpoint?.split('/')[0];
237240

238241
const sum = core.summary.addHeading('Docker Build summary', 2);
239242

243+
if (dbcAccount && singleRef && singleSummary) {
244+
const buildURL = GitHub.formatDBCBuildURL(dbcAccount, singleRef, singleSummary.defaultPlatform);
245+
// prettier-ignore
246+
sum.addRaw(`<p>`)
247+
.addRaw(`For a detailed look at the build, you can check the results at:`)
248+
.addRaw('</p>')
249+
.addRaw(`<p>`)
250+
.addRaw(`:whale: ${addLink(`<strong>${buildURL}</strong>`, buildURL)}`)
251+
.addRaw(`</p>`);
252+
}
253+
240254
if (opts.uploadRes) {
241255
// we just need the last two parts of the URL as they are always relative
242256
// to the workflow run URL otherwise URL could be broken if GitHub
@@ -246,17 +260,29 @@ export class GitHub {
246260
// https://github.com/docker/actions-toolkit/issues/367
247261
const artifactRelativeURL = `./${GitHub.runId}/${opts.uploadRes.url.split('/').slice(-2).join('/')}`;
248262

263+
if (dbcAccount && refsSize === 1) {
264+
// prettier-ignore
265+
sum.addRaw(`<p>`)
266+
.addRaw(`You can also download the following build record archive and import it into Docker Desktop's Builds view. `)
267+
.addBreak()
268+
.addRaw(`Build records include details such as timing, dependencies, results, logs, traces, and other information about a build. `)
269+
.addRaw(addLink('Learn more', 'https://www.docker.com/blog/new-beta-feature-deep-dive-into-github-actions-docker-builds-with-docker-desktop/?utm_source=github&utm_medium=actions'))
270+
.addRaw('</p>')
271+
} else {
272+
// prettier-ignore
273+
sum.addRaw(`<p>`)
274+
.addRaw(`For a detailed look at the build, download the following build record archive and import it into Docker Desktop's Builds view. `)
275+
.addBreak()
276+
.addRaw(`Build records include details such as timing, dependencies, results, logs, traces, and other information about a build. `)
277+
.addRaw(addLink('Learn more', 'https://www.docker.com/blog/new-beta-feature-deep-dive-into-github-actions-docker-builds-with-docker-desktop/?utm_source=github&utm_medium=actions'))
278+
.addRaw('</p>')
279+
}
280+
249281
// prettier-ignore
250282
sum.addRaw(`<p>`)
251-
.addRaw(`For a detailed look at the build, download the following build record archive and import it into Docker Desktop's Builds view. `)
252-
.addBreak()
253-
.addRaw(`Build records include details such as timing, dependencies, results, logs, traces, and other information about a build. `)
254-
.addRaw(addLink('Learn more', 'https://www.docker.com/blog/new-beta-feature-deep-dive-into-github-actions-docker-builds-with-docker-desktop/?utm_source=github&utm_medium=actions'))
255-
.addRaw('</p>')
256-
.addRaw(`<p>`)
257283
.addRaw(`:arrow_down: ${addLink(`<strong>${Util.stringToUnicodeEntities(opts.uploadRes.filename)}</strong>`, artifactRelativeURL)} (${Util.formatFileSize(opts.uploadRes.size)} - includes <strong>${refsSize} build record${refsSize > 1 ? 's' : ''}</strong>)`)
258284
.addRaw(`</p>`);
259-
} else {
285+
} else if (opts.exportRes.summaries) {
260286
// prettier-ignore
261287
sum.addRaw(`<p>`)
262288
.addRaw(`The following table provides a brief summary of your build.`)
@@ -273,12 +299,14 @@ export class GitHub {
273299
// Preview
274300
sum.addRaw('<p>');
275301
const summaryTableData: Array<Array<SummaryTableCell>> = [
302+
// prettier-ignore
276303
[
277304
{header: true, data: 'ID'},
278305
{header: true, data: 'Name'},
279306
{header: true, data: 'Status'},
280307
{header: true, data: 'Cached'},
281-
{header: true, data: 'Duration'}
308+
{header: true, data: 'Duration'},
309+
...(dbcAccount && refsSize > 1 ? [{header: true, data: 'Build result URL'}] : [])
282310
]
283311
];
284312
let buildError: string | undefined;
@@ -287,12 +315,13 @@ export class GitHub {
287315
const summary = opts.exportRes.summaries[ref];
288316
// prettier-ignore
289317
summaryTableData.push([
290-
{data: `<code>${ref.substring(0, 6).toUpperCase()}</code>`},
291-
{data: `<strong>${Util.stringToUnicodeEntities(summary.name)}</strong>`},
292-
{data: `${summary.status === 'completed' ? ':white_check_mark:' : summary.status === 'canceled' ? ':no_entry_sign:' : ':x:'} ${summary.status}`},
293-
{data: `${summary.numCachedSteps > 0 ? Math.round((summary.numCachedSteps / summary.numTotalSteps) * 100) : 0}%`},
294-
{data: summary.duration}
295-
]);
318+
{data: `<code>${ref.substring(0, 6).toUpperCase()}</code>`},
319+
{data: `<strong>${Util.stringToUnicodeEntities(summary.name)}</strong>`},
320+
{data: `${summary.status === 'completed' ? ':white_check_mark:' : summary.status === 'canceled' ? ':no_entry_sign:' : ':x:'} ${summary.status}`},
321+
{data: `${summary.numCachedSteps > 0 ? Math.round((summary.numCachedSteps / summary.numTotalSteps) * 100) : 0}%`},
322+
{data: summary.duration},
323+
...(dbcAccount && refsSize > 1 ? [{data: addLink(':whale: Open', GitHub.formatDBCBuildURL(dbcAccount, ref, summary.defaultPlatform))}] : [])
324+
]);
296325
if (summary.error) {
297326
buildError = summary.error;
298327
}
@@ -347,4 +376,8 @@ export class GitHub {
347376
core.info(`Writing summary`);
348377
await sum.addSeparator().write();
349378
}
379+
380+
private static formatDBCBuildURL(account: string, ref: string, platform?: string): string {
381+
return `https://app.docker.com/build/accounts/${account}/builds/${(platform ?? 'linux/amd64').replace('/', '-')}/${ref}`;
382+
}
350383
}

src/types/buildx/history.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,6 @@ export interface Summary {
131131
numTotalSteps: number;
132132
numCompletedSteps: number;
133133
frontendAttrs?: Record<string, string>;
134+
defaultPlatform?: string;
134135
error?: string;
135136
}

src/types/github.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ export interface BuildSummaryOpts {
6262
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6363
inputs?: any;
6464
bakeDefinition?: BakeDefinition;
65+
// builder options
66+
driver?: string;
67+
endpoint?: string;
6568
}

0 commit comments

Comments
 (0)