mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-26 22:26:08 +08:00
Merge pull request #49 from crazy-max/buildx-version
buildx: fix version method
This commit is contained in:
commit
d09114e0c5
@ -157,7 +157,7 @@ describe('printVersion', () => {
|
||||
describe('version', () => {
|
||||
it('valid', async () => {
|
||||
const buildx = new Buildx();
|
||||
expect(semver.valid(await buildx.version)).not.toBeUndefined();
|
||||
expect(semver.valid(await buildx.version())).not.toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -52,7 +52,7 @@ describe('isAvailable', () => {
|
||||
const execSpy = jest.spyOn(Exec, 'getExecOutput');
|
||||
await Docker.isAvailable();
|
||||
// eslint-disable-next-line jest/no-standalone-expect
|
||||
expect(execSpy).toHaveBeenCalledWith(`docker`, undefined, {
|
||||
expect(execSpy).toHaveBeenCalledWith(`docker`, [], {
|
||||
silent: true,
|
||||
ignoreReturnCode: true
|
||||
});
|
||||
|
@ -80,17 +80,17 @@ export class BuildKit {
|
||||
builderInfo = await new Builder({buildx: this.buildx}).inspect(builderName);
|
||||
}
|
||||
for (const node of builderInfo.nodes) {
|
||||
core.debug(`BuildKit.versionSatisfies ${node}: ${range}`);
|
||||
let bkversion = node.buildkitVersion;
|
||||
core.debug(`BuildKit.versionSatisfies ${bkversion}: ${range}`);
|
||||
if (!bkversion) {
|
||||
try {
|
||||
bkversion = await this.getVersionWithinImage(node.name || '');
|
||||
} catch (e) {
|
||||
core.debug(`BuildKit.versionSatisfies ${node}: can't get version`);
|
||||
core.debug(`BuildKit.versionSatisfies ${node.name}: can't get version`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
core.debug(`BuildKit.versionSatisfies ${node}: version ${bkversion}`);
|
||||
core.debug(`BuildKit.versionSatisfies ${node.name}: version ${bkversion}`);
|
||||
// BuildKit version reported by moby is in the format of `v0.11.0-moby`
|
||||
if (builderInfo.driver == 'docker' && !bkversion.endsWith('-moby')) {
|
||||
return false;
|
||||
|
@ -30,7 +30,8 @@ export interface BuildxOpts {
|
||||
}
|
||||
|
||||
export class Buildx {
|
||||
private _version: string | undefined;
|
||||
private _version: string;
|
||||
private _versionOnce: boolean;
|
||||
private readonly _standalone: boolean | undefined;
|
||||
|
||||
public readonly inputs: Inputs;
|
||||
@ -39,6 +40,8 @@ export class Buildx {
|
||||
|
||||
constructor(opts?: BuildxOpts) {
|
||||
this._standalone = opts?.standalone;
|
||||
this._version = '';
|
||||
this._versionOnce = false;
|
||||
this.inputs = new Inputs();
|
||||
}
|
||||
|
||||
@ -94,22 +97,22 @@ export class Buildx {
|
||||
});
|
||||
}
|
||||
|
||||
get version() {
|
||||
return (async () => {
|
||||
if (!this._version) {
|
||||
const cmd = await this.getCommand(['version']);
|
||||
this._version = await Exec.getExecOutput(cmd.command, cmd.args, {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
return Buildx.parseVersion(res.stdout.trim());
|
||||
});
|
||||
}
|
||||
public async version(): Promise<string> {
|
||||
if (this._versionOnce) {
|
||||
return this._version;
|
||||
})();
|
||||
}
|
||||
this._versionOnce = true;
|
||||
const cmd = await this.getCommand(['version']);
|
||||
this._version = await Exec.getExecOutput(cmd.command, cmd.args, {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
return Buildx.parseVersion(res.stdout.trim());
|
||||
});
|
||||
return this._version;
|
||||
}
|
||||
|
||||
public async printVersion() {
|
||||
@ -128,7 +131,7 @@ export class Buildx {
|
||||
}
|
||||
|
||||
public async versionSatisfies(range: string, version?: string): Promise<boolean> {
|
||||
const ver = version ?? (await this.version);
|
||||
const ver = version ?? (await this.version());
|
||||
if (!ver) {
|
||||
core.debug(`Buildx.versionSatisfies false: undefined version`);
|
||||
return false;
|
||||
|
@ -25,7 +25,7 @@ export class Docker {
|
||||
}
|
||||
|
||||
public static async isAvailable(): Promise<boolean> {
|
||||
const ok: boolean = await Exec.getExecOutput('docker', undefined, {
|
||||
const ok: boolean = await Exec.getExecOutput('docker', [], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user