Skip to content

Commit

Permalink
Better parsing of outputs
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
CrazyMax committed Oct 19, 2020
1 parent fb84813 commit 75727aa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
36 changes: 25 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/buildx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ export async function getSecret(kvp: string): Promise<string> {
return `id=${key},src=${secretFile}`;
}

export function isLocalOrTarExporter(outputs: string[]): Boolean {
for (let output of outputs) {
for (let [key, value] of output.split(/\s*,\s*/).map(chunk => chunk.split('='))) {
if (key == 'type' && (value == 'local' || value == 'tar')) {
return true;
}
}
}
return false;
}

export function hasGitAuthToken(secrets: string[]): Boolean {
for (let secret of secrets) {
if (secret.startsWith('GIT_AUTH_TOKEN=')) {
return true;
}
}
return false;
}

export async function isAvailable(): Promise<Boolean> {
return await exec.exec(`docker`, ['buildx'], true).then(res => {
if (res.stderr != '' && !res.success) {
Expand Down
16 changes: 6 additions & 10 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
if (inputs.platforms.length > 0) {
args.push('--platform', inputs.platforms.join(','));
}
let isLocalOrTarExporter: boolean = false;
await asyncForEach(inputs.outputs, async output => {
if (output.startsWith('type=local') || output.startsWith('type=tar')) {
isLocalOrTarExporter = true;
}
args.push('--output', output);
});
// TODO: Remove platforms length cond when buildx >0.4.2 available on runner (docker/buildx#351)
if (inputs.platforms.length == 0 && !isLocalOrTarExporter && semver.satisfies(buildxVersion, '>=0.4.2')) {
if (
inputs.platforms.length == 0 &&
!buildx.isLocalOrTarExporter(inputs.outputs) &&
semver.satisfies(buildxVersion, '>=0.4.2')
) {
args.push('--iidfile', await buildx.getImageIDFile());
}
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
Expand All @@ -110,14 +110,10 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
await asyncForEach(inputs.cacheTo, async cacheTo => {
args.push('--cache-to', cacheTo);
});
let hasGitAuthToken: boolean = false;
await asyncForEach(inputs.secrets, async secret => {
if (secret.startsWith('GIT_AUTH_TOKEN=')) {
hasGitAuthToken = true;
}
args.push('--secret', await buildx.getSecret(secret));
});
if (inputs.githubToken && !hasGitAuthToken && inputs.context == defaultContext) {
if (inputs.githubToken && !buildx.hasGitAuthToken(inputs.secrets) && inputs.context == defaultContext) {
args.push('--secret', await buildx.getSecret(`GIT_AUTH_TOKEN=${inputs.githubToken}`));
}
if (inputs.file) {
Expand Down

0 comments on commit 75727aa

Please sign in to comment.