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