2020-08-19 00:19:47 +08:00
|
|
|
import * as mexec from './exec';
|
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as exec from '@actions/exec';
|
2021-04-24 05:25:00 +08:00
|
|
|
import {issueCommand} from '@actions/core/lib/command';
|
2020-08-19 00:19:47 +08:00
|
|
|
|
|
|
|
interface Platforms {
|
|
|
|
supported: string[];
|
|
|
|
available: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
try {
|
2021-04-16 22:29:05 +08:00
|
|
|
core.startGroup(`Docker info`);
|
|
|
|
await exec.exec('docker', ['version']);
|
|
|
|
await exec.exec('docker', ['info']);
|
|
|
|
core.endGroup();
|
2020-08-19 00:19:47 +08:00
|
|
|
|
|
|
|
const image: string = core.getInput('image') || 'tonistiigi/binfmt:latest';
|
|
|
|
const platforms: string = core.getInput('platforms') || 'all';
|
|
|
|
|
2021-04-02 17:47:52 +08:00
|
|
|
core.startGroup(`Pulling binfmt Docker image`);
|
|
|
|
await exec.exec('docker', ['pull', image]);
|
|
|
|
core.endGroup();
|
|
|
|
|
2021-05-26 21:46:14 +08:00
|
|
|
core.startGroup(`Image info`);
|
|
|
|
await exec.exec('docker', ['image', 'inspect', image]);
|
|
|
|
core.endGroup();
|
|
|
|
|
2021-04-02 17:47:52 +08:00
|
|
|
core.startGroup(`Installing QEMU static binaries`);
|
2020-08-19 00:19:47 +08:00
|
|
|
await exec.exec('docker', ['run', '--rm', '--privileged', image, '--install', platforms]);
|
2021-04-02 17:47:52 +08:00
|
|
|
core.endGroup();
|
2020-08-19 00:19:47 +08:00
|
|
|
|
2021-04-02 17:47:52 +08:00
|
|
|
core.startGroup(`Extracting available platforms`);
|
2020-08-19 00:19:47 +08:00
|
|
|
await mexec.exec(`docker`, ['run', '--rm', '--privileged', image], true).then(res => {
|
|
|
|
if (res.stderr != '' && !res.success) {
|
|
|
|
throw new Error(res.stderr);
|
|
|
|
}
|
|
|
|
const platforms: Platforms = JSON.parse(res.stdout.trim());
|
|
|
|
core.info(`${platforms.supported.join(',')}`);
|
2021-04-24 05:25:00 +08:00
|
|
|
setOutput('platforms', platforms.supported.join(','));
|
2020-08-19 00:19:47 +08:00
|
|
|
});
|
2021-04-02 17:47:52 +08:00
|
|
|
core.endGroup();
|
2020-08-19 00:19:47 +08:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-24 05:25:00 +08:00
|
|
|
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
|
|
|
|
function setOutput(name: string, value: any): void {
|
|
|
|
issueCommand('set-output', {name}, value);
|
|
|
|
}
|
|
|
|
|
2020-08-19 00:19:47 +08:00
|
|
|
run();
|