1
0
Fork 0
mirror of https://github.com/docker/build-push-action.git synced 2025-04-29 18:29:15 +02:00

Handle multi-line secret value

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-11-17 21:38:45 +01:00
parent 9c13ff40b3
commit 1471dfb80d
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
7 changed files with 409 additions and 39 deletions

View file

@ -1,7 +1,8 @@
import csvparse from 'csv-parse/lib/sync';
import fs from 'fs';
import path from 'path';
import csvparse from 'csv-parse/lib/sync';
import * as semver from 'semver';
import * as context from './context';
import * as exec from './exec';
@ -21,6 +22,9 @@ export async function getSecret(kvp: string): Promise<string> {
const delimiterIndex = kvp.indexOf('=');
const key = kvp.substring(0, delimiterIndex);
const value = kvp.substring(delimiterIndex + 1);
if (key.length == 0 || value.length == 0) {
throw new Error(`${kvp} is not a valid secret`);
}
const secretFile = context.tmpNameSync({
tmpdir: context.tmpDir()
});
@ -33,7 +37,7 @@ export function isLocalOrTarExporter(outputs: string[]): Boolean {
delimiter: ',',
trim: true,
columns: false,
relax_column_count: true
relaxColumnCount: true
})) {
// Local if no type is defined
// https://github.com/docker/buildx/blob/d2bf42f8b4784d83fde17acb3ed84703ddc2156b/build/output.go#L29-L43

View file

@ -1,3 +1,4 @@
import csvparse from 'csv-parse/lib/sync';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
@ -121,7 +122,11 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
args.push('--cache-to', cacheTo);
});
await asyncForEach(inputs.secrets, async secret => {
args.push('--secret', await buildx.getSecret(secret));
try {
args.push('--secret', await buildx.getSecret(secret));
} catch (err) {
core.warning(err.message);
}
});
if (inputs.githubToken && !buildx.hasGitAuthToken(inputs.secrets) && inputs.context == defaultContext) {
args.push('--secret', await buildx.getSecret(`GIT_AUTH_TOKEN=${inputs.githubToken}`));
@ -156,17 +161,29 @@ async function getCommonArgs(inputs: Inputs): Promise<Array<string>> {
}
export async function getInputList(name: string, ignoreComma?: boolean): Promise<string[]> {
let res: Array<string> = [];
const items = core.getInput(name);
if (items == '') {
return [];
return res;
}
return items
.split(/\r?\n/)
.filter(x => x)
.reduce<string[]>(
(acc, line) => acc.concat(!ignoreComma ? line.split(',').filter(x => x) : line).map(pat => pat.trim()),
[]
);
for (let output of (await csvparse(items, {
columns: false,
relaxColumnCount: true,
skipLinesWithEmptyValues: true
})) as Array<string[]>) {
if (output.length == 1) {
res.push(output[0]);
continue;
} else if (!ignoreComma) {
res.push(...output);
continue;
}
res.push(output.join(','));
}
return res.filter(item => item);
}
export const asyncForEach = async (array, callback) => {