2020-08-18 18:19:47 +02:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as exec from '@actions/exec';
|
2021-04-23 23:25:00 +02:00
|
|
|
import {issueCommand} from '@actions/core/lib/command';
|
2020-08-18 18:19:47 +02:00
|
|
|
|
|
|
|
interface Platforms {
|
|
|
|
supported: string[];
|
|
|
|
available: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
try {
|
2021-04-16 16:29:05 +02:00
|
|
|
core.startGroup(`Docker info`);
|
|
|
|
await exec.exec('docker', ['version']);
|
|
|
|
await exec.exec('docker', ['info']);
|
|
|
|
core.endGroup();
|
2020-08-18 18:19:47 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2021-05-26 15:46:14 +02:00
|
|
|
core.startGroup(`Image info`);
|
|
|
|
await exec.exec('docker', ['image', 'inspect', image]);
|
|
|
|
core.endGroup();
|
|
|
|
|
2021-04-02 11:47:52 +02:00
|
|
|
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`);
|
2022-10-08 18:23:57 +02: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 11:47:52 +02:00
|
|
|
core.endGroup();
|
2020-08-18 18:19:47 +02:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 23:25:00 +02:00
|
|
|
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
|
2022-03-22 20:15:50 +01:00
|
|
|
function setOutput(name: string, value: unknown): void {
|
2021-04-23 23:25:00 +02:00
|
|
|
issueCommand('set-output', {name}, value);
|
|
|
|
}
|
|
|
|
|
2020-08-18 18:19:47 +02:00
|
|
|
run();
|