mirror of
https://gitea.com/docker/build-push-action.git
synced 2024-11-25 19:09:40 +01:00
generate build summary
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
e51051ad0b
commit
d880b1964b
3 changed files with 34 additions and 2 deletions
|
@ -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>> {
|
export async function getArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
||||||
const context = handlebars.compile(inputs.context)({
|
const context = handlebars.compile(inputs.context)({
|
||||||
defaultContext: Context.gitContext()
|
defaultContext: Context.gitContext()
|
||||||
|
|
10
src/main.ts
10
src/main.ts
|
@ -23,6 +23,7 @@ actionsToolkit.run(
|
||||||
const startedTime = new Date();
|
const startedTime = new Date();
|
||||||
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();
|
||||||
|
|
||||||
|
@ -139,18 +140,23 @@ actionsToolkit.run(
|
||||||
// post
|
// post
|
||||||
async () => {
|
async () => {
|
||||||
if (stateHelper.buildRef.length > 0) {
|
if (stateHelper.buildRef.length > 0) {
|
||||||
await core.group(`Exporting build record`, async () => {
|
await core.group(`Generating build summary`, async () => {
|
||||||
try {
|
try {
|
||||||
const buildxHistory = new BuildxHistory();
|
const buildxHistory = new BuildxHistory();
|
||||||
const exportRes = await buildxHistory.export({
|
const exportRes = await buildxHistory.export({
|
||||||
refs: [stateHelper.buildRef]
|
refs: [stateHelper.buildRef]
|
||||||
});
|
});
|
||||||
core.info(`Build record exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
|
core.info(`Build record 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
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.warning(e.message);
|
core.warning(e.message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
|
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 buildRef = process.env['STATE_buildRef'] || '';
|
export const buildRef = process.env['STATE_buildRef'] || '';
|
||||||
|
|
||||||
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 setBuildRef(buildRef: string) {
|
export function setBuildRef(buildRef: string) {
|
||||||
core.saveState('buildRef', buildRef);
|
core.saveState('buildRef', buildRef);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue