()
| 16 | import {exportVariable, getBooleanInput, getInput} from '@actions/core'; |
| 17 | |
| 18 | async function main() { |
| 19 | const isWindows = os.platform() === 'win32'; |
| 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(); |
| 26 | |
| 27 | const destPath = isWindows |
| 28 | ? path.join(process.env.APPDATA!, 'gcloud/application_default_credentials.json') |
| 29 | : path.join(process.env.HOME!, '.config/gcloud/application_default_credentials.json'); |
| 30 | |
| 31 | await fs.promises.mkdir(path.dirname(destPath), {recursive: true}); |
| 32 | await fs.promises.writeFile(destPath, credential, 'utf8'); |
| 33 | |
| 34 | const configMode = isWindows && !allowWindowsRbe ? 'remote-cache' : 'remote'; |
| 35 | |
| 36 | if (bazelRcPath) { |
| 37 | let content = await readFileGracefully(bazelRcPath); |
| 38 | content += ['', `build --config=${configMode}`, 'test --flaky_test_attempts=3'].join('\n'); |
| 39 | if (trustedBuild) { |
| 40 | content += `\nbuild --config=trusted-build`; |
| 41 | } |
| 42 | await fs.promises.writeFile(bazelRcPath, content, 'utf8'); |
| 43 | } |
| 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); |
| 48 | } |
| 49 | |
| 50 | async function readFileGracefully(filePath: string): Promise<string> { |
| 51 | try { |
no test coverage detected