Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing for Bazel browser setup #397

Merged
merged 8 commits into from
Feb 12, 2022
Merged
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: 2 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ dist

bazel/integration/tests/angular-cli/.angular/
bazel/integration/tests/angular-cli/node_modules/
bazel/integration/tests/nested_bazel_workspaces/node_modules
bazel/integration/tests/package_mappings/node_modules/
bazel/integration/tests/playwright_chromium/node_modules
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0
5.0.0
96 changes: 71 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ version: 2.1

orbs:
buildalert: oss-tools/[email protected]
win: circleci/[email protected]

# **Note**: When updating the beginning of the cache key, also update the cache key to match
# the new cache key prefix. This allows us to take advantage of CircleCI's fallback caching.
# Read more here: https://circleci.com/docs/2.0/caching/#restoring-cache.
var_1: &cache_key v1-{{ checksum ".bazelversion" }}-{{ checksum "WORKSPACE" }}
# We invalidate the cache if the Bazel version changes. We do this because otherwise the `bazelisk`
# cache folder will contain all previously used versions and ultimately cause the cache
# restoring to be slower.
var_2: &cache_fallback_key v1-{{ checksum ".bazelversion" }}-
var_1: &cache_key v1-{{arch}}-{{ checksum ".bazelversion" }}-{{ checksum "WORKSPACE" }}
# We use a different cache if the Bazel version changes, or if the executor is a different one.
# We do this because otherwise the `bazelisk` cache folder will contain all previously used
# versions and ultimately cause the cache restoring to be slower.
var_2: &cache_fallback_key v1-{{arch}}-{{ checksum ".bazelversion" }}-

var_3: &gcp_decrypt_token 'angular'

Expand All @@ -29,20 +30,36 @@ var_5: &save_cache
- '~/.cache/bazelisk'
- '~/bazel_repository_cache'

var_6: &default_executor_settings
parameters:
resource_class:
type: string
default: medium
environment:
GCP_DECRYPT_TOKEN: *gcp_decrypt_token
resource_class: << parameters.resource_class >>
working_directory: ~/ng

var_7: &main_upstream_branches_filter
branches:
only:
- main
# Additional branch that can be used to test the snapshot build output.
# Developers can just push to that branch to test the built artifact.
- snapshot-test

# Executor Definitions
# https://circleci.com/docs/2.0/reusing-config/#authoring-reusable-executors
executors:
default-executor:
parameters:
resource_class:
type: string
default: medium
environment:
GCP_DECRYPT_TOKEN: *gcp_decrypt_token
docker-linux-executor:
<<: *default_executor_settings
docker:
- image: cimg/node:16.10.0-browsers@sha256:83ff2dcad3043c4b3f7f58513805a0c8757ba5541a1f3c213f80bd242a3c77ac
resource_class: << parameters.resource_class >>
working_directory: ~/ng

macos-x64-executor:
<<: *default_executor_settings
macos:
xcode: '13.3.0'

# Command Definitions
# https://circleci.com/docs/2.0/reusing-config/#authoring-reusable-commands
Expand All @@ -64,7 +81,7 @@ commands:
setup_bazel_config:
description: 'Setting up Bazel configuration for CI'
steps:
- run: echo "import %workspace%/.circleci/bazel.rc" >> ./.bazelrc
- run: echo "import %workspace%/.circleci/linux-bazel.rc" >> ./.bazelrc
- run: ./.circleci/setup-bazel.sh

prepare_and_store_test_results:
Expand Down Expand Up @@ -100,7 +117,10 @@ commands:
# https://circleci.com/docs/2.0/reusing-config/#authoring-parameterized-jobs
jobs:
test:
executor: default-executor
executor:
name: docker-linux-executor
resource_class: xlarge

steps:
- checkout_and_rebase
- *restore_cache
Expand All @@ -112,8 +132,36 @@ jobs:
- prepare_and_store_test_results
- *save_cache

