mirror of
https://git.flexiblyrigid.au/actions/bake-action.git
synced 2025-12-06 07:48:05 +08:00
29 lines
785 B
TypeScript
29 lines
785 B
TypeScript
import * as semver from 'semver';
|
|
import * as exec from './exec';
|
|
|
|
export async function isAvailable(): Promise<Boolean> {
|
|
return await exec.exec(`docker`, ['buildx'], true).then(res => {
|
|
if (res.stderr != '' && !res.success) {
|
|
return false;
|
|
}
|
|
return res.success;
|
|
});
|
|
}
|
|
|
|
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]);
|
|
}
|