Small refactor

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-08-12 22:56:20 +02:00
parent ec2628bb21
commit 26b3a3b0cd
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
4 changed files with 38 additions and 26 deletions

View file

@ -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) {

View file

@ -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);
}