Skip to content

Commit 25725d8

Browse files
committed
Use context for inputs
Signed-off-by: CrazyMax <[email protected]>
1 parent 8c1e35a commit 25725d8

File tree

5 files changed

+60
-42
lines changed

5 files changed

+60
-42
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ___
1313
* [Usage](#usage)
1414
* [Customizing](#customizing)
1515
* [inputs](#inputs)
16+
* [outputs](#outputs)
1617
* [Contributing](#contributing)
1718

1819
## Usage

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as core from '@actions/core';
2+
import {issueCommand} from '@actions/core/lib/command';
3+
4+
export interface Inputs {
5+
image: string;
6+
platforms: string;
7+
}
8+
9+
export function getInputs(): Inputs {
10+
return {
11+
image: core.getInput('image') || 'tonistiigi/binfmt:latest',
12+
platforms: core.getInput('platforms') || 'all'
13+
};
14+
}
15+
16+
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
17+
export function setOutput(name: string, value: unknown): void {
18+
issueCommand('set-output', {name}, value);
19+
}

src/main.ts

+38-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as context from './context';
12
import * as core from '@actions/core';
23
import * as exec from '@actions/exec';
3-
import {issueCommand} from '@actions/core/lib/command';
44

55
interface Platforms {
66
supported: string[];
@@ -9,49 +9,47 @@ interface Platforms {
99

1010
async function run(): Promise<void> {
1111
try {
12-
core.startGroup(`Docker info`);
13-
await exec.exec('docker', ['version']);
14-
await exec.exec('docker', ['info']);
15-
core.endGroup();
16-
17-
const image: string = core.getInput('image') || 'tonistiigi/binfmt:latest';
18-
const platforms: string = core.getInput('platforms') || 'all';
19-
20-
core.startGroup(`Pulling binfmt Docker image`);
21-
await exec.exec('docker', ['pull', image]);
22-
core.endGroup();
23-
24-
core.startGroup(`Image info`);
25-
await exec.exec('docker', ['image', 'inspect', image]);
26-
core.endGroup();
27-
28-
core.startGroup(`Installing QEMU static binaries`);
29-
await exec.exec('docker', ['run', '--rm', '--privileged', image, '--install', platforms]);
30-
core.endGroup();
31-
32-
core.startGroup(`Extracting available platforms`);
33-
await exec
34-
.getExecOutput('docker', ['run', '--rm', '--privileged', image], {
35-
ignoreReturnCode: true,
36-
silent: true
37-
})
38-
.then(res => {
39-
if (res.stderr.length > 0 && res.exitCode != 0) {
40-
throw new Error(res.stderr.trim());
41-
}
42-
const platforms: Platforms = JSON.parse(res.stdout.trim());
43-
core.info(`${platforms.supported.join(',')}`);
44-
setOutput('platforms', platforms.supported.join(','));
12+
const input: context.Inputs = context.getInputs();
13+
14+
await core.group(`Docker info`, async () => {
15+
await exec.exec('docker', ['version'], {
16+
failOnStdErr: false
17+
});
18+
await exec.exec('docker', ['info'], {
19+
failOnStdErr: false
4520
});
46-
core.endGroup();
21+
});
22+
23+
await core.group(`Pulling binfmt Docker image`, async () => {
24+
await exec.exec('docker', ['pull', input.image]);
25+
});
26+
27+
await core.group(`Image info`, async () => {
28+
await exec.exec('docker', ['image', 'inspect', input.image]);
29+
});
30+
31+
await core.group(`Installing QEMU static binaries`, async () => {
32+
await exec.exec('docker', ['run', '--rm', '--privileged', input.image, '--install', input.platforms]);
33+
});
34+
35+
await core.group(`Extracting available platforms`, async () => {
36+
await exec
37+
.getExecOutput('docker', ['run', '--rm', '--privileged', input.image], {
38+
ignoreReturnCode: true,
39+
silent: true
40+
})
41+
.then(res => {
42+
if (res.stderr.length > 0 && res.exitCode != 0) {
43+
throw new Error(res.stderr.trim());
44+
}
45+
const platforms: Platforms = JSON.parse(res.stdout.trim());
46+
core.info(`${platforms.supported.join(',')}`);
47+
context.setOutput('platforms', platforms.supported.join(','));
48+
});
49+
});
4750
} catch (error) {
4851
core.setFailed(error.message);
4952
}
5053
}
5154

52-
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
53-
function setOutput(name: string, value: unknown): void {
54-
issueCommand('set-output', {name}, value);
55-
}
56-
5755
run();

0 commit comments

Comments
 (0)