From 94827201d1ef44132e16666b71fdb028712d0e0f Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 1 Jul 2021 15:29:36 +0200 Subject: [PATCH] Handle git sha version of buildx Signed-off-by: CrazyMax --- .prettierrc.json | 2 +- __tests__/buildx.test.ts | 23 ++++++++++++++--------- __tests__/context.test.ts | 8 +------- codecov.yml | 3 +++ dist/index.js | 22 +++++++++++----------- src/buildx.ts | 10 +++++++--- src/context.ts | 9 ++------- 7 files changed, 39 insertions(+), 38 deletions(-) create mode 100644 codecov.yml diff --git a/.prettierrc.json b/.prettierrc.json index 1339e9b..d8339f6 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,5 +1,5 @@ { - "printWidth": 120, + "printWidth": 240, "tabWidth": 2, "useTabs": false, "semi": true, diff --git a/__tests__/buildx.test.ts b/__tests__/buildx.test.ts index 84ff992..8e65651 100644 --- a/__tests__/buildx.test.ts +++ b/__tests__/buildx.test.ts @@ -128,9 +128,20 @@ describe('parseVersion', () => { test.each([ ['github.com/docker/buildx 0.4.1+azure bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'], ['github.com/docker/buildx v0.4.1 bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'], - ['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2'] + ['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2'], + ['github.com/docker/buildx f117971 f11797113e5a9b86bd976329c5dbb8a8bfdfadfa', 'f117971'] ])('given %p', async (stdout, expected) => { - expect(await buildx.parseVersion(stdout)).toEqual(expected); + expect(buildx.parseVersion(stdout)).toEqual(expected); + }); +}); + +describe('satisfies', () => { + test.each([ + ['0.4.1', '>=0.3.2', true], + ['bda4882a65349ca359216b135896bddc1d92461c', '>0.1.0', false], + ['f117971', '>0.6.0', true] + ])('given %p', async (version, range, expected) => { + expect(buildx.satisfies(version, range)).toBe(expected); }); }); @@ -142,13 +153,7 @@ describe('getSecret', () => { ['aaaaaaaa', false, '', '', true], ['aaaaaaaa=', false, '', '', true], ['=bbbbbbb', false, '', '', true], - [ - `foo=${path.join(__dirname, 'fixtures', 'secret.txt').split(path.sep).join(path.posix.sep)}`, - true, - 'foo', - 'bar', - false - ], + [`foo=${path.join(__dirname, 'fixtures', 'secret.txt').split(path.sep).join(path.posix.sep)}`, true, 'foo', 'bar', false], [`notfound=secret`, true, '', '', true] ])('given %p key and %p secret', async (kvp, file, exKey, exValue, invalid) => { try { diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index e3d8686..3fc2cfe 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -565,13 +565,7 @@ FOO=bar` ); const res = await context.getInputList('secrets', true); console.log(res); - expect(res).toEqual([ - 'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', - 'MYSECRET=aaaaaaaa', - 'bbbbbbb', - 'ccccccccc', - 'FOO=bar' - ]); + expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']); }); it('large multiline values', async () => { diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..dc46984 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,3 @@ +comment: false +github_checks: + annotations: false diff --git a/dist/index.js b/dist/index.js index 20be0cc..621487e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.parseVersion = exports.getVersion = exports.isAvailable = exports.hasGitAuthToken = exports.isLocalOrTarExporter = exports.getSecret = exports.getSecretFile = exports.getSecretString = exports.getImageID = exports.getImageIDFile = void 0; +exports.satisfies = exports.parseVersion = exports.getVersion = exports.isAvailable = exports.hasGitAuthToken = exports.isLocalOrTarExporter = exports.getSecret = exports.getSecretFile = exports.getSecretString = exports.getImageID = exports.getImageIDFile = void 0; const sync_1 = __importDefault(__nccwpck_require__(8750)); const fs_1 = __importDefault(__nccwpck_require__(5747)); const path_1 = __importDefault(__nccwpck_require__(5622)); @@ -158,15 +158,17 @@ function getVersion() { } exports.getVersion = getVersion; function parseVersion(stdout) { - return __awaiter(this, void 0, void 0, function* () { - const matches = /\sv?([0-9.]+)/.exec(stdout); - if (!matches) { - throw new Error(`Cannot parse buildx version`); - } - return semver.clean(matches[1]); - }); + const matches = /\sv?([0-9a-f]{7}|[0-9.]+)/.exec(stdout); + if (!matches) { + throw new Error(`Cannot parse buildx version`); + } + return matches[1]; } exports.parseVersion = parseVersion; +function satisfies(version, range) { + return semver.satisfies(version, range) || /^[0-9a-f]{7}$/.exec(version) !== null; +} +exports.satisfies = satisfies; //# sourceMappingURL=buildx.js.map /***/ }), @@ -213,7 +215,6 @@ const sync_1 = __importDefault(__nccwpck_require__(8750)); const fs = __importStar(__nccwpck_require__(5747)); const os = __importStar(__nccwpck_require__(2087)); const path = __importStar(__nccwpck_require__(5622)); -const semver = __importStar(__nccwpck_require__(1383)); const tmp = __importStar(__nccwpck_require__(8517)); const core = __importStar(__nccwpck_require__(2186)); const command_1 = __nccwpck_require__(5241); @@ -307,8 +308,7 @@ function getBuildArgs(inputs, defaultContext, buildxVersion) { yield exports.asyncForEach(inputs.outputs, (output) => __awaiter(this, void 0, void 0, function* () { args.push('--output', output); })); - if (!buildx.isLocalOrTarExporter(inputs.outputs) && - (inputs.platforms.length == 0 || semver.satisfies(buildxVersion, '>=0.4.2'))) { + if (!buildx.isLocalOrTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || buildx.satisfies(buildxVersion, '>=0.4.2'))) { args.push('--iidfile', yield buildx.getImageIDFile()); } yield exports.asyncForEach(inputs.cacheFrom, (cacheFrom) => __awaiter(this, void 0, void 0, function* () { diff --git a/src/buildx.ts b/src/buildx.ts index b36bffe..d624b6b 100644 --- a/src/buildx.ts +++ b/src/buildx.ts @@ -107,10 +107,14 @@ export async function getVersion(): Promise { }); } -export async function parseVersion(stdout: string): Promise { - const matches = /\sv?([0-9.]+)/.exec(stdout); +export function parseVersion(stdout: string): string { + const matches = /\sv?([0-9a-f]{7}|[0-9.]+)/.exec(stdout); if (!matches) { throw new Error(`Cannot parse buildx version`); } - return semver.clean(matches[1]); + return matches[1]; +} + +export function satisfies(version: string, range: string): boolean { + return semver.satisfies(version, range) || /^[0-9a-f]{7}$/.exec(version) !== null; } diff --git a/src/context.ts b/src/context.ts index aa0629a..552b0fe 100644 --- a/src/context.ts +++ b/src/context.ts @@ -46,9 +46,7 @@ export function defaultContext(): string { if (github.context.sha && !ref.startsWith(`refs/pull/`)) { ref = github.context.sha; } - _defaultContext = `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${github.context.repo.owner}/${ - github.context.repo.repo - }.git#${ref}`; + _defaultContext = `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${github.context.repo.owner}/${github.context.repo.repo}.git#${ref}`; } return _defaultContext; } @@ -121,10 +119,7 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio await asyncForEach(inputs.outputs, async output => { args.push('--output', output); }); - if ( - !buildx.isLocalOrTarExporter(inputs.outputs) && - (inputs.platforms.length == 0 || semver.satisfies(buildxVersion, '>=0.4.2')) - ) { + if (!buildx.isLocalOrTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || buildx.satisfies(buildxVersion, '>=0.4.2'))) { args.push('--iidfile', await buildx.getImageIDFile()); } await asyncForEach(inputs.cacheFrom, async cacheFrom => {