Skip to content

Commit

Permalink
generate build summary
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jun 14, 2024
1 parent e51051a commit d880b19
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ 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;
}
res[key] = value;
}
return res;
}

export async function getArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
const context = handlebars.compile(inputs.context)({
defaultContext: Context.gitContext()
Expand Down
10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ actionsToolkit.run(
const startedTime = new Date();
const inputs: context.Inputs = await context.getInputs();
core.debug(`inputs: ${JSON.stringify(inputs)}`);
stateHelper.setInputs(inputs);

const toolkit = new Toolkit();

Expand Down Expand Up @@ -139,18 +140,23 @@ actionsToolkit.run(
// post
async () => {
if (stateHelper.buildRef.length > 0) {
await core.group(`Exporting build record`, async () => {
await core.group(`Generating build summary`, async () => {
try {
const buildxHistory = new BuildxHistory();
const exportRes = await buildxHistory.export({
refs: [stateHelper.buildRef]
});
core.info(`Build record 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
});
} catch (e) {
core.warning(e.message);
}
Expand Down
7 changes: 7 additions & 0 deletions src/state-helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import * as core from '@actions/core';

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 buildRef = process.env['STATE_buildRef'] || '';

export function setTmpDir(tmpDir: string) {
core.saveState('tmpDir', tmpDir);
}

export function setInputs(inputs: Inputs) {
core.saveState('inputs', JSON.stringify(sanitizeInputs(inputs)));
}

export function setBuildRef(buildRef: string) {
core.saveState('buildRef', buildRef);
}

0 comments on commit d880b19

Please sign in to comment.