forked from docker/setup-qemu-action
/
main.ts
55 lines (47 loc) · 1.59 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as context from './context';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
interface Platforms {
supported: string[];
available: string[];
}
async function run(): Promise<void> {
try {
const input: context.Inputs = context.getInputs();
await core.group(`Docker info`, async () => {
await exec.exec('docker', ['version'], {
failOnStdErr: false
});
await exec.exec('docker', ['info'], {
failOnStdErr: false
});
});
await core.group(`Pulling binfmt Docker image`, async () => {
await exec.exec('docker', ['pull', input.image]);
});
await core.group(`Image info`, async () => {
await exec.exec('docker', ['image', 'inspect', input.image]);
});
await core.group(`Installing QEMU static binaries`, async () => {
await exec.exec('docker', ['run', '--rm', '--privileged', input.image, '--install', input.platforms]);
});
await core.group(`Extracting available platforms`, async () => {
await exec
.getExecOutput('docker', ['run', '--rm', '--privileged', input.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(',')}`);
core.setOutput('platforms', platforms.supported.join(','));
});
});
} catch (error) {
core.setFailed(error.message);
}
}
run();