test_macos_x64:
executor: macos-x64-executor
steps:
- checkout
- *restore_cache
- yarn_install
# Firefox tests will run in the Bazel sandbox, but Firefox currently requires, regardless
# of us specifying a custom profile directory, that the default profile directory exists.
# TODO: Remove this once https://bugzilla.mozilla.org/show_bug.cgi?id=1754821#c3 is resolved.
- run: mkdir "$HOME/Library/Application Support/Firefox"
- run: yarn bazel test --test_tag_filters=macos --build_tests_only -- //... -//bazel/remote-execution/...
- prepare_and_store_test_results
- *save_cache

test_windows_x64:
executor:
name: win/default
shell: bash.exe
steps:
- checkout
- *restore_cache
# Note: We cannot use the config-shared Yarn install command because the output timeout
# needs to be increased due to slower windows I/O (back to the 10min default for CircleCI).
- run: yarn install --immutable
- run: yarn bazel test --test_tag_filters=windows --build_tests_only -- ... -bazel/remote-execution/...
- prepare_and_store_test_results
- *save_cache

lint:
executor: default-executor
executor: docker-linux-executor
steps:
- checkout_and_rebase
- *restore_cache
Expand All @@ -127,7 +175,7 @@ jobs:
command: yarn ng-dev commit-message validate-range << pipeline.git.base_revision >> << pipeline.git.revision >>

