Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.github/local-actions/labels-sync/main.js
.github/local-actions/lock-closed/main.js
github-actions/bazel/configure-remote/configure-remote.cjs
github-actions/bazel/configure-remote/main.js
github-actions/branch-manager/main.js
github-actions/browserstack/set-browserstack-env.cjs
github-actions/pull-request-labeling/main.js
Expand Down
48 changes: 7 additions & 41 deletions github-actions/bazel/configure-remote/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,53 +1,19 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "generated_file_test", "nodejs_binary")
load("//tools:defaults.bzl", "esbuild", "ts_library")
load("//tools/node-to-shell-script:index.bzl", "nodejs_script_to_sh_script")

copy_to_bin(
name = "gcp_token",
srcs = ["gcp_token.data"],
)
load("//tools:defaults.bzl", "esbuild_checked_in", "ts_library")

ts_library(
name = "setup-bazel-remote-exec",
srcs = glob(["*.ts"]),
# TODO(devversion): Remove this when `ts_library` supports `.mts` extension.
devmode_module = "commonjs",
deps = [
"@npm//@actions/core",
"@npm//@types/node",
],
)

nodejs_binary(
name = "encrypt",
data = [":setup-bazel-remote-exec"],
entry_point = ":encrypt.ts",
)

esbuild(
name = "bundle",
srcs = [":gcp_token"],
args = {
"loader": {
".data": "binary",
},
},
esbuild_checked_in(
name = "main",
entry_point = "index.ts",
format = "iife",
minify = True,
sourcemap = "",
deps = [":setup-bazel-remote-exec"],
)

# TODO: determine if we can use the node script directly in github actions
nodejs_script_to_sh_script(
name = "script",
bundle_file = ":bundle.js",
output_file = "script.sh",
)

generated_file_test(
name = "configure-remote",
src = "configure-remote.cjs",
generated = ":bundle.js",
target = "node20",
deps = [
":setup-bazel-remote-exec",
],
)
2 changes: 1 addition & 1 deletion github-actions/bazel/configure-remote/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ inputs:
runs:
using: 'node20'
main: 'configure-remote.cjs'
main: 'main.js'
73 changes: 0 additions & 73 deletions github-actions/bazel/configure-remote/configure-remote.cjs

This file was deleted.

14 changes: 0 additions & 14 deletions github-actions/bazel/configure-remote/constants.ts

This file was deleted.

20 changes: 0 additions & 20 deletions github-actions/bazel/configure-remote/encrypt.ts

This file was deleted.

Binary file removed github-actions/bazel/configure-remote/gcp_token.data
Binary file not shown.
22 changes: 8 additions & 14 deletions github-actions/bazel/configure-remote/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
*/

// @ts-ignore-next-line
import tokenRaw from './gcp_token.data';
import {k, iv, alg, at} from './constants.js';
import {createDecipheriv} from 'crypto';
import path from 'path';
import fs from 'fs';
import os from 'os';
import {exportVariable, getBooleanInput, getInput} from '@actions/core';
import {exportVariable, getBooleanInput, getInput, notice} from '@actions/core';

async function main() {
const isWindows = os.platform() === 'win32';
const bazelRcPath = getInput('bazelrc', {required: false, trimWhitespace: true});
const allowWindowsRbe = getBooleanInput('allow_windows_rbe', {required: true});
const trustedBuild = getBooleanInput('trusted_build', {required: false});
const credential =
getInput('google_credential', {required: false, trimWhitespace: true}) ||
getEmbeddedCredential();
const credential = getInput('google_credential', {required: false, trimWhitespace: true});

// If no credential is provided, gracefully exit.
if (credential === '') {
notice('No credential was provided.', {title: 'Skipped setting up Bazel RBE'});
return;
}

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

/** Extract the embeeded credential from the action. */
function getEmbeddedCredential(): string {
const t: Uint8Array = tokenRaw;
const dcip = createDecipheriv(alg, k, iv).setAuthTag(Buffer.from(at, 'base64'));
return dcip.update(t, undefined, 'utf8') + dcip.final('utf8');
}

main().catch((e) => {
console.error(e);
process.exitCode = 1;
Expand Down
Loading
Loading