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 } from '@actions/core' ;
16+ import { exportVariable , getBooleanInput , getInput } from '@actions/core' ;
1717
18- async function main ( bazelRcPath : string | undefined ) {
18+ async function main ( ) {
1919 const isWindows = os . platform ( ) === 'win32' ;
20- const t : Uint8Array = tokenRaw ;
21- const dcip = createDecipheriv ( alg , k , iv ) . setAuthTag ( Buffer . from ( at , 'base64' ) ) ;
22- 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 : true } ) ;
23+
24+ // If no credential is provided as an input, `getInput` will return an empty string allowing
25+ // us to default to the embedded credential.
26+ const credential =
27+ getInput ( 'google_credential' , { required : false , trimWhitespace : true } ) ||
28+ getEmbeddedCredential ( ) ;
2329
2430 const destPath = isWindows
2531 ? path . join ( process . env . APPDATA ! , 'gcloud/application_default_credentials.json' )
2632 : path . join ( process . env . HOME ! , '.config/gcloud/application_default_credentials.json' ) ;
2733
2834 await fs . promises . mkdir ( path . dirname ( destPath ) , { recursive : true } ) ;
29- await fs . promises . writeFile ( destPath , dec , 'utf8' ) ;
35+ await fs . promises . writeFile ( destPath , credential , 'utf8' ) ;
3036
31- const allowWindowsRbe = process . env [ 'ALLOW_WINDOWS_RBE' ] === 'true' ;
3237 const configMode = isWindows && ! allowWindowsRbe ? 'remote-cache' : 'remote' ;
3338
3439 if ( bazelRcPath ) {
3540 let content = await readFileGracefully ( bazelRcPath ) ;
3641 content += `\nbuild --config=${ configMode } ` ;
42+ if ( trustedBuild ) {
43+ content += `\nbuild --config=trusted-build` ;
44+ }
3745 await fs . promises . writeFile ( bazelRcPath , content , 'utf8' ) ;
3846 }
3947
@@ -50,7 +58,14 @@ async function readFileGracefully(filePath: string): Promise<string> {
5058 }
5159}
5260
53- main ( process . env . BAZELRC_PATH ) . catch ( ( e ) => {
61+ /** Extract the embeeded credential from the action. */
62+ function getEmbeddedCredential ( ) : string {
63+ const t : Uint8Array = tokenRaw ;
64+ const dcip = createDecipheriv ( alg , k , iv ) . setAuthTag ( Buffer . from ( at , 'base64' ) ) ;
65+ return dcip . update ( t , undefined , 'utf8' ) + dcip . final ( 'utf8' ) ;
66+ }
67+
68+ main ( ) . catch ( ( e ) => {
5469 console . error ( e ) ;
5570 process . exitCode = 1 ;
5671} ) ;
0 commit comments