publish_snapshot_build:
executor: default-executor
executor: docker-linux-executor
steps:
- checkout_and_rebase
- *restore_cache
Expand Down Expand Up @@ -163,11 +211,9 @@ workflows:
jobs:
- test
- lint
- test_macos_x64:
filters: *main_upstream_branches_filter
- test_windows_x64:
filters: *main_upstream_branches_filter
- publish_snapshot_build:
filters:
branches:
only:
- main
# Additional branch that can be used to test the snapshot build output.
# Developers can just push to that branch to test the built artifact.
- snapshot-test
filters: *main_upstream_branches_filter
File renamed without changes.
2 changes: 1 addition & 1 deletion bazel/browsers/firefox/firefox.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def define_firefox_repositories():
browser_archive(
name = "org_mozilla_geckodriver_macos_arm64",
licenses = ["reciprocal"], # MPL 2.0
sha256 = "6230b0abea0df843d3420f46871efd91e17a21602f4ffc84db57c7c3a42ec00d",
sha256 = "895bc2146edaea434d57a3b5d9a141be5cb3c5f8e8804916bd4869978ddfd4db",
# Geckodriver v0.30.0
urls = [
"https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-macos-aarch64.tar.gz",
Expand Down
32 changes: 32 additions & 0 deletions bazel/browsers/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("@npm//@bazel/concatjs:index.bzl", "karma_web_test_suite")
load("//bazel/spec-bundling:index.bzl", "spec_bundle")

karma_web_test_suite(
name = "test",
browsers = [
"//bazel/browsers/chromium:chromium",
"//bazel/browsers/firefox:firefox",
],
tags = [
"linux",
"macos",
"windows",
],
deps = [
":test_bundle",
],
)

js_library(
name = "test_lib",
testonly = True,
srcs = ["browser-test.spec.mjs"],
)

spec_bundle(
name = "test_bundle",
platform = "browser",
workspace_name = "dev-infra",
deps = [":test_lib"],
)
13 changes: 13 additions & 0 deletions bazel/browsers/test/browser-test.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

describe('browser test', () => {
it('should work', () => {
expect(true).toBe(true);
});
});
16 changes: 12 additions & 4 deletions bazel/browsers/update-script/browser-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ const KNOWN_EXTENSIONS = new Set(['zip', 'tar.gz', 'tar.bz2', 'dmg']);

/** Class describing an artifact for a browser. */
export class BrowserArtifact {
/** Extension of the artifact, derived from the download URL. */
extension = getArtifactExtension(this.downloadUrl);

constructor(
/** Instance of the browser this artifact exists for. */
public browser: Browser<unknown>,
/** Type of the artifact. */
public type: ArtifactType,
/** URL for downloading the artifact. */
public downloadUrl: string,
/** Extension of the artifact. If unspecified, derived from the download URL. */
public extension: string = detectArtifactExtension(downloadUrl),
) {}
}

Expand All @@ -37,14 +36,23 @@ export class BrowserArtifact {
* example with `.tar.gz`, we will need to keep track of known extensions
* and start looking with the first dot/period we discover.
*/
function getArtifactExtension(filePath: string) {
export function detectArtifactExtension(filePath: string) {
let tmpPath: string = filePath;
let extension: string = '';
let currentPart: string = '';

// Iterate from the end of the path, finding the largest possible
// extension substring, accounting for cases like `a/b.tmp/file.tar.gz`.
while ((currentPart = path.extname(tmpPath)) !== '') {
// An extension needs to be a continuous set of alphanumeric characters. This is a rather
// strict requirement as technically extensions could contain e.g. `dashes`. In our case
// this strictness is acceptable though as we don't expect such extensions and it makes
// this extension detection logic more correct. e.g. the logic would not incorrectly
// detect an extension for `firefox-97.0-linux.tar.gz` to `0-linux.tar.gz`.
if (!/^\.[a-zA-Z0-9]+$/.test(currentPart)) {
break;
}

extension = currentPart + extension;
tmpPath = path.basename(tmpPath, currentPart);
}
Expand Down
11 changes: 9 additions & 2 deletions bazel/browsers/update-script/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {ArtifactType, BrowserArtifact} from './browser-artifact';
import {Browser} from './browser';
import {Platform} from './platform';
import {detectArtifactExtension} from './browser-artifact';

const downloadLinuxUrls = {
'browser-bin':
Expand Down Expand Up @@ -48,9 +49,15 @@ export class Firefox implements Browser<string> {
getArtifact(platform: Platform, archiveType: ArtifactType): BrowserArtifact {
const urlSet = this._getUrlSetForPlatform(platform);
const baseUrl = urlSet[archiveType];
const downloadUrl = baseUrl.replace(/\{version}/g, this.revision);
const downloadUrl = baseUrl.replace(
/\{version}/g,
// Depending on browser, or driver being requested, substitute the associated version.
archiveType === 'browser-bin' ? this.revision : this.driverVersion,
);

return new BrowserArtifact(this, archiveType, downloadUrl);
// Note that for the artifact extension we will consult the non-substituted base URL
// as the substituted version like `97.0.tar.bz2` would throw off the detection.
return new BrowserArtifact(this, archiveType, downloadUrl, detectArtifactExtension(baseUrl));
}

private _getUrlSetForPlatform(platform: Platform): Record<ArtifactType, string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "bazel test ..."
"test": "bazelisk test ..."
},
"devDependencies": {
"@bazel/bazelisk": "^1.10.1"
"@bazel/bazelisk": "^1.11.0"
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# yarn lockfile v1


"@bazel/bazelisk@^1.10.1":
"@bazel/bazelisk@^1.11.0":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.11.0.tgz#f98d8438b4c14e3328126618b96775d271caa5f8"
integrity sha512-lxiQzVqSGDG0PIDQGJdVDjp7T+50p5NnM4EnRJa76mkZp6u5ul19GJNKhPKi81TZQALZEZDxAgxVqQKkWTUOxA==
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@
"@types/yarnpkg__lockfile": "^1.1.5",
"jsdoc": "^3.6.7",
"jsdom": "^19.0.0",
"karma": "^6.3.15",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^2.1.2",
"karma-jasmine": "^4.0.1",
"karma-requirejs": "^1.1.0",
"karma-sourcemap-loader": "^0.3.8",
"minimist": "^1.2.5",
"protobufjs": "^6.11.2",
"requirejs": "^2.3.6",
"rxjs": "^7.4.0",
"uglify-js": "^3.14.2",
"wait-on": "^6.0.0",
Expand Down
Loading