2020-09-02 10:07:11 +02:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as stateHelper from './state-helper';
|
2020-08-16 00:36:41 +02:00
|
|
|
import * as core from '@actions/core';
|
2023-02-20 11:11:15 +01:00
|
|
|
import * as actionsToolkit from '@docker/actions-toolkit';
|
|
|
|
import {Context} from '@docker/actions-toolkit/lib/context';
|
|
|
|
import {Docker} from '@docker/actions-toolkit/lib/docker';
|
|
|
|
import {Exec} from '@docker/actions-toolkit/lib/exec';
|
|
|
|
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
|
|
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
2020-08-16 00:36:41 +02:00
|
|
|
|
2023-02-20 11:11:15 +01:00
|
|
|
import * as context from './context';
|
2022-04-28 09:31:47 +02:00
|
|
|
|
2023-02-20 11:11:15 +01:00
|
|
|
actionsToolkit.run(
|
|
|
|
// main
|
|
|
|
async () => {
|
|
|
|
const inputs: context.Inputs = await context.getInputs();
|
|
|
|
const toolkit = new Toolkit();
|
2022-04-28 09:31:47 +02:00
|
|
|
|
2023-02-20 11:11:15 +01:00
|
|
|
await core.group(`GitHub Actions runtime token ACs`, async () => {
|
|
|
|
try {
|
|
|
|
await GitHub.printActionsRuntimeTokenACs();
|
|
|
|
} catch (e) {
|
|
|
|
core.warning(e.message);
|
2023-01-12 19:44:15 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-20 11:11:15 +01:00
|
|
|
await core.group(`Docker info`, async () => {
|
|
|
|
try {
|
|
|
|
await Docker.printVersion();
|
|
|
|
await Docker.printInfo();
|
|
|
|
} catch (e) {
|
|
|
|
core.info(e.message);
|
|
|
|
}
|
|
|
|
});
|
2020-08-16 00:36:41 +02:00
|
|
|
|
2023-02-20 11:11:15 +01:00
|
|
|
if (!(await toolkit.buildx.isAvailable())) {
|
2021-04-27 16:16:22 +02:00
|
|
|
core.setFailed(`Docker buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`);
|
|
|
|
return;
|
2020-08-16 00:36:41 +02:00
|
|
|
}
|
|
|
|
|
2023-02-20 11:11:15 +01:00
|
|
|
stateHelper.setTmpDir(Context.tmpDir());
|
|
|
|
|
2022-04-28 09:31:47 +02:00
|
|
|
await core.group(`Buildx version`, async () => {
|
2023-02-20 11:11:15 +01:00
|
|
|
await toolkit.buildx.printVersion();
|
2022-04-28 09:31:47 +02:00
|
|
|
});
|
2020-08-16 22:31:37 +02:00
|
|
|
|
2023-02-20 11:11:15 +01:00
|
|
|
const args: string[] = await context.getArgs(inputs, toolkit);
|
|
|
|
const buildCmd = await toolkit.buildx.getCommand(args);
|
|
|
|
await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
|
|
|
|
ignoreReturnCode: true
|
|
|
|
}).then(res => {
|
|
|
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
|
|
|
throw new Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
|
|
|
|
}
|
|
|
|
});
|
2020-08-17 22:18:15 +02:00
|
|
|
|
2023-02-20 11:11:15 +01:00
|
|
|
const imageID = await toolkit.buildx.inputs.resolveBuildImageID();
|
|
|
|
const metadata = await toolkit.buildx.inputs.resolveBuildMetadata();
|
|
|
|
const digest = await toolkit.buildx.inputs.resolveDigest();
|
2022-03-14 19:30:50 +01:00
|
|
|
|
2022-02-09 11:32:35 +01:00
|
|
|
if (imageID) {
|
2022-03-14 19:30:50 +01:00
|
|
|
await core.group(`ImageID`, async () => {
|
2022-02-09 11:32:35 +01:00
|
|
|
core.info(imageID);
|
2022-10-12 06:56:31 +02:00
|
|
|
core.setOutput('imageid', imageID);
|
2022-03-14 19:30:50 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (digest) {
|
|
|
|
await core.group(`Digest`, async () => {
|
|
|
|
core.info(digest);
|
2022-10-12 06:56:31 +02:00
|
|
|
core.setOutput('digest', digest);
|
2022-02-09 11:32:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (metadata) {
|
2022-03-14 19:30:50 +01:00
|
|
|
await core.group(`Metadata`, async () => {
|
2022-02-09 11:32:35 +01:00
|
|
|
core.info(metadata);
|
2022-10-12 06:56:31 +02:00
|
|
|
core.setOutput('metadata', metadata);
|
2022-02-09 11:32:35 +01:00
|
|
|
});
|
|
|
|
}
|
2023-02-20 11:11:15 +01:00
|
|
|
},
|
|
|
|
// post
|
|
|
|
async () => {
|
|
|
|
if (stateHelper.tmpDir.length > 0) {
|
|
|
|
await core.group(`Removing temp folder ${stateHelper.tmpDir}`, async () => {
|
|
|
|
fs.rmSync(stateHelper.tmpDir, {recursive: true});
|
|
|
|
});
|
|
|
|
}
|
2020-09-02 10:07:11 +02:00
|
|
|
}
|
2023-02-20 11:11:15 +01:00
|
|
|
);
|