From 26b3a3b0cd675f389c368f172cc14d3dc2ac76c9 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 12 Aug 2020 22:56:20 +0200 Subject: [PATCH] Small refactor Signed-off-by: CrazyMax --- setup-buildx/__tests__/buildx.test.ts | 7 +++++++ setup-buildx/dist/index.js | 29 ++++++++++++++++----------- setup-buildx/src/buildx.ts | 13 ++++++++++++ setup-buildx/src/main.ts | 15 +------------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/setup-buildx/__tests__/buildx.test.ts b/setup-buildx/__tests__/buildx.test.ts index b4f2612..f72bd45 100644 --- a/setup-buildx/__tests__/buildx.test.ts +++ b/setup-buildx/__tests__/buildx.test.ts @@ -16,6 +16,13 @@ describe('buildx', () => { expect(countBuilders).toBeGreaterThan(0); }); + it('platforms', async () => { + const platforms = await buildx.platforms(); + console.log(`platforms: ${platforms}`); + expect(platforms).not.toBeUndefined(); + expect(platforms).not.toEqual(''); + }); + it('acquires v0.2.2 version of buildx', async () => { const buildxBin = await buildx.install('v0.2.2', tmpDir); console.log(buildxBin); diff --git a/setup-buildx/dist/index.js b/setup-buildx/dist/index.js index a654131..9e7178e 100644 --- a/setup-buildx/dist/index.js +++ b/setup-buildx/dist/index.js @@ -2522,17 +2522,7 @@ function run() { core.info('🐳 Docker info'); yield exec.exec('docker', ['info'], false); core.info('🛒 Extracting available platforms...'); - yield exec.exec(`docker`, ['buildx', 'inspect'], true).then(res => { - if (res.stderr != '' && !res.success) { - throw new Error(res.stderr); - } - for (const line of res.stdout.trim().split(os.EOL)) { - if (line.startsWith('Platforms')) { - core.setOutput('platforms', line.replace('Platforms: ', '').replace(/\s/g, '').trim()); - break; - } - } - }); + core.setOutput('platforms', yield buildx.platforms()); } catch (error) { core.setFailed(error.message); @@ -7239,7 +7229,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.install = exports.countBuilders = exports.isAvailable = void 0; +exports.install = exports.platforms = exports.countBuilders = exports.isAvailable = void 0; const fs = __importStar(__webpack_require__(747)); const os = __importStar(__webpack_require__(87)); const path = __importStar(__webpack_require__(622)); @@ -7272,6 +7262,21 @@ function countBuilders() { }); } exports.countBuilders = countBuilders; +function platforms() { + return __awaiter(this, void 0, void 0, function* () { + return yield exec.exec(`docker`, ['buildx', 'inspect'], true).then(res => { + if (res.stderr != '' && !res.success) { + throw new Error(res.stderr); + } + for (const line of res.stdout.trim().split(`\n`)) { + if (line.startsWith('Platforms')) { + return line.replace('Platforms: ', '').replace(/\s/g, '').trim(); + } + } + }); + }); +} +exports.platforms = platforms; function install(inputVersion, dockerConfigHome) { return __awaiter(this, void 0, void 0, function* () { const release = yield github.getRelease(inputVersion); diff --git a/setup-buildx/src/buildx.ts b/setup-buildx/src/buildx.ts index 9896be5..88fd5af 100644 --- a/setup-buildx/src/buildx.ts +++ b/setup-buildx/src/buildx.ts @@ -28,6 +28,19 @@ export async function countBuilders(): Promise { }); } +export async function platforms(): Promise { + return await exec.exec(`docker`, ['buildx', 'inspect'], true).then(res => { + if (res.stderr != '' && !res.success) { + throw new Error(res.stderr); + } + for (const line of res.stdout.trim().split(`\n`)) { + if (line.startsWith('Platforms')) { + return line.replace('Platforms: ', '').replace(/\s/g, '').trim(); + } + } + }); +} + export async function install(inputVersion: string, dockerConfigHome: string): Promise { const release: github.GitHubRelease | null = await github.getRelease(inputVersion); if (!release) { diff --git a/setup-buildx/src/main.ts b/setup-buildx/src/main.ts index 9ab2442..06f3b4b 100644 --- a/setup-buildx/src/main.ts +++ b/setup-buildx/src/main.ts @@ -50,21 +50,8 @@ async function run(): Promise { await exec.exec('docker', ['buildx', 'install'], false); } - core.info('🐳 Docker info'); - await exec.exec('docker', ['info'], false); - core.info('🛒 Extracting available platforms...'); - await exec.exec(`docker`, ['buildx', 'inspect'], true).then(res => { - if (res.stderr != '' && !res.success) { - throw new Error(res.stderr); - } - for (const line of res.stdout.trim().split(os.EOL)) { - if (line.startsWith('Platforms')) { - core.setOutput('platforms', line.replace('Platforms: ', '').replace(/\s/g, '').trim()); - break; - } - } - }); + core.setOutput('platforms', await buildx.platforms()); } catch (error) { core.setFailed(error.message); }