generate build summary
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -44,6 +44,28 @@ export async function getInputs(): Promise<Inputs> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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<Array<string>> {
|
export async function getArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise<Array<string>> {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
return [
|
return [
|
||||||
|
|||||||
10
src/main.ts
10
src/main.ts
@@ -25,6 +25,7 @@ actionsToolkit.run(
|
|||||||
|
|
||||||
const inputs: context.Inputs = await context.getInputs();
|
const inputs: context.Inputs = await context.getInputs();
|
||||||
core.debug(`inputs: ${JSON.stringify(inputs)}`);
|
core.debug(`inputs: ${JSON.stringify(inputs)}`);
|
||||||
|
stateHelper.setInputs(inputs);
|
||||||
|
|
||||||
const toolkit = new Toolkit();
|
const toolkit = new Toolkit();
|
||||||
const gitAuthToken = process.env.BUILDX_BAKE_GIT_AUTH_TOKEN ?? inputs['github-token'];
|
const gitAuthToken = process.env.BUILDX_BAKE_GIT_AUTH_TOKEN ?? inputs['github-token'];
|
||||||
@@ -110,6 +111,7 @@ actionsToolkit.run(
|
|||||||
if (!definition) {
|
if (!definition) {
|
||||||
throw new Error('Bake definition not set');
|
throw new Error('Bake definition not set');
|
||||||
}
|
}
|
||||||
|
stateHelper.setBakeDefinition(definition);
|
||||||
|
|
||||||
const args: string[] = await context.getArgs(inputs, definition, toolkit);
|
const args: string[] = await context.getArgs(inputs, definition, toolkit);
|
||||||
const buildCmd = await toolkit.buildx.getCommand(args);
|
const buildCmd = await toolkit.buildx.getCommand(args);
|
||||||
@@ -170,11 +172,17 @@ actionsToolkit.run(
|
|||||||
refs: stateHelper.buildRefs
|
refs: stateHelper.buildRefs
|
||||||
});
|
});
|
||||||
core.info(`Build records exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
|
core.info(`Build records exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
|
||||||
await GitHub.uploadArtifact({
|
const uploadRes = await GitHub.uploadArtifact({
|
||||||
filename: exportRes.dockerbuildFilename,
|
filename: exportRes.dockerbuildFilename,
|
||||||
mimeType: 'application/gzip',
|
mimeType: 'application/gzip',
|
||||||
retentionDays: 90
|
retentionDays: 90
|
||||||
});
|
});
|
||||||
|
await GitHub.writeBuildSummary({
|
||||||
|
exportRes: exportRes,
|
||||||
|
uploadRes: uploadRes,
|
||||||
|
inputs: stateHelper.inputs,
|
||||||
|
bakeDefinition: stateHelper.bakeDefinition
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.warning(e.message);
|
core.warning(e.message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,26 @@
|
|||||||
import * as core from '@actions/core';
|
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 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'] ? <BakeDefinition>JSON.parse(process.env['STATE_bakeDefinition']) : undefined;
|
||||||
export const buildRefs = process.env['STATE_buildRefs'] ? process.env['STATE_buildRefs'].split(',') : [];
|
export const buildRefs = process.env['STATE_buildRefs'] ? process.env['STATE_buildRefs'].split(',') : [];
|
||||||
|
|
||||||
export function setTmpDir(tmpDir: string) {
|
export function setTmpDir(tmpDir: string) {
|
||||||
core.saveState('tmpDir', tmpDir);
|
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<string>) {
|
export function setBuildRefs(buildRefs: Array<string>) {
|
||||||
core.saveState('buildRefs', buildRefs.join(','));
|
core.saveState('buildRefs', buildRefs.join(','));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user