diff --git a/src/context.ts b/src/context.ts index 160d0ce..0ea15bd 100644 --- a/src/context.ts +++ b/src/context.ts @@ -44,6 +44,28 @@ export async function getInputs(): Promise { }; } +export function sanitizeInputs(inputs: Inputs) { + const res = {}; + for (const key of Object.keys(inputs)) { + if (key === 'github-token') { + continue; + } + const value: string | string[] | boolean = inputs[key]; + if (typeof value === 'boolean' && value === false) { + continue; + } else if (Array.isArray(value) && value.length === 0) { + continue; + } else if (!value) { + continue; + } + if (key === 'workdir' && value === '.') { + continue; + } + res[key] = value; + } + return res; +} + export async function getArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise> { // prettier-ignore return [ diff --git a/src/main.ts b/src/main.ts index f1b3ae5..934affa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,6 +25,7 @@ actionsToolkit.run( const inputs: context.Inputs = await context.getInputs(); core.debug(`inputs: ${JSON.stringify(inputs)}`); + stateHelper.setInputs(inputs); const toolkit = new Toolkit(); const gitAuthToken = process.env.BUILDX_BAKE_GIT_AUTH_TOKEN ?? inputs['github-token']; @@ -110,6 +111,7 @@ actionsToolkit.run( if (!definition) { throw new Error('Bake definition not set'); } + stateHelper.setBakeDefinition(definition); const args: string[] = await context.getArgs(inputs, definition, toolkit); const buildCmd = await toolkit.buildx.getCommand(args); @@ -170,11 +172,17 @@ actionsToolkit.run( refs: stateHelper.buildRefs }); core.info(`Build records exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`); - await GitHub.uploadArtifact({ + const uploadRes = await GitHub.uploadArtifact({ filename: exportRes.dockerbuildFilename, mimeType: 'application/gzip', retentionDays: 90 }); + await GitHub.writeBuildSummary({ + exportRes: exportRes, + uploadRes: uploadRes, + inputs: stateHelper.inputs, + bakeDefinition: stateHelper.bakeDefinition + }); } catch (e) { core.warning(e.message); } diff --git a/src/state-helper.ts b/src/state-helper.ts index cbc6d25..736693b 100644 --- a/src/state-helper.ts +++ b/src/state-helper.ts @@ -1,12 +1,26 @@ import * as core from '@actions/core'; +import {BakeDefinition} from '@docker/actions-toolkit/lib/types/buildx/bake'; + +import {Inputs, sanitizeInputs} from './context'; + export const tmpDir = process.env['STATE_tmpDir'] || ''; +export const inputs = process.env['STATE_inputs'] ? JSON.parse(process.env['STATE_inputs']) : undefined; +export const bakeDefinition = process.env['STATE_bakeDefinition'] ? JSON.parse(process.env['STATE_bakeDefinition']) : undefined; export const buildRefs = process.env['STATE_buildRefs'] ? process.env['STATE_buildRefs'].split(',') : []; export function setTmpDir(tmpDir: string) { core.saveState('tmpDir', tmpDir); } +export function setInputs(inputs: Inputs) { + core.saveState('inputs', JSON.stringify(sanitizeInputs(inputs))); +} + +export function setBakeDefinition(bakeDefinition: BakeDefinition) { + core.saveState('bakeDefinition', JSON.stringify(bakeDefinition)); +} + export function setBuildRefs(buildRefs: Array) { core.saveState('buildRefs', buildRefs.join(',')); }