66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- // @ts -ignore
9+ // @ts -ignore-next-line
1010import tokenRaw from './gcp_token.data' ;
1111import { k , iv , alg , at } from './constants.js' ;
1212import { createDecipheriv } from 'crypto' ;
1313import path from 'path' ;
1414import fs from 'fs' ;
1515import os from 'os' ;
16+ import { exportVariable , getBooleanInput , getInput } from '@actions/core' ;
1617
17- async function main ( bazelRcPath : string | undefined ) {
18+ async function main ( ) {
1819 const isWindows = os . platform ( ) === 'win32' ;
19- const t : Uint8Array = tokenRaw ;
20- const dcip = createDecipheriv ( alg , k , iv ) . setAuthTag ( Buffer . from ( at , 'base64' ) ) ;
21- const dec = dcip . update ( t , undefined , 'utf8' ) + dcip . final ( 'utf8' ) ;
20+ const bazelRcPath = getInput ( 'bazelrc' , { required : false , trimWhitespace : true } ) ;
21+ const allowWindowsRbe = getBooleanInput ( 'allow_windows_rbe' , { required : true } ) ;
22+ const trustedBuild = getBooleanInput ( 'trusted_build' , { required : false } ) ;
23+ const credential =
24+ getInput ( 'google_credential' , { required : false , trimWhitespace : true } ) ||
25+ getEmbeddedCredential ( ) ;
2226
2327 const destPath = isWindows
2428 ? path . join ( process . env . APPDATA ! , 'gcloud/application_default_credentials.json' )
2529 : path . join ( process . env . HOME ! , '.config/gcloud/application_default_credentials.json' ) ;
2630
2731 await fs . promises . mkdir ( path . dirname ( destPath ) , { recursive : true } ) ;
28- await fs . promises . writeFile ( destPath , dec , 'utf8' ) ;
32+ await fs . promises . writeFile ( destPath , credential , 'utf8' ) ;
33+
34+ const configMode = isWindows && ! allowWindowsRbe ? 'remote-cache' : 'remote' ;
2935
3036 if ( bazelRcPath ) {
3137 let content = await readFileGracefully ( bazelRcPath ) ;
32- if ( isWindows ) {
33- // Set the config to remote-cache as we do not have support for RBE on windows at this time
34- content += '\nbuild --config=remote-cache' ;
35- } else {
36- content += '\nbuild --config=remote' ;
38+ content += `\nbuild --config=${ configMode } ` ;
39+ if ( trustedBuild ) {
40+ content += `\nbuild --config=trusted-build` ;
3741 }
3842 await fs . promises . writeFile ( bazelRcPath , content , 'utf8' ) ;
3943 }
44+
45+ // Expose application credentials as variable. This may not be necessary with the default
46+ // path being used for credentials, but it's helpful when we cross boundaries with e.g. WSL.
47+ exportVariable ( 'GOOGLE_APPLICATION_CREDENTIALS' , destPath ) ;
4048}
4149
4250async function readFileGracefully ( filePath : string ) : Promise < string > {
@@ -47,7 +55,14 @@ async function readFileGracefully(filePath: string): Promise<string> {
4755 }
4856}
4957
50- main ( process . env . BAZELRC_PATH ) . catch ( ( e ) => {
58+ /** Extract the embeeded credential from the action. */
59+ function getEmbeddedCredential ( ) : string {
60+ const t : Uint8Array = tokenRaw ;
61+ const dcip = createDecipheriv ( alg , k , iv ) . setAuthTag ( Buffer . from ( at , 'base64' ) ) ;
62+ return dcip . update ( t , undefined , 'utf8' ) + dcip . final ( 'utf8' ) ;
63+ }
64+
65+ main ( ) . catch ( ( e ) => {
5166 console . error ( e ) ;
5267 process . exitCode = 1 ;
5368} ) ;
0 commit comments