From 687fd9635fd85b1da920d8275c379c38f1af4773 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 8 Apr 2025 18:06:18 +0200 Subject: [PATCH] only print secret keys in build summary output Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- src/context.ts | 19 ------------------- src/state-helper.ts | 32 +++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/context.ts b/src/context.ts index 0a110a2..49bde50 100644 --- a/src/context.ts +++ b/src/context.ts @@ -81,25 +81,6 @@ export async function getInputs(): Promise { }; } -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> { const context = handlebars.compile(inputs.context)({ defaultContext: Context.gitContext() diff --git a/src/state-helper.ts b/src/state-helper.ts index ff46763..f564c22 100644 --- a/src/state-helper.ts +++ b/src/state-helper.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; +import {Build} from '@docker/actions-toolkit/lib/buildx/build'; -import {Inputs, sanitizeInputs} from './context'; +import {Inputs} from './context'; export const tmpDir = process.env['STATE_tmpDir'] || ''; export const inputs = process.env['STATE_inputs'] ? JSON.parse(process.env['STATE_inputs']) : undefined; @@ -22,3 +23,32 @@ export function setBuildRef(buildRef: string) { export function setSummarySupported() { core.saveState('isSummarySupported', 'true'); } + +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) { + continue; + } else if (Array.isArray(value)) { + if (value.length === 0) { + continue; + } else if (key === 'secrets' && value.length > 0) { + for (const secret of value) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const [skey, _] = Build.parseSecretKvp(secret); + res[key] = res[key] || []; + res[key].push(skey); + } + continue; + } + } else if (!value) { + continue; + } + res[key] = value; + } + return res; +}