diff --git a/__tests__/buildx/buildx.test.ts b/__tests__/buildx/buildx.test.ts index b5c53f6..503667a 100644 --- a/__tests__/buildx/buildx.test.ts +++ b/__tests__/buildx/buildx.test.ts @@ -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(); }); }); diff --git a/__tests__/docker.test.ts b/__tests__/docker.test.ts index c8a7415..416f1a4 100644 --- a/__tests__/docker.test.ts +++ b/__tests__/docker.test.ts @@ -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 }); diff --git a/src/buildkit/buildkit.ts b/src/buildkit/buildkit.ts index 30bd8b8..9abbe78 100644 --- a/src/buildkit/buildkit.ts +++ b/src/buildkit/buildkit.ts @@ -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; diff --git a/src/buildx/buildx.ts b/src/buildx/buildx.ts index fbf3d64..c59b89e 100644 --- a/src/buildx/buildx.ts +++ b/src/buildx/buildx.ts @@ -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 { + 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 { - const ver = version ?? (await this.version); + const ver = version ?? (await this.version()); if (!ver) { core.debug(`Buildx.versionSatisfies false: undefined version`); return false; diff --git a/src/docker.ts b/src/docker.ts index e959ac9..3760735 100644 --- a/src/docker.ts +++ b/src/docker.ts @@ -25,7 +25,7 @@ export class Docker { } public static async isAvailable(): Promise { - const ok: boolean = await Exec.getExecOutput('docker', undefined, { + const ok: boolean = await Exec.getExecOutput('docker', [], { ignoreReturnCode: true, silent: true })