@@ -269,22 +269,12 @@ export class Install {
269269 await io . mkdirP ( limaDir ) ;
270270 const dockerHost = `unix://${ limaDir } /docker.sock` ;
271271
272- // avoid brew to auto update and upgrade unrelated packages.
273- let envs = Object . assign ( { } , process . env , {
274- HOMEBREW_NO_AUTO_UPDATE : '1' ,
275- HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK : '1'
276- } ) as {
277- [ key : string ] : string ;
278- } ;
279-
280272 if ( ! ( await Install . limaInstalled ( ) ) ) {
281- await core . group ( 'Installing lima' , async ( ) => {
282- await Exec . exec ( 'brew' , [ 'install' , 'lima' ] , { env : envs } ) ;
283- } ) ;
273+ await this . brewInstall ( 'lima' ) ;
284274 }
285275
286276 await core . group ( 'Lima version' , async ( ) => {
287- await Exec . exec ( 'lima' , [ '--version' ] , { env : envs } ) ;
277+ await Exec . exec ( 'lima' , [ '--version' ] ) ;
288278 } ) ;
289279
290280 await core . group ( 'Creating lima config' , async ( ) => {
@@ -313,9 +303,8 @@ export class Install {
313303 } ) ;
314304
315305 if ( ! ( await Install . qemuInstalled ( ) ) ) {
316- await core . group ( 'Installing QEMU' , async ( ) => {
317- await Exec . exec ( 'brew' , [ 'install' , 'qemu' ] , { env : envs } ) ;
318- } ) ;
306+ // FIXME: QEMU 10.1.2 seems to break on GitHub runners. Pin to 10.1.1 in the meantime: https://github.com/docker/actions-toolkit/issues/852
307+ await this . brewInstall ( 'qemu' , '4a7a2dd5d44d068b3e89ebed5be7b4ada315d221' ) ;
319308 }
320309 const qemuBin = await Install . qemuBin ( ) ;
321310 await core . group ( 'QEMU version' , async ( ) => {
@@ -324,7 +313,7 @@ export class Install {
324313
325314 // lima might already be started on the runner so env var added in download
326315 // method is not expanded to the running process.
327- envs = Object . assign ( { } , envs , {
316+ const envs = Object . assign ( { } , process . env , {
328317 PATH : `${ this . toolDir } :${ process . env . PATH } `
329318 } ) as {
330319 [ key : string ] : string ;
@@ -751,4 +740,72 @@ EOF`,
751740 } ) ;
752741 return < Image > JSON . parse ( blob ) ;
753742 }
743+
744+ private async brewInstall ( packageName : string , revision ?: string ) : Promise < void > {
745+ // avoid brew to auto update and upgrade unrelated packages.
746+ const envs = Object . assign ( { } , process . env , {
747+ HOMEBREW_NO_AUTO_UPDATE : '1' ,
748+ HOMEBREW_NO_INSTALL_UPGRADE : '1' ,
749+ HOMEBREW_NO_INSTALL_CLEANUP : '1'
750+ } ) as {
751+ [ key : string ] : string ;
752+ } ;
753+
754+ await core . group ( `Installing ${ packageName } ` , async ( ) => {
755+ if ( ! revision ) {
756+ await Exec . exec ( 'brew' , [ 'install' , packageName ] ) ;
757+ } else {
758+ const dockerTap = 'docker-actions-toolkit/tap' ;
759+ const hasDockerTap = await Exec . getExecOutput ( 'brew' , [ 'tap' ] , {
760+ ignoreReturnCode : true ,
761+ silent : true ,
762+ env : envs
763+ } ) . then ( res => {
764+ if ( res . stderr . length > 0 && res . exitCode != 0 ) {
765+ throw new Error ( res . stderr ) ;
766+ }
767+ for ( const line of res . stdout . trim ( ) . split ( '\n' ) ) {
768+ if ( line . includes ( dockerTap ) ) {
769+ return true ;
770+ }
771+ }
772+ return false ;
773+ } ) ;
774+ if ( ! hasDockerTap ) {
775+ await Exec . exec ( 'brew' , [ 'tap-new' , dockerTap ] , { env : envs } ) ;
776+ }
777+ const brewRepoTapPath = await Exec . getExecOutput ( 'brew' , [ '--repo' , dockerTap ] , {
778+ ignoreReturnCode : true ,
779+ silent : true ,
780+ env : envs
781+ } ) . then ( res => {
782+ if ( res . stderr . length > 0 && res . exitCode != 0 ) {
783+ throw new Error ( res . stderr ) ;
784+ }
785+ return res . stdout . trim ( ) ;
786+ } ) ;
787+ const formulaURL = `https://raw.githubusercontent.com/Homebrew/homebrew-core/${ revision } /Formula/${ packageName . charAt ( 0 ) } /${ packageName } .rb` ;
788+ await tc . downloadTool ( formulaURL , path . join ( brewRepoTapPath , 'Formula' , `${ packageName } .rb` ) ) ;
789+ const hasFormulaInstalled = await Exec . getExecOutput ( 'brew' , [ 'ls' , '-1' ] , {
790+ ignoreReturnCode : true ,
791+ silent : true ,
792+ env : envs
793+ } ) . then ( res => {
794+ if ( res . stderr . length > 0 && res . exitCode != 0 ) {
795+ throw new Error ( res . stderr ) ;
796+ }
797+ for ( const line of res . stdout . trim ( ) . split ( '\n' ) ) {
798+ if ( line . trim ( ) == packageName ) {
799+ return true ;
800+ }
801+ }
802+ return false ;
803+ } ) ;
804+ if ( hasFormulaInstalled ) {
805+ await Exec . exec ( 'brew' , [ 'uninstall' , packageName , '--ignore-dependencies' ] , { env : envs } ) ;
806+ }
807+ await Exec . exec ( 'brew' , [ 'install' , `${ dockerTap } /${ packageName } ` ] , { env : envs } ) ;
808+ }
809+ } ) ;
810+ }
754811}
0 commit comments