buildx: optional version for versionSatisfies

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-01-24 01:43:01 +01:00
parent b6f85576fa
commit d27b5d60be
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 5 additions and 3 deletions

View File

@ -191,7 +191,8 @@ describe('versionSatisfies', () => {
['bda4882a65349ca359216b135896bddc1d92461c', '>0.1.0', false], ['bda4882a65349ca359216b135896bddc1d92461c', '>0.1.0', false],
['f117971', '>0.6.0', true] ['f117971', '>0.6.0', true]
])('given %p', async (version, range, expected) => { ])('given %p', async (version, range, expected) => {
expect(Buildx.versionSatisfies(version, range)).toBe(expected); const buildx = new Buildx();
expect(await buildx.versionSatisfies(range, version)).toBe(expected);
}); });
}); });

View File

@ -86,8 +86,9 @@ export class Buildx {
return matches[1]; return matches[1];
} }
public static versionSatisfies(version: string, range: string): boolean { public async versionSatisfies(range: string, version?: string): Promise<boolean> {
return semver.satisfies(version, range) || /^[0-9a-f]{7}$/.exec(version) !== null; const ver = version ?? (await this.getVersion());
return semver.satisfies(ver, range) || /^[0-9a-f]{7}$/.exec(ver) !== null;
} }
public getBuildImageIDFilePath(): string { public getBuildImageIDFilePath(): string {