Files
bake-action/src/main.ts

40 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2020-10-08 00:52:52 +02:00
import * as buildx from './buildx';
import * as context from './context';
import * as mexec from './exec';
2020-10-08 00:52:52 +02:00
import * as core from '@actions/core';
import * as exec from '@actions/exec';
async function run(): Promise<void> {
try {
2021-04-27 15:47:00 +02:00
core.startGroup(`Docker info`);
await exec.exec('docker', ['version']);
await exec.exec('docker', ['info']);
core.endGroup();
2020-10-08 00:52:52 +02:00
if (!(await buildx.isAvailable())) {
2021-04-27 15:47:00 +02:00
core.setFailed(`Docker buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
2020-10-08 00:52:52 +02:00
return;
}
const bxVersion = await buildx.getVersion();
core.debug(`buildx version: ${bxVersion}`);
2020-10-08 00:52:52 +02:00
const inputs: context.Inputs = await context.getInputs();
const args: string[] = await context.getArgs(inputs, bxVersion);
2020-12-24 18:03:30 +01:00
2021-04-27 15:47:00 +02:00
core.startGroup(`Bake definition`);
2020-12-23 20:15:23 +01:00
await exec.exec('docker', [...args, '--print']);
core.endGroup();
2020-12-24 18:03:30 +01:00
await mexec.exec('docker', args).then(res => {
if (res.stderr.length > 0 && !res.success) {
throw new Error(`buildx bake failed with: ${res.stderr.match(/(.*)\s*$/)![0]}`);
}
});
2020-10-08 00:52:52 +02:00
} catch (error) {
core.setFailed(error.message);
}
}
run();