Skip to content

Commit d880b19

Browse files
committed
generate build summary
Signed-off-by: CrazyMax <[email protected]>
1 parent e51051a commit d880b19

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/context.ts

+19
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ export async function getInputs(): Promise<Inputs> {
7979
};
8080
}
8181

82+
export function sanitizeInputs(inputs: Inputs) {
83+
const res = {};
84+
for (const key of Object.keys(inputs)) {
85+
if (key === 'github-token') {
86+
continue;
87+
}
88+
const value: string | string[] | boolean = inputs[key];
89+
if (typeof value === 'boolean' && value === false) {
90+
continue;
91+
} else if (Array.isArray(value) && value.length === 0) {
92+
continue;
93+
} else if (!value) {
94+
continue;
95+
}
96+
res[key] = value;
97+
}
98+
return res;
99+
}
100+
82101
export async function getArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
83102
const context = handlebars.compile(inputs.context)({
84103
defaultContext: Context.gitContext()

src/main.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ actionsToolkit.run(
2323
const startedTime = new Date();
2424
const inputs: context.Inputs = await context.getInputs();
2525
core.debug(`inputs: ${JSON.stringify(inputs)}`);
26+
stateHelper.setInputs(inputs);
2627

2728
const toolkit = new Toolkit();
2829

@@ -139,18 +140,23 @@ actionsToolkit.run(
139140
// post
140141
async () => {
141142
if (stateHelper.buildRef.length > 0) {
142-
await core.group(`Exporting build record`, async () => {
143+
await core.group(`Generating build summary`, async () => {
143144
try {
144145
const buildxHistory = new BuildxHistory();
145146
const exportRes = await buildxHistory.export({
146147
refs: [stateHelper.buildRef]
147148
});
148149
core.info(`Build record exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
149-
await GitHub.uploadArtifact({
150+
const uploadRes = await GitHub.uploadArtifact({
150151
filename: exportRes.dockerbuildFilename,
151152
mimeType: 'application/gzip',
152153
retentionDays: 90
153154
});
155+
await GitHub.writeBuildSummary({
156+
exportRes: exportRes,
157+
uploadRes: uploadRes,
158+
inputs: stateHelper.inputs
159+
});
154160
} catch (e) {
155161
core.warning(e.message);
156162
}

src/state-helper.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import * as core from '@actions/core';
22

3+
import {Inputs, sanitizeInputs} from './context';
4+
35
export const tmpDir = process.env['STATE_tmpDir'] || '';
6+
export const inputs = process.env['STATE_inputs'] ? JSON.parse(process.env['STATE_inputs']) : undefined;
47
export const buildRef = process.env['STATE_buildRef'] || '';
58

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

13+
export function setInputs(inputs: Inputs) {
14+
core.saveState('inputs', JSON.stringify(sanitizeInputs(inputs)));
15+
}
16+
1017
export function setBuildRef(buildRef: string) {
1118
core.saveState('buildRef', buildRef);
1219
}

0 commit comments

Comments
 (0)