8000 github(summary): add details to summary sections · docker/actions-toolkit@b9b815a · GitHub
[go: up one dir, main page]

Skip to content

Commit b9b815a

Browse files
committed
github(summary): add details to summary sections
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 26a1c92 commit b9b815a

File tree

3 files changed

+136
-33
lines changed

3 files changed

+136
-33
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Copyright 2024 actions-toolkit authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
FROM busybox:latest
18+
ARGGG NAME=foo
19+
RUN echo "hello $NAME"

__tests__/github.test.itg.ts

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,29 +118,20 @@ maybe('writeBuildSummary', () => {
118118
test.each([
119119
[
120120
'single',
121-
[
122-
'bake',
123-
'-f', path.join(fixturesDir, 'hello-bake.hcl'),
124-
'hello'
125-
],
121+
path.join(fixturesDir, 'hello-bake.hcl'),
122+
'hello'
126123
],
127124
[
128125
'group',
129-
[
130-
'bake',
131-
'-f', path.join(fixturesDir, 'hello-bake.hcl'),
132-
'hello-all'
133-
],
126+
path.join(fixturesDir, 'hello-bake.hcl'),
127+
'hello-all'
134128
],
135129
[
136130
'matrix',
137-
[
138-
'bake',
139-
'-f', path.join(fixturesDir, 'hello-bake.hcl'),
140-
'hello-matrix'
141-
],
131+
path.join(fixturesDir, 'hello-bake.hcl'),
132+
'hello-matrix'
142133
]
143-
])('write bake summary %p', async (_, bargs) => {
134+
])('write bake summary %p', async (_, file, target) => {
144135
const buildx = new Buildx();
145136
const bake = new Bake({buildx: buildx});
146137

@@ -150,7 +141,9 @@ maybe('writeBuildSummary', () => {
150141
// prettier-ignore
151142
const buildCmd = await buildx.getCommand([
152143
'--builder', process.env.CTN_BUILDER_NAME ?? 'default',
153-
...bargs,
144+
'bake',
145+
'-f', file,
146+
target,
154147
'--metadata-file', bake.getMetadataFilePath()
155148
]);
156149
await Exec.exec(buildCmd.command, buildCmd.args, {
@@ -159,6 +152,16 @@ maybe('writeBuildSummary', () => {
159152
})()
160153
).resolves.not.toThrow();
161154

155+
const definition = await bake.getDefinition(
156+
{
157+
files: [file],
158+
targets: [target],
159+
},
160+
{
161+
cwd: fixturesDir
162+
}
163+
);
164+
162165
const metadata = bake.resolveMetadata();
163166
expect(metadata).toBeDefined();
164167
const buildRefs = bake.resolveRefs(metadata);
@@ -186,6 +189,62 @@ maybe('writeBuildSummary', () => {
186189
uploadRes: uploadRes,
187190
inputs: {
188191
files: path.join(fixturesDir, 'hello-bake.hcl')
192+
},
193+
bakeDefinition: definition
194+
});
195+
});
196+
197+
it('fails with dockerfile syntax issue', async () => {
198+
const startedTime = new Date();
199+
const buildx = new Buildx();
200+
const build = new Build({buildx: buildx});
201+
202+
fs.mkdirSync(tmpDir, {recursive: true});
203+
await expect(
204+
(async () => {
205+
// prettier-ignore
206+
const buildCmd = await buildx.getCommand([
207+
'--builder', process.env.CTN_BUILDER_NAME ?? 'default',
208+
'build',
209+
'-f', path.join(fixturesDir, 'hello-err.Dockerfile'),
210+
fixturesDir,
211+
'--metadata-file', build.getMetadataFilePath()
212+
]);
213+
await Exec.exec(buildCmd.command, buildCmd.args);
214+
})()
215+
).rejects.toThrow();
216+
217+
const refs = Buildx.refs({
218+
dir: Buildx.refsDir,
219+
builderName: process.env.CTN_BUILDER_NAME ?? 'default',
220+
since: startedTime
221+
});
222+
expect< 9E72 span class=pl-kos>(refs).toBeDefined();
223+
expect(Object.keys(refs).length).toBeGreaterThan(0);
224+
225+
const history = new History({buildx: buildx});
226+
const exportRes = await history.export({
227+
refs: [Object.keys(refs)[0] ?? '']
228+
});
229+
expect(exportRes).toBeDefined();
230+
expect(exportRes?.dockerbuildFilename).toBeDefined();
231+
expect(exportRes?.dockerbuildSize).toBeDefined();
232+
expect(exportRes?.summaries).toBeDefined();
233+
234+
const uploadRes = await GitHub.uploadArtifact({
235+
filename: exportRes?.dockerbuildFilename,
236+
mimeType: 'application/gzip',
237+
retentionDays: 1
238+
});
239+
expect(uploadRes).toBeDefined();
240+
expect(uploadRes?.url).toBeDefined();
241+
242+
await GitHub.writeBuildSummary({
243+
exportRes: exportRes,
244+
uploadRes: uploadRes,
245+
inputs: {
246+
context: fixturesDir,
247+
file: path.join(fixturesDir, 'hello-err.Dockerfile')
189248
}
190249
});
191250
});

src/github.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export class GitHub {
229229

230230
// prettier-ignore
231231
const sum = core.summary
232-
.addHeading('Docker Build summary', 1)
232+
.addHeading('Docker Build summary', 2)
233233
.addRaw(`<p>`)
234234
.addRaw(`For a detailed look at the build, download the following build record archive and import it into Docker Desktop's Builds view. `)
235235
.addBreak()
@@ -246,8 +246,8 @@ export class GitHub {
246246
.addRaw(addLink('Let us know', 'https://docs.docker.com/feedback/gha-build-summary'))
247247
.addRaw('</p>');
248248

249-
sum.addHeading('Preview', 2);
250-
249+
// Preview
250+
sum.addRaw(`<strong>Preview</strong>`).addBreak().addRaw('<p>');
251251
const summaryTableData: Array<Array<SummaryTableCell>> = [
252252
[
253253
{header: true, data: 'ID'},
@@ -257,7 +257,7 @@ export class GitHub {
257257
{header: true, data: 'Duration'}
258258
]
259259
];
260-
let summaryError: string | undefined;
260+
let buildError: string | undefined;
261261
for (const ref in opts.exportRes.summaries) {
262262
if (Object.prototype.hasOwnProperty.call(opts.exportRes.summaries, ref)) {
263263
const summary = opts.exportRes.summaries[ref];
@@ -270,28 +270,53 @@ export class GitHub {
270270
{data: summary.duration}
271271
]);
272272
if (summary.error) {
273-
summaryError = summary.error;
273+
buildError = summary.error;
274274
}
275275
}
276276
}
277277
sum.addTable([...summaryTableData]);
278-
if (summaryError) {
279-
sum.addHeading('Error', 4);
280-
sum.addCodeBlock(summaryError, 'text');
278+
sum.addRaw(`</p>`);
279+
280+
// Build error
281+
if (buildError) {
282+
sum.addRaw(`<blockquote>`);
283+
if (Util.countLines(buildError) > 10) {
284+
// prettier-ignore
285+
sum
286+
.addRaw(`<details><summary><strong>Error</strong></summary>`)
287+
.addCodeBlock(buildError, 'text')
288+
.addRaw(`</details>`);
289+
} else {
290+
// prettier-ignore
291+
sum
292+
.addRaw(`<strong>Error</strong>`)
293+
.addBreak()
294+
.addRaw(`<p>`)
295+
.addCodeBlock(buildError, 'text')
296+
.addRaw(`</p>`);
297+
}
298+
sum.addRaw(`</blockquote>`);
281299
}
282300

301+
// Build inputs
283302
if (opts.inputs) {
284-
sum.addHeading('Build inputs', 2).addCodeBlock(
285-
jsyaml.dump(opts.inputs, {
286-
indent: 2,
287-
lineWidth: -1
288-
}),
289-
'yaml'
290-
);
303+
// prettier-ignore
304+
sum.addRaw(`<details><summary><strong>Build inputs</strong></summary>`)
305+
.addCodeBlock(
306+
jsyaml.dump(opts.inputs, {
307+
indent: 2,
308+
lineWidth: -1
309+
}), 'yaml'
310+
)
311+
.addRaw(`</details>`);
291312
}
292313

314+
// Bake definition
293315
if (opts.bakeDefinition) {
294-
sum.addHeading('Bake definition', 2).addCodeBlock(JSON.stringify(opts.bakeDefinition, null, 2), 'json');
316+
// prettier-ignore
317+
sum.addRaw(`<details><summary><strong>Bake definition</strong></summary>`)
318+
.addCodeBlock(JSON.stringify(opts.bakeDefinition, null, 2), 'json')
319+
.addRaw(`</details>`);
295320
}
296321

297322
core.info(`Writing summary`);

0 commit comments

Comments
 (0)
0