Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 9b1a41f

Browse files
jbedarddevversion
authored andcommitted
build: add bazel build
1 parent fadbba1 commit 9b1a41f

21 files changed

+774
-25
lines changed

Diff for: .bazelignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist/
2+
node_modules/
3+
.angular/
4+
.circleci/
5+
.github/

Diff for: .bazelrc

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
###############################
2+
# Filesystem interactions #
3+
###############################
4+
5+
# Disable watchfs as it causes tests to be flaky on Windows
6+
# https://github.com/angular/angular/issues/29541
7+
build --nowatchfs
8+
9+
# Turn off legacy external runfiles
10+
build --nolegacy_external_runfiles
11+
12+
# Turn on --incompatible_strict_action_env which was on by default
13+
# in Bazel 0.21.0 but turned off again in 0.22.0. Follow
14+
# https://github.com/bazelbuild/bazel/issues/7026 for more details.
15+
# This flag is needed to so that the bazel cache is not invalidated
16+
# when running bazel via `yarn bazel`.
17+
# See https://github.com/angular/angular/issues/27514.
18+
build --incompatible_strict_action_env
19+
20+
# Enable remote caching of build/action tree
21+
build --experimental_remote_merkle_tree_cache
22+
23+
# Ensure that tags applied in BUILDs propagate to actions
24+
build --experimental_allow_tags_propagation
25+
26+
# Don't check if output files have been modified
27+
build --noexperimental_check_output_files
28+
29+
# Ensure sandboxing is enabled even for exclusive tests
30+
test --incompatible_exclusive_test_sandboxed
31+
32+
# Fixes use of npm paths with spaces such as some within the puppeteer module
33+
build --experimental_inprocess_symlink_creation
34+
35+
####################################################
36+
# User bazel configuration
37+
# NOTE: This needs to be the *last* entry in the config.
38+
####################################################
39+
40+
# Load any settings which are specific to the current user. Needs to be *last* statement
41+
# in this config, as the user configuration should be able to overwrite flags from this file.
42+
try-import .bazelrc.user
43+
44+
# Enable runfiles even on Windows.
45+
# Architect resolves output files from data files, and this isn't possible without runfile support.
46+
build --enable_runfiles

Diff for: .bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.3.1

Diff for: .circleci/config.yml

+63-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ version: 2.1
1212

1313
orbs:
1414
browser-tools: circleci/[email protected]
15+
devinfra: angular/[email protected]
1516

1617
# Cache key for CircleCI. We want to invalidate the cache whenever the Yarn lock file changes.
1718
var_1: &cache_key material-angular-io-{{ .Branch }}-{{ checksum "yarn.lock" }}
18-
var_2: &default_docker_image cimg/node:16.14.0-browsers
19+
var_2: &default_docker_image cimg/node:16.17.1-browsers
1920

2021
# Settings common to each job
2122
var_3: &job_defaults
@@ -83,6 +84,7 @@ jobs:
8384
<<: *job_defaults
8485
steps:
8586
- checkout
87+
- browser-tools/install-chrome
8688
- restore_cache:
8789
key: *cache_key
8890
- *yarn_install
@@ -100,6 +102,62 @@ jobs:
100102
- *yarn_install
101103
- run: yarn test:audit:ci
102104

