Skip to content

Commit 8f0ab4d

Browse files
committed
feat(github-actions): allow a credential to be provided for configuring remote bazel setup
Allow an input for a credential to provide authentication for RBE setup.
1 parent 9040cfb commit 8f0ab4d

File tree

6 files changed

+69
-49
lines changed

6 files changed

+69
-49
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
- uses: ./github-actions/npm/checkout-and-setup-node
2828
- uses: ./github-actions/bazel/setup
2929
- uses: ./github-actions/bazel/configure-remote
30+
with:
31+
trusted_build: true
3032
- run: yarn install --immutable
3133
- name: Confirm code builds with typescript as expected
3234
run: yarn tsc -p tsconfig.json
@@ -42,6 +44,8 @@ jobs:
4244
- uses: ./github-actions/npm/checkout-and-setup-node
4345
- uses: ./github-actions/bazel/setup
4446
- uses: ./github-actions/bazel/configure-remote
47+
with:
48+
trusted_build: true
4549
- run: yarn install --immutable
4650
- run: yarn bazel test -- //...
4751

.github/workflows/pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
- uses: ./github-actions/npm/checkout-and-setup-node
2727
- uses: ./github-actions/bazel/setup
2828
- uses: ./github-actions/bazel/configure-remote
29+
with:
30+
trusted_build: true
2931
- run: yarn install --immutable
3032
- name: Check code format
3133
run: yarn ng-dev format changed --check ${{ github.event.pull_request.base.sha }}

github-actions/bazel/configure-remote/action.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ inputs:
1212
description: |
1313
Whether to allow remote execution to be configured for Windows. By default,
1414
Windows is only configured to leverage remote caching.
15-
16-
shell:
17-
default: bash
18-
description: Shell to use for executing the configure script.
15+
trusted_build:
16+
default: false
17+
description: |
18+
Whether to enable the flag for performing additional configurations for
19+
trusted builds on CI.
20+
google_credential:
21+
description: |
22+
A Google credential to be used as authentication for RBE API usages.
1923
2024
runs:
21-
using: composite
22-
steps:
23-
- run: node $GITHUB_ACTION_PATH/configure-remote.cjs
24-
env:
25-
BAZELRC_PATH: ${{ inputs.bazelrc }}
26-
ALLOW_WINDOWS_RBE: ${{ inputs.allow_windows_rbe }}
27-
NGAT: 'bKddxrYADouso3haW7lCFA=='
28-
shell: ${{ inputs.shell }}
25+
using: 'node20'
26+
main: 'configure-remote.cjs'

github-actions/bazel/configure-remote/configure-remote.cjs

Lines changed: 28 additions & 27 deletions
Large diffs are not rendered by default.

github-actions/bazel/configure-remote/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
const owner = (process.env.CIRCLE_PROJECT_USERNAME ?? process.env.GITHUB_REPOSITORY_OWNER)!;
1010

1111
export const alg = 'aes-256-gcm';
12-
export const at = process.env.NGAT!;
12+
export const at = 'bKddxrYADouso3haW7lCFA==';
1313
export const k = owner.padEnd(32, '<');
1414
export const iv = '000003213213123213';

github-actions/bazel/configure-remote/index.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,42 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// @ts-ignore
9+
// @ts-ignore-next-line
1010
import tokenRaw from './gcp_token.data';
1111
import {k, iv, alg, at} from './constants.js';
1212
import {createDecipheriv} from 'crypto';
1313
import path from 'path';
1414
import fs from 'fs';
1515
import 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

Comments
 (0)