mirror of
https://github.com/docker/setup-buildx-action.git
synced 2025-04-20 09:36:45 +00:00
Check buildx version
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
4285b9db58
commit
0be6f6575b
6 changed files with 83 additions and 25 deletions
|
@ -8,6 +8,23 @@ import * as github from './github';
|
|||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
export async function getVersion(): Promise<string> {
|
||||
return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
return parseVersion(res.stdout);
|
||||
});
|
||||
}
|
||||
|
||||
export async function parseVersion(stdout: string): Promise<string> {
|
||||
const matches = /\sv?([0-9.]+)/.exec(stdout);
|
||||
if (!matches) {
|
||||
throw new Error(`Cannot parse Buildx version`);
|
||||
}
|
||||
return semver.clean(matches[1]);
|
||||
}
|
||||
|
||||
export async function isAvailable(): Promise<Boolean> {
|
||||
return await exec.exec(`docker`, ['buildx'], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
|||
import * as exec from '@actions/exec';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as buildx from './buildx';
|
||||
import * as context from './context';
|
||||
import * as mexec from './exec';
|
||||
|
@ -21,8 +22,8 @@ async function run(): Promise<void> {
|
|||
await buildx.install(inputs.version || 'latest', dockerConfigHome);
|
||||
}
|
||||
|
||||
core.info('📣 Buildx info');
|
||||
await exec.exec('docker', ['buildx', 'version']);
|
||||
const buildxVersion = await buildx.getVersion();
|
||||
core.info(`📣 Buildx version: ${buildxVersion}`);
|
||||
|
||||
const builderName: string =
|
||||
inputs.driver == 'docker' ? 'default' : `builder-${process.env.GITHUB_JOB}-${(await buildx.countBuilders()) + 1}`;
|
||||
|
@ -35,7 +36,7 @@ async function run(): Promise<void> {
|
|||
await context.asyncForEach(inputs.driverOpts, async driverOpt => {
|
||||
createArgs.push('--driver-opt', driverOpt);
|
||||
});
|
||||
if (inputs.buildkitdFlags) {
|
||||
if (inputs.buildkitdFlags && semver.satisfies(buildxVersion, '>=0.3.0')) {
|
||||
createArgs.push('--buildkitd-flags', inputs.buildkitdFlags);
|
||||
}
|
||||
if (inputs.use) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue