Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
CrazyMax committed Aug 12, 2020
1 parent ec2628b commit 26b3a3b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
7 changes: 7 additions & 0 deletions setup-buildx/__tests__/buildx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 17 additions & 12 deletions setup-buildx/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions setup-buildx/src/buildx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ export async function countBuilders(): Promise<number> {
});
}

export async function platforms(): Promise<String | undefined> {
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<string> {
const release: github.GitHubRelease | null = await github.getRelease(inputVersion);
if (!release) {
Expand Down
15 changes: 1 addition & 14 deletions setup-buildx/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,8 @@ async function run(): Promise<void> {
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);
}
Expand Down

0 comments on commit 26b3a3b

Please sign in to comment.