Skip to content

Commit 110186f

Browse files
committed
fix(github-actions): reenable bundled token for remote configurations
1 parent 5a3a86f commit 110186f

File tree

9 files changed

+164
-19441
lines changed

9 files changed

+164
-19441
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.github/local-actions/labels-sync/main.js
44
.github/local-actions/lock-closed/main.js
5-
github-actions/bazel/configure-remote/main.js
5+
github-actions/bazel/configure-remote/configure-remote.cjs
66
github-actions/branch-manager/main.js
77
github-actions/browserstack/set-browserstack-env.cjs
88
github-actions/pull-request-labeling/main.js
Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
1-
load("//tools:defaults.bzl", "esbuild_checked_in", "ts_library")
1+
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "generated_file_test", "nodejs_binary")
2+
load("//tools:defaults.bzl", "esbuild", "ts_library")
3+
load("//tools/node-to-shell-script:index.bzl", "nodejs_script_to_sh_script")
4+
5+
copy_to_bin(
6+
name = "gcp_token",
7+
srcs = ["gcp_token.data"],
8+
)
29

310
ts_library(
411
name = "setup-bazel-remote-exec",
512
srcs = glob(["*.ts"]),
13+
# TODO(devversion): Remove this when `ts_library` supports `.mts` extension.
14+
devmode_module = "commonjs",
615
deps = [
716
"@npm//@actions/core",
817
"@npm//@types/node",
918
],
1019
)
1120

12-
esbuild_checked_in(
13-
name = "main",
21+
nodejs_binary(
22+
name = "encrypt",
23+
data = [":setup-bazel-remote-exec"],
24+
entry_point = ":encrypt.ts",
25+
)
26+
27+
esbuild(
28+
name = "bundle",
29+
srcs = [":gcp_token"],
30+
args = {
31+
"loader": {
32+
".data": "binary",
33+
},
34+
},
1435
entry_point = "index.ts",
15-
target = "node20",
16-
deps = [
17-
":setup-bazel-remote-exec",
18-
],
36+
format = "iife",
37+
minify = True,
38+
sourcemap = "",
39+
deps = [":setup-bazel-remote-exec"],
40+
)
41+
42+
# TODO: determine if we can use the node script directly in github actions
43+
nodejs_script_to_sh_script(
44+
name = "script",
45+
bundle_file = ":bundle.js",
46+
output_file = "script.sh",
47+
)
48+
49+
generated_file_test(
50+
name = "configure-remote",
51+
src = "configure-remote.cjs",
52+
generated = ":bundle.js",
1953
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ inputs:
2222
2323
runs:
2424
using: 'node20'
25-
main: 'main.js'
25+
main: 'configure-remote.cjs'

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

Lines changed: 73 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
const owner = (process.env.CIRCLE_PROJECT_USERNAME ?? process.env.GITHUB_REPOSITORY_OWNER)!;
10+
11+
export const alg = 'aes-256-gcm';
12+
export const at = 'QwbjZ/z+yDtD+XZjKj9Ynw==';
13+
export const k = owner.padEnd(32, '<');
14+
export const iv = '000003213213123213';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {createCipheriv} from 'crypto';
10+
import {k, iv, alg} from './constants.js';
11+
import fs from 'fs';
12+
13+
const [inputPath, outputPath] = process.argv.slice(2);
14+
const input = fs.readFileSync(inputPath, 'utf8');
15+
const cip = createCipheriv(alg, k, iv);
16+
const enc = cip.update(input, 'utf8', 'binary') + cip.final('binary');
17+
18+
fs.writeFileSync(outputPath, enc, 'binary');
19+
20+
console.info('Auth tag:', cip.getAuthTag().toString('base64'));
Binary file not shown.

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@
77
*/
88

99
// @ts-ignore-next-line
10+
import tokenRaw from './gcp_token.data';
11+
import {k, iv, alg, at} from './constants.js';
12+
import {createDecipheriv} from 'crypto';
1013
import path from 'path';
1114
import fs from 'fs';
1215
import os from 'os';
13-
import {exportVariable, getBooleanInput, getInput, notice} from '@actions/core';
16+
import {exportVariable, getBooleanInput, getInput} from '@actions/core';
1417

1518
async function main() {
1619
const isWindows = os.platform() === 'win32';
1720
const bazelRcPath = getInput('bazelrc', {required: false, trimWhitespace: true});
1821
const allowWindowsRbe = getBooleanInput('allow_windows_rbe', {required: true});
1922
const trustedBuild = getBooleanInput('trusted_build', {required: false});
20-
const credential = getInput('google_credential', {required: false, trimWhitespace: true});
21-
22-
// If no credential is provided, gracefully exit.
23-
if (credential === '') {
24-
notice('No credential was provided.', {title: 'Skipped setting up Bazel RBE'});
25-
return;
26-
}
23+
const credential =
24+
getInput('google_credential', {required: false, trimWhitespace: true}) ||
25+
getEmbeddedCredential();
2726

2827
const destPath = isWindows
2928
? path.join(process.env.APPDATA!, 'gcloud/application_default_credentials.json')
@@ -56,6 +55,13 @@ async function readFileGracefully(filePath: string): Promise<string> {
5655
}
5756
}
5857

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+
5965
main().catch((e) => {
6066
console.error(e);
6167
process.exitCode = 1;

0 commit comments

Comments
 (0)