Skip to content

Commit

Permalink
Merge pull request #250 from Tradeshift/exec-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wejendorp authored Mar 26, 2022
2 parents cbac167 + 0b2afcd commit f5be74b
Show file tree
Hide file tree
Showing 8 changed files with 48,327 additions and 50,482 deletions.
98,595 changes: 48,241 additions & 50,354 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

71 changes: 36 additions & 35 deletions dist/licenses.txt

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

6 changes: 3 additions & 3 deletions src/aws.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as semver from 'semver';

import {exec} from './exec';
import {info} from '@actions/core';
import {which} from '@actions/io';
import {getExecOutput} from '@actions/exec';

const ecrRepositoryRegex =
/^(([0-9]{12})\.dkr\.ecr\.(.+)\.amazonaws\.com(.cn)?)(\/([^:]+)(:.+)?)?$/;
Expand Down Expand Up @@ -37,8 +37,8 @@ async function parseCLIVersion(stdout: string): Promise<string> {

async function execCLI(args: string[]): Promise<string> {
const cli = await getCLI();
const res = await exec(cli, args, true);
if (res.stderr !== '' && !res.success) {
const res = await getExecOutput(cli, args, {silent: true});
if (res.stderr !== '' && res.exitCode) {
throw new Error(res.stderr);
} else if (res.stderr !== '') {
return res.stderr.trim();
Expand Down
40 changes: 21 additions & 19 deletions src/buildx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import * as uuid from 'uuid';

import {debug, endGroup, info, startGroup, warning} from '@actions/core';
import {HttpClient} from '@actions/http-client';

import {exec} from './exec';
import {exec, getExecOutput} from '@actions/exec';

export async function setup(builderName: string): Promise<void> {
if (!(await isAvailable())) {
Expand All @@ -37,8 +36,8 @@ export async function stop(builderName: string): Promise<void> {

startGroup(`🧹 Cleaning up builder`);

const res = await exec('docker', ['buildx', 'rm', builderName], false);
if (res.stderr !== '' && !res.success) {
const res = await getExecOutput('docker', ['buildx', 'rm', builderName]);
if (res.stderr !== '' && res.exitCode) {
warning(res.stderr);
}

Expand All @@ -56,7 +55,7 @@ async function createBuilder(name: string): Promise<void> {
'--driver',
'docker-container'
];
await exec('docker', args, false);
await exec('docker', args);

endGroup();
}
Expand All @@ -65,7 +64,7 @@ async function bootBuilder(name: string): Promise<void> {
startGroup(`🏃 Booting builder`);

const args = ['buildx', 'inspect', '--bootstrap', '--builder', name];
await exec('docker', args, false);
await exec('docker', args);

endGroup();
}
Expand All @@ -74,36 +73,39 @@ async function useBuilder(name: string): Promise<void> {
startGroup(`Using builder`);

const args = ['buildx', 'use', name];
await exec('docker', args, false);
await exec('docker', args);
await ls();

endGroup();
}

async function getVersion(): Promise<string> {
const res = await exec('docker', ['buildx', 'version'], true);
if (res.stderr !== '' && !res.success) {
const res = await getExecOutput('docker', ['buildx', 'version'], {
silent: true
});
if (res.stderr !== '' && res.exitCode) {
throw new Error(res.stderr);
}
return parseVersion(res.stdout);
}

export async function inspect(shatag: string): Promise<void> {
startGroup(`📦 Pushed image`);
const res = await exec(
'docker',
['buildx', 'imagetools', 'inspect', shatag],
false
);
if (res.stderr !== '' && !res.success) {
const res = await getExecOutput('docker', [
'buildx',
'imagetools',
'inspect',
shatag
]);
if (res.stderr !== '' && res.exitCode) {
throw new Error(res.stderr);
}
endGroup();
}

async function ls(): Promise<void> {
const res = await exec('docker', ['buildx', 'ls'], false);
if (res.stderr !== '' && !res.success) {
const res = await getExecOutput('docker', ['buildx', 'ls']);
if (res.stderr !== '' && res.exitCode) {
throw new Error(res.stderr);
}
}
Expand All @@ -121,8 +123,8 @@ async function parseVersion(stdout: string): Promise<string> {
}

async function isAvailable(): Promise<boolean> {
const res = await exec('docker', ['buildx'], true);
return res.stderr === '' && res.success;
const res = await getExecOutput('docker', ['buildx']);
return res.stderr === '' && !res.exitCode;
}

async function install(inputVersion = 'latest'): Promise<void> {
Expand Down
26 changes: 15 additions & 11 deletions src/docker.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as exec from '@actions/exec';
import * as outputs from './outputs';
import * as state from './state';
import {buildxCachePath, buildxNewCachePath} from './cache';
import {debug, endGroup, info, startGroup, warning} from '@actions/core';
import {Inputs} from './inputs';
import {exec} from './exec';

export async function build(inputs: Inputs): Promise<string> {
startGroup('🏃 Starting build');

const shaTag = await getSHATag(inputs.repository);
outputs.setImage(shaTag);
const args = await getBuildArgs(inputs, shaTag);
const res = await exec('docker', args, false);
if (res.stderr !== '' && !res.success) {
const res = await exec.getExecOutput('docker', args);
if (res.stderr !== '' && res.exitCode) {
throw new Error(`buildx call failed: ${res.stderr.trim()}`);
}
endGroup();
Expand Down Expand Up @@ -67,16 +67,18 @@ export function isDockerhubRepository(repository: string): boolean {
}

async function getSHATag(repository: string): Promise<string> {
const res = await exec('git', ['rev-parse', 'HEAD'], true);
if (res.stderr !== '' && !res.success) {
const res = await exec.getExecOutput('git', ['rev-parse', 'HEAD'], {
silent: true
});
if (res.stderr !== '' && res.exitCode) {
throw new Error(`git rev-parse HEAD failed: ${res.stderr.trim()}`);
}
return `${repository}:${res.stdout.trim()}`;
}

export async function version(): Promise<void> {
const res = await exec('docker', ['version'], false);
if (res.stderr !== '' && !res.success) {
const res = await exec.getExecOutput('docker', ['version']);
if (res.stderr !== '' && res.exitCode) {
warning(res.stderr);
return;
}
Expand All @@ -103,8 +105,10 @@ export async function login(
info(`🔑 Logging into Docker Hub...`);
}

const res = await exec('docker', args, false, password);
if (res.stderr !== '' && !res.success) {
const res = await exec.getExecOutput('docker', args, {
input: Buffer.from(password, 'utf-8')
});
if (res.stderr !== '' && res.exitCode) {
throw new Error(res.stderr);
}
state.setRegistry(registry);
Expand All @@ -123,8 +127,8 @@ async function asyncForEach<T>(
}

export async function logout(registry: string): Promise<void> {
const res = await exec('docker', ['logout', registry], false);
if (res.stderr !== '' && !res.success) {
const res = await exec.getExecOutput('docker', ['logout', registry]);
if (res.stderr !== '' && res.exitCode) {
warning(res.stderr);
return;
}
Expand Down
45 changes: 0 additions & 45 deletions src/exec.ts

This file was deleted.

24 changes: 10 additions & 14 deletions src/qemu.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import {endGroup, startGroup, warning} from '@actions/core';
import {exec} from './exec';
import {getExecOutput} from '@actions/exec';

export async function setup(): Promise<void> {
startGroup(`🖥️ Setup qemu`);
const res = await exec(
'docker',
[
'run',
'--privileged',
'--rm',
'eu.gcr.io/tradeshift-base/tonistiigi/binfmt:qemu-v6.1.0',
'--install',
'all'
],
false
);
if (res.stderr !== '' && !res.success) {
const res = await getExecOutput('docker', [
'run',
'--privileged',
'--rm',
'eu.gcr.io/tradeshift-base/tonistiigi/binfmt:qemu-v6.1.0',
'--install',
'all'
]);
if (res.stderr !== '' && res.exitCode) {
warning(res.stderr);
}
endGroup();
Expand Down

0 comments on commit f5be74b

Please sign in to comment.