Skip to content

Commit 88844b9

Browse files
authored
Merge pull request #1353 from crazy-max/summary-secret-keys
only print secret keys in build summary output
2 parents 548776e + 1be4244 commit 88844b9

File tree

5 files changed

+44
-29
lines changed

5 files changed

+44
-29
lines changed

‎dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/context.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,6 @@ export async function getInputs(): Promise<Inputs> {
8181
};
8282
}
8383

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

‎src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ actionsToolkit.run(
2424
async () => {
2525
const startedTime = new Date();
2626
const inputs: context.Inputs = await context.getInputs();
27+
stateHelper.setSummaryInputs(inputs);
2728
core.debug(`inputs: ${JSON.stringify(inputs)}`);
28-
stateHelper.setInputs(inputs);
2929

3030
const toolkit = new Toolkit();
3131

@@ -216,7 +216,7 @@ actionsToolkit.run(
216216
await GitHub.writeBuildSummary({
217217
exportRes: exportRes,
218218
uploadRes: uploadRes,
219-
inputs: stateHelper.inputs
219+
inputs: stateHelper.summaryInputs
220220
});
221221
} catch (e) {
222222
core.warning(e.message);

‎src/state-helper.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
11
import * as core from '@actions/core';
22

3-
import {Inputs, sanitizeInputs} from './context';
3+
import {Build} from '@docker/actions-toolkit/lib/buildx/build';
4+
5+
import {Inputs} from './context';
46

57
export const tmpDir = process.env['STATE_tmpDir'] || '';
6-
export const inputs = process.env['STATE_inputs'] ? JSON.parse(process.env['STATE_inputs']) : undefined;
78
export const buildRef = process.env['STATE_buildRef'] || '';
89
export const isSummarySupported = !!process.env['STATE_isSummarySupported'];
10+
export const summaryInputs = process.env['STATE_summaryInputs'] ? JSON.parse(process.env['STATE_summaryInputs']) : undefined;
911

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

14-
export function setInputs(inputs: Inputs) {
15-
core.saveState('inputs', JSON.stringify(sanitizeInputs(inputs)));
16-
}
17-
1816
export function setBuildRef(buildRef: string) {
1917
core.saveState('buildRef', buildRef);
2018
}
2119

2220
export function setSummarySupported() {
2321
core.saveState('isSummarySupported', 'true');
2422
}
23+
24+
export function setSummaryInputs(inputs: Inputs) {
25+
const res = {};
26+
for (const key of Object.keys(inputs)) {
27+
if (key === 'github-token') {
28+
continue;
29+
}
30+
const value: string | string[] | boolean = inputs[key];
31+
if (typeof value === 'boolean' && !value) {
32+
continue;
33+
} else if (Array.isArray(value)) {
34+
if (value.length === 0) {
35+
continue;
36+
} else if (key === 'secrets' && value.length > 0) {
37+
const secretKeys: string[] = [];
38+
for (const secret of value) {
39+
try {
40+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
41+
const [skey, _] = Build.parseSecretKvp(secret, true);
42+
secretKeys.push(skey);
43+
} catch (err) {
44+
// ignore invalid secret
45+
}
46+
}
47+
if (secretKeys.length > 0) {
48+
res[key] = secretKeys;
49+
}
50+
continue;
51+
}
52+
} else if (!value) {
53+
continue;
54+
}
55+
res[key] = value;
56+
}
57+
core.saveState('summaryInputs', JSON.stringify(res));
58+
}

0 commit comments

Comments
 (0)