Skip to content

Commit 4b43307

Browse files
committed
feat(github-actions): create browserstack initialization action (#1942)
Create action to set initial browserstack information PR Close #1942
1 parent 9bf2527 commit 4b43307

File tree

8 files changed

+198
-0
lines changed

8 files changed

+198
-0
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ng-dev/utils/protos/*.js
77
.github/local-actions/lock-closed/main.js
88
github-actions/bazel/configure-remote/configure-remote.cjs
99
github-actions/branch-manager/main.js
10+
github-actions/browserstack/set-browserstack-env.cjs
1011
github-actions/commit-message-based-labels/main.js
1112
github-actions/create-pr-for-changes/main.js
1213
github-actions/feature-request/main.js
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
4+
copy_to_bin(
5+
name = "browserstack_token",
6+
srcs = ["browserstack_token.data"],
7+
)
8+
9+
ts_library(
10+
name = "browserstack",
11+
srcs = glob(["*.ts"]),
12+
# TODO(devversion): Remove this when `ts_library` supports `.mts` extension.
13+
devmode_module = "commonjs",
14+
deps = [
15+
"@npm//@actions/core",
16+
"@npm//@types/node",
17+
],
18+
)
19+
20+
nodejs_binary(
21+
name = "encrypt",
22+
data = [":browserstack"],
23+
entry_point = ":encrypt.ts",
24+
)
25+
26+
esbuild(
27+
name = "bundle",
28+
srcs = [":browserstack_token"],
29+
args = {
30+
"loader": {
31+
".data": "binary",
32+
},
33+
},
34+
entry_point = "index.ts",
35+
format = "iife",
36+
minify = True,
37+
sourcemap = "",
38+
deps = [":browserstack"],
39+
)
40+
41+
generated_file_test(
42+
name = "set_browserstack_env",
43+
src = "set-browserstack-env.cjs",
44+
generated = ":bundle.js",
45+
)
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Config browserstack'
2+
description: 'Set browserstack environmental variables'
3+
author: 'Angular'
4+
5+
runs:
6+
using: composite
7+
steps:
8+
- run: node $GITHUB_ACTION_PATH/set-browserstack-env.cjs
9+
env:
10+
NGAT: 'd56ftXEUwkfHJy5+rGBqNA=='
11+
shell: bash
100 Bytes
Binary file not shown.
+14
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 = process.env.NGAT!;
13+
export const k = owner.padEnd(32, '<');
14+
export const iv = '104149904141653713';
+20
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'));

github-actions/browserstack/index.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
// @ts-ignore
10+
import tokenRaw from './browserstack_token.data';
11+
import {k, iv, alg, at} from './constants.js';
12+
import {createDecipheriv} from 'crypto';
13+
import {exportVariable, setSecret} from '@actions/core';
14+
15+
interface BrowserStackInfoObject {
16+
BROWSER_STACK_USERNAME: string;
17+
BROWSER_STACK_ACCESS_KEY: string;
18+
}
19+
20+
async function main() {
21+
const t: Uint8Array = tokenRaw;
22+
const dcip = createDecipheriv(alg, k, iv).setAuthTag(Buffer.from(at, 'base64'));
23+
const dec = dcip.update(t, undefined, 'utf8') + dcip.final('utf8');
24+
const {BROWSER_STACK_USERNAME, BROWSER_STACK_ACCESS_KEY} = JSON.parse(
25+
dec,
26+
) as BrowserStackInfoObject;
27+
// Register the access key as a secret to prevent it from being logged.
28+
setSecret(BROWSER_STACK_ACCESS_KEY);
29+
// Set the borwserstack access key and username as environment variables.
30+
exportVariable('BROWSER_STACK_ACCESS_KEY', BROWSER_STACK_ACCESS_KEY);
31+
exportVariable('BROWSER_STACK_USERNAME', BROWSER_STACK_USERNAME);
32+
}
33+
34+
main().catch((e) => {
35+
console.error(e);
36+
process.exitCode = 1;
37+
});

github-actions/browserstack/set-browserstack-env.cjs

+70
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)