From 68623fe0d9f2303ad791257228f0da15b387ac72 Mon Sep 17 00:00:00 2001
From: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Date: Wed, 19 Jun 2024 20:40:35 +0200
Subject: [PATCH] github(summary): add collapsible section for build inputs and
bake def
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
---
__tests__/github.test.itg.ts | 40 ++++++++++++++++++++----------------
src/github.ts | 23 +++++++++++++--------
2 files changed, 37 insertions(+), 26 deletions(-)
diff --git a/__tests__/github.test.itg.ts b/__tests__/github.test.itg.ts
index 2163a765..790547a8 100644
--- a/__tests__/github.test.itg.ts
+++ b/__tests__/github.test.itg.ts
@@ -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});
@@ -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, {
@@ -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);
@@ -186,7 +189,8 @@ maybe('writeBuildSummary', () => {
uploadRes: uploadRes,
inputs: {
files: path.join(fixturesDir, 'hello-bake.hcl')
- }
+ },
+ bakeDefinition: definition
});
});
});
diff --git a/src/github.ts b/src/github.ts
index 5fd1d5a8..d2b237fb 100644
--- a/src/github.ts
+++ b/src/github.ts
@@ -281,17 +281,24 @@ 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(`Show content
`)
+ .addCodeBlock(
+ jsyaml.dump(opts.inputs, {
+ indent: 2,
+ lineWidth: -1
+ }), 'yaml'
+ )
+ .addRaw(` `);
}
if (opts.bakeDefinition) {
- sum.addHeading('Bake definition', 2).addCodeBlock(JSON.stringify(opts.bakeDefinition, null, 2), 'json');
+ // prettier-ignore
+ sum.addHeading('Bake definition', 2)
+ .addRaw(`Show content
`)
+ .addCodeBlock(JSON.stringify(opts.bakeDefinition, null, 2), 'json')
+ .addRaw(` `);
}
core.info(`Writing summary`);