105+
bazel-build:
106+
<<: *job_defaults
107+
resource_class: large
108+
steps:
109+
- checkout
110+
- restore_cache:
111+
key: *cache_key
112+
- *yarn_install
113+
- run: yarn bazel build //...
114+
- *save_cache
115+
116+
bazel-test:
117+
<<: *job_defaults
118+
resource_class: large
119+
steps:
120+
- checkout
121+
- restore_cache:
122+
key: *cache_key
123+
- *yarn_install
124+
- run: yarn bazel test --test_tag_filters=-lint,-e2e,-audit //...
125+
- *save_cache
126+
- store_artifacts:
127+
path: bazel-testlogs/
128+
- store_artifacts:
129+
path: bazel-testlogs/scenes/
130+
131+
bazel-lint:
132+
<<: *job_defaults
133+
resource_class: large
134+
steps:
135+
- checkout
136+
- restore_cache:
137+
key: *cache_key
138+
- *yarn_install
139+
- run: yarn bazel test --test_tag_filters=+lint //...
140+
- *save_cache
141+
- store_artifacts:
142+
path: bazel-testlogs/
143+
- store_artifacts:
144+
path: bazel-testlogs/scenes/
145+
146+
bazel-lighthouse_audits:
147+
<<: *job_defaults
148+
resource_class: xlarge
149+
steps:
150+
- checkout
151+
- restore_cache:
152+
key: *cache_key
153+
- *yarn_install
154+
- run: yarn bazel test --test_tag_filters=+audit //...
155+
- *save_cache
156+
- store_artifacts:
157+
path: bazel-testlogs/
158+
- store_artifacts:
159+
path: bazel-testlogs/scenes/
160+
103161
workflows:
104162
version: 2
105163
default_workflow:
@@ -110,3 +168,7 @@ workflows:
110168
- lighthouse_audits:
111169
requires:
112170
- build
171+
- bazel-build
172+
- bazel-test
173+
- bazel-lighthouse_audits
174+
- bazel-lint

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/out-tsc
77
/src/assets/*.css
88
# Only exists if Bazel was run
9-
/bazel-out
9+
/bazel-*
1010

1111
.angular/
1212

Diff for: .npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
strict-peer-dependencies=false

Diff for: .nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.14.0
1+
16.17.1

Diff for: BUILD.bazel

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
2+
load("@aspect_rules_js//js:defs.bzl", "js_test")
3+
load("@npm//:defs.bzl", "npm_link_all_packages")
4+
load("//:defs.bzl", "ng_app")
5+
6+
package(default_visibility = ["//visibility:public"])
7+
8+
# Link npm packages
9+
npm_link_all_packages(name = "node_modules")
10+
11+
# Root config files used throughout build/test/lint etc
12+
copy_to_bin(
13+
name = "ng-base-config",
14+
srcs = [
15+
"angular.json",
16+
"tsconfig.json",
17+
"package.json",
18+
],
19+
)
20+
21+
# Test config files
22+
copy_to_bin(
23+
name = "ng-base-test-config",
24+
srcs = [
25+
"karma-custom-launchers.js",
26+
],
27+
)
28+
29+
# Lint config files
30+
copy_to_bin(
31+
name = "ng-base-lint-config",
32+
srcs = [
33+
".eslintrc.json",
34+
],
35+
)
36+
37+
38+
# The main application
39+
ng_app(
40+
name = "app",
41+
project_name = "material-angular-io",
42+
deps = [
43+
"//:node_modules/@angular/components-examples",
44+
"//:node_modules/@stackblitz/sdk",
45+
"//:node_modules/moment",
46+
],
47+
)
48+
49+
50+
js_test(
51+
name = "audit",
52+
entry_point = "tools/audit-docs.js",
53+
args = [
54+
"$(location //:build.production)",
55+
],
56+
data = [
57+
"tools/lighthouse-audit.js",
58+
"//:build.production",
59+
"//:node_modules/lighthouse",
60+
"//:node_modules/lighthouse-logger",
61+
"//:node_modules/puppeteer",
62+
"//:node_modules/shelljs",
63+
"//:node_modules/light-server",
64+
],
65+
tags = ["audit"],
66+
)

Diff for: WORKSPACE.bazel

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
3+
http_archive(
4+
name = "aspect_bazel_lib",
5+
sha256 = "3534a27621725fbbf1d3e53daa0c1dda055a2732d9031b8c579f917d7347b6c4",
6+
strip_prefix = "bazel-lib-1.16.1",
7+
url = "https://github.com/aspect-build/bazel-lib/archive/refs/tags/v1.16.1.tar.gz",
8+
)
9+
10+
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
11+
12+
aspect_bazel_lib_dependencies()
13+
14+
http_archive(
15+
name = "aspect_rules_js",
16+
sha256 = "dda5fee3926e62c483660b35b25d1577d23f88f11a2775e3555b57289f4edb12",
17+
strip_prefix = "rules_js-1.6.9",
18+
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.6.9.tar.gz",
19+
)
20+
21+
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
22+
23+
rules_js_dependencies()
24+
25+
load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
26+
27+
nodejs_register_toolchains(
28+
name = "nodejs",
29+
node_version = "16.17.1",
30+
)
31+
32+
# Add a patch fix for rules_webtesting v0.3.5 required for enabling runfiles on Windows.
33+
# TODO: Remove the http_archive for this transitive dependency when a release is cut
34+
# for https://github.com/bazelbuild/rules_webtesting/commit/581b1557e382f93419da6a03b91a45c2ac9a9ec8
35+
# and the version is updated in rules_nodejs.
36+
http_archive(
37+
name = "io_bazel_rules_webtesting",
38+
patch_args = ["-p1"],
39+
patches = [
40+
"//:tools/patches/rules_webtesting__windows_runfiles_fix.patch",
41+
],
42+
sha256 = "e9abb7658b6a129740c0b3ef6f5a2370864e102a5ba5ffca2cea565829ed825a",
43+
urls = ["https://github.com/bazelbuild/rules_webtesting/releases/download/0.3.5/rules_webtesting.tar.gz"],
44+
)
45+
46+
http_archive(
47+
name = "dev-infra",
48+
strip_prefix = "dev-infra-9bc16c6fd4297c5220eb7627e42f8117ca6d1967",
49+
sha256 = "3208595ba1b237d71a1b1542a6241210a5a543074d42adb0f0378b7408b5369d",
50+
url = "https://github.com/angular/dev-infra/archive/9bc16c6fd4297c5220eb7627e42f8117ca6d1967/9bc16c6fd4297c5220eb7627e42f8117ca6d1967.tar.gz",
51+
)
52+
53+
load("@dev-infra//bazel/browsers:browser_repositories.bzl", "browser_repositories")
54+
55+
browser_repositories()
56+
57+
load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")
58+
59+
web_test_repositories()
60+
61+
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
62+
63+
npm_translate_lock(
64+
name = "npm",
65+
package_json = "//:package.json",
66+
yarn_lock = "//:yarn.lock",
67+
npmrc = "//:.npmrc",
68+
verify_node_modules_ignored = "//:.bazelignore",
69+
patches = {
70+
"@angular-devkit/architect-cli": ["//:tools/patches/bazel-architect-cli.patch"],
71+
},
72+
)
73+
74+
load("@npm//:repositories.bzl", "npm_repositories")
75+
76+
npm_repositories()

0 commit comments

Comments
 (0)