@@ -89,24 +89,25 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
89
89
}
90
90
91
91
export async function getArgs ( inputs : Inputs , defaultContext : string , buildxVersion : string ) : Promise < Array < string > > {
92
- let args : Array < string > = [ 'buildx' ] ;
93
- args . push . apply ( args , await getBuildArgs ( inputs , defaultContext , buildxVersion ) ) ;
94
- args . push . apply ( args , await getCommonArgs ( inputs ) ) ;
95
- args . push ( inputs . context ) ;
96
- return args ;
92
+ return [
93
+ 'buildx' ,
94
+ ...await getBuildArgs ( inputs , defaultContext , buildxVersion ) ,
95
+ ...await getCommonArgs ( inputs ) ,
96
+ inputs . context ,
97
+ ] ;
97
98
}
98
99
99
100
async function getBuildArgs ( inputs : Inputs , defaultContext : string , buildxVersion : string ) : Promise < Array < string > > {
100
- let args : Array < string > = [ 'build' ] ;
101
- await asyncForEach ( inputs . buildArgs , async buildArg => {
102
- args . push ( '--build-arg' , buildArg ) ;
103
- } ) ;
104
- await asyncForEach ( inputs . labels , async label => {
105
- args . push ( '--label' , label ) ;
106
- } ) ;
107
- await asyncForEach ( inputs . tags , async tag => {
108
- args . push ( '--tag' , tag ) ;
109
- } ) ;
101
+ const args : Array < string > = [ 'build' ] . concat (
102
+ ... flagMap ( inputs . buildArgs , '--build-arg' ) ,
103
+ ... flagMap ( inputs . cacheFrom , '--cache-from' ) ,
104
+ ... flagMap ( inputs . cacheTo , '--cache-to' ) ,
105
+ ... flagMap ( inputs . labels , '-- label' ) ,
106
+ ... flagMap ( inputs . outputs , '--output' ) ,
107
+ ... flagMap ( inputs . tags , '--tag' ) ,
108
+ ... flagMap ( inputs . ssh , '--ssh' ) ,
109
+ ) ;
110
+
110
111
if ( inputs . target ) {
111
112
args . push ( '--target' , inputs . target ) ;
112
113
}
@@ -116,18 +117,9 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
116
117
if ( inputs . platforms . length > 0 ) {
117
118
args . push ( '--platform' , inputs . platforms . join ( ',' ) ) ;
118
119
}
119
- await asyncForEach ( inputs . outputs , async output => {
120
- args . push ( '--output' , output ) ;
121
- } ) ;
122
120
if ( ! buildx . isLocalOrTarExporter ( inputs . outputs ) && ( inputs . platforms . length == 0 || buildx . satisfies ( buildxVersion , '>=0.4.2' ) ) ) {
123
121
args . push ( '--iidfile' , await buildx . getImageIDFile ( ) ) ;
124
122
}
125
- await asyncForEach ( inputs . cacheFrom , async cacheFrom => {
126
- args . push ( '--cache-from' , cacheFrom ) ;
127
- } ) ;
128
- await asyncForEach ( inputs . cacheTo , async cacheTo => {
129
- args . push ( '--cache-to' , cacheTo ) ;
130
- } ) ;
131
123
await asyncForEach ( inputs . secrets , async secret => {
132
124
try {
133
125
args . push ( '--secret' , await buildx . getSecretString ( secret ) ) ;
@@ -145,9 +137,6 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
145
137
if ( inputs . githubToken && ! buildx . hasGitAuthToken ( inputs . secrets ) && inputs . context == defaultContext ) {
146
138
args . push ( '--secret' , await buildx . getSecretString ( `GIT_AUTH_TOKEN=${ inputs . githubToken } ` ) ) ;
147
139
}
148
- await asyncForEach ( inputs . ssh , async ssh => {
149
- args . push ( '--ssh' , ssh ) ;
150
- } ) ;
151
140
if ( inputs . file ) {
152
141
args . push ( '--file' , inputs . file ) ;
153
142
}
@@ -210,6 +199,10 @@ export const asyncForEach = async (array, callback) => {
210
199
}
211
200
} ;
212
201
202
+ export function flagMap ( array : string [ ] , flag : string ) : string [ ] [ ] {
203
+ return array . map ( value => [ flag , value ] ) ;
204
+ }
205
+
213
206
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
214
207
export function setOutput ( name : string , value : any ) : void {
215
208
issueCommand ( 'set-output' , { name} , value ) ;
0 commit comments