2020-08-18 18:19:47 +02:00
|
|
|
import * as os from 'os';
|
|
|
|
import * as mexec from './exec';
|
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as exec from '@actions/exec';
|
|
|
|
|
|
|
|
interface Platforms {
|
|
|
|
supported: string[];
|
|
|
|
available: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
try {
|
|
|
|
if (os.platform() !== 'linux') {
|
|
|
|
core.setFailed('Only supported on linux platform');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const image: string = core.getInput('image') || 'tonistiigi/binfmt:latest';
|
|
|
|
const platforms: string = core.getInput('platforms') || 'all';
|
|
|
|
|
2021-04-02 11:47:52 +02:00
|
|
|
core.startGroup(`Pulling binfmt Docker image`);
|
|
|
|
await exec.exec('docker', ['pull', image]);
|
|
|
|
core.endGroup();
|
|
|
|
|
|
|
|
core.startGroup(`Installing QEMU static binaries`);
|
2020-08-18 18:19:47 +02:00
|
|
|
await exec.exec('docker', ['run', '--rm', '--privileged', image, '--install', platforms]);
|
2021-04-02 11:47:52 +02:00
|
|
|
core.endGroup();
|
2020-08-18 18:19:47 +02:00
|
|
|
|
2021-04-02 11:47:52 +02:00
|
|
|
core.startGroup(`Extracting available platforms`);
|
2020-08-18 18:19:47 +02: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(',')}`);
|
|
|
|
core.setOutput('platforms', platforms.supported.join(','));
|
|
|
|
});
|
2021-04-02 11:47:52 +02:00
|
|
|
core.endGroup();
|
2020-08-18 18:19:47 +02:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run();
|