mirror of
https://github.com/docker/setup-buildx-action.git
synced 2024-11-22 22:46:07 +08:00
Merge pull request #315 from crazy-max/fix-err-output
throw error message instead of exit code
This commit is contained in:
commit
a530e948ad
14
dist/index.js
generated
vendored
14
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -26,7 +26,6 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@actions/exec": "^1.1.1",
|
|
||||||
"@docker/actions-toolkit": "^0.20.0",
|
"@docker/actions-toolkit": "^0.20.0",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
|
66
src/main.ts
66
src/main.ts
@ -1,11 +1,11 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as yaml from 'js-yaml';
|
import * as yaml from 'js-yaml';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
|
||||||
import * as actionsToolkit from '@docker/actions-toolkit';
|
import * as actionsToolkit from '@docker/actions-toolkit';
|
||||||
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
||||||
import {Builder} from '@docker/actions-toolkit/lib/buildx/builder';
|
import {Builder} from '@docker/actions-toolkit/lib/buildx/builder';
|
||||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||||
|
import {Exec} from '@docker/actions-toolkit/lib/exec';
|
||||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||||
import {Node} from '@docker/actions-toolkit/lib/types/builder';
|
import {Node} from '@docker/actions-toolkit/lib/types/builder';
|
||||||
@ -77,7 +77,13 @@ actionsToolkit.run(
|
|||||||
inputs.driverOpts = [...inputs.driverOpts, ...certsDriverOpts];
|
inputs.driverOpts = [...inputs.driverOpts, ...certsDriverOpts];
|
||||||
}
|
}
|
||||||
const createCmd = await toolkit.buildx.getCommand(await context.getCreateArgs(inputs, toolkit));
|
const createCmd = await toolkit.buildx.getCommand(await context.getCreateArgs(inputs, toolkit));
|
||||||
await exec.exec(createCmd.command, createCmd.args);
|
await Exec.getExecOutput(createCmd.command, createCmd.args, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
}).then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +101,13 @@ actionsToolkit.run(
|
|||||||
node['driver-opts'] = [...(node['driver-opts'] || []), ...certsDriverOpts];
|
node['driver-opts'] = [...(node['driver-opts'] || []), ...certsDriverOpts];
|
||||||
}
|
}
|
||||||
const appendCmd = await toolkit.buildx.getCommand(await context.getAppendArgs(inputs, node, toolkit));
|
const appendCmd = await toolkit.buildx.getCommand(await context.getAppendArgs(inputs, node, toolkit));
|
||||||
await exec.exec(appendCmd.command, appendCmd.args);
|
await Exec.getExecOutput(appendCmd.command, appendCmd.args, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
}).then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(`Failed to append node ${node.name}: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
nodeIndex++;
|
nodeIndex++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -103,7 +115,13 @@ actionsToolkit.run(
|
|||||||
|
|
||||||
await core.group(`Booting builder`, async () => {
|
await core.group(`Booting builder`, async () => {
|
||||||
const inspectCmd = await toolkit.buildx.getCommand(await context.getInspectArgs(inputs, toolkit));
|
const inspectCmd = await toolkit.buildx.getCommand(await context.getInspectArgs(inputs, toolkit));
|
||||||
await exec.exec(inspectCmd.command, inspectCmd.args);
|
await Exec.getExecOutput(inspectCmd.command, inspectCmd.args, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
}).then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (inputs.install) {
|
if (inputs.install) {
|
||||||
@ -112,7 +130,13 @@ actionsToolkit.run(
|
|||||||
}
|
}
|
||||||
await core.group(`Setting buildx as default builder`, async () => {
|
await core.group(`Setting buildx as default builder`, async () => {
|
||||||
const installCmd = await toolkit.buildx.getCommand(['install']);
|
const installCmd = await toolkit.buildx.getCommand(['install']);
|
||||||
await exec.exec(installCmd.command, installCmd.args);
|
await Exec.getExecOutput(installCmd.command, installCmd.args, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
}).then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,15 +179,13 @@ actionsToolkit.run(
|
|||||||
async () => {
|
async () => {
|
||||||
if (stateHelper.IsDebug && stateHelper.containerName.length > 0) {
|
if (stateHelper.IsDebug && stateHelper.containerName.length > 0) {
|
||||||
await core.group(`BuildKit container logs`, async () => {
|
await core.group(`BuildKit container logs`, async () => {
|
||||||
await exec
|
await Exec.getExecOutput('docker', ['logs', `${stateHelper.containerName}`], {
|
||||||
.getExecOutput('docker', ['logs', `${stateHelper.containerName}`], {
|
ignoreReturnCode: true
|
||||||
ignoreReturnCode: true
|
}).then(res => {
|
||||||
})
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
.then(res => {
|
core.warning(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
}
|
||||||
core.warning(res.stderr.trim());
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,15 +199,13 @@ actionsToolkit.run(
|
|||||||
const builder = new Builder({buildx: buildx});
|
const builder = new Builder({buildx: buildx});
|
||||||
if (await builder.exists(stateHelper.builderName)) {
|
if (await builder.exists(stateHelper.builderName)) {
|
||||||
const rmCmd = await buildx.getCommand(['rm', stateHelper.builderName]);
|
const rmCmd = await buildx.getCommand(['rm', stateHelper.builderName]);
|
||||||
await exec
|
await Exec.getExecOutput(rmCmd.command, rmCmd.args, {
|
||||||
.getExecOutput(rmCmd.command, rmCmd.args, {
|
ignoreReturnCode: true
|
||||||
ignoreReturnCode: true
|
}).then(res => {
|
||||||
})
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
.then(res => {
|
core.warning(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error');
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
}
|
||||||
core.warning(res.stderr.trim());
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
core.info(`${stateHelper.builderName} does not exist`);
|
core.info(`${stateHelper.builderName} does not exist`);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user