1
+ import * as context from './context' ;
1
2
import * as core from '@actions/core' ;
2
3
import * as exec from '@actions/exec' ;
3
- import { issueCommand } from '@actions/core/lib/command' ;
4
4
5
5
interface Platforms {
6
6
supported : string [ ] ;
@@ -9,49 +9,47 @@ interface Platforms {
9
9
10
10
async function run ( ) : Promise < void > {
11
11
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
45
20
} ) ;
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
+ } ) ;
47
50
} catch ( error ) {
48
51
core . setFailed ( error . message ) ;
49
52
}
50
53
}
51
54
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
-
57
55
run ( ) ;
0 commit comments