Skip to content

Commit

Permalink
github(summary): add collapsible section for build inputs and bake def
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Jun 19, 2024
1 parent b5ae9cc commit 13ad782
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
40 changes: 22 additions & 18 deletions __tests__/github.test.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,20 @@ maybe('writeBuildSummary', () => {
test.each([
[
'single',
[
'bake',
'-f', path.join(fixturesDir, 'hello-bake.hcl'),
'hello'
],
path.join(fixturesDir, 'hello-bake.hcl'),
'hello'
],
[
'group',
[
'bake',
'-f', path.join(fixturesDir, 'hello-bake.hcl'),
'hello-all'
],
path.join(fixturesDir, 'hello-bake.hcl'),
'hello-all'
],
[
'matrix',
[
'bake',
'-f', path.join(fixturesDir, 'hello-bake.hcl'),
'hello-matrix'
],
path.join(fixturesDir, 'hello-bake.hcl'),
'hello-matrix'
]
])('write bake summary %p', async (_, bargs) => {
])('write bake summary %p', async (_, file, target) => {
const buildx = new Buildx();
const bake = new Bake({buildx: buildx});

Expand All @@ -150,7 +141,9 @@ maybe('writeBuildSummary', () => {
// prettier-ignore
const buildCmd = await buildx.getCommand([
'--builder', process.env.CTN_BUILDER_NAME ?? 'default',
...bargs,
'bake',
'-f', file,
target,
'--metadata-file', bake.getMetadataFilePath()
]);
await Exec.exec(buildCmd.command, buildCmd.args, {
Expand All @@ -159,6 +152,16 @@ maybe('writeBuildSummary', () => {
})()
).resolves.not.toThrow();

const definition = await bake.getDefinition(
{
files: [file],
targets: [target],
},
{
cwd: fixturesDir
}
);

const metadata = bake.resolveMetadata();
expect(metadata).toBeDefined();
const buildRefs = bake.resolveRefs(metadata);
Expand Down Expand Up @@ -186,7 +189,8 @@ maybe('writeBuildSummary', () => {
uploadRes: uploadRes,
inputs: {
files: path.join(fixturesDir, 'hello-bake.hcl')
}
},
bakeDefinition: definition
});
});
});
24 changes: 16 additions & 8 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,25 @@ export class GitHub {
}

if (opts.inputs) {
sum.addHeading('Build inputs', 2).addCodeBlock(
jsyaml.dump(opts.inputs, {
indent: 2,
lineWidth: -1
}),
'yaml'
);
// prettier-ignore
sum.addHeading('Build inputs', 2)
.addRaw(`<details><summary>Click to Expand</summary>`)
.addCodeBlock(
jsyaml.dump(opts.inputs, {
indent: 2,
lineWidth: -1
}),
'yaml'
)
.addRaw(`</details>`);
}

if (opts.bakeDefinition) {
sum.addHeading('Bake definition', 2).addCodeBlock(JSON.stringify(opts.bakeDefinition, null, 2), 'json');
// prettier-ignore
sum.addHeading('Bake definition', 2)
.addRaw(`<details><summary>Click to Expand</summary>`)
.addCodeBlock(JSON.stringify(opts.bakeDefinition, null, 2), 'json')
.addRaw(`</details>`);
}

core.info(`Writing summary`);
Expand Down

0 comments on commit 13ad782

Please sign in to comment.