@@ -89,24 +89,25 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
8989}
9090
9191export 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+ ] ;
9798}
9899
99100async 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+
110111 if ( inputs . target ) {
111112 args . push ( '--target' , inputs . target ) ;
112113 }
@@ -116,18 +117,9 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
116117 if ( inputs . platforms . length > 0 ) {
117118 args . push ( '--platform' , inputs . platforms . join ( ',' ) ) ;
118119 }
119- await asyncForEach ( inputs . outputs , async output => {
120- args . push ( '--output' , output ) ;
121- } ) ;
122120 if ( ! buildx . isLocalOrTarExporter ( inputs . outputs ) && ( inputs . platforms . length == 0 || buildx . satisfies ( buildxVersion , '>=0.4.2' ) ) ) {
123121 args . push ( '--iidfile' , await buildx . getImageIDFile ( ) ) ;
124122 }
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- } ) ;
131123 await asyncForEach ( inputs . secrets , async secret => {
132124 try {
133125 args . push ( '--secret' , await buildx . getSecretString ( secret ) ) ;
@@ -145,9 +137,6 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
145137 if ( inputs . githubToken && ! buildx . hasGitAuthToken ( inputs . secrets ) && inputs . context == defaultContext ) {
146138 args . push ( '--secret' , await buildx . getSecretString ( `GIT_AUTH_TOKEN=${ inputs . githubToken } ` ) ) ;
147139 }
148- await asyncForEach ( inputs . ssh , async ssh => {
149- args . push ( '--ssh' , ssh ) ;
150- } ) ;
151140 if ( inputs . file ) {
152141 args . push ( '--file' , inputs . file ) ;
153142 }
@@ -210,6 +199,10 @@ export const asyncForEach = async (array, callback) => {
210199 }
211200} ;
212201
202+ export function flagMap ( array : string [ ] , flag : string ) : string [ ] [ ] {
203+ return array . map ( value => [ flag , value ] ) ;
204+ }
205+
213206// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
214207export function setOutput ( name : string , value : any ) : void {
215208 issueCommand ( 'set-output' , { name} , value ) ;
0 commit comments