Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.
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
45 changes: 25 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
# This file configures the build at https://circleci.com/gh/alexeagle/angular-bazel-example
# Complete documentation is at https://circleci.com/docs/2.0/

# We use a docker image as the basis for our build, so that all the toolchains we use
# are already installed and the build can start running right away. It also guarantees
# the environment is portable and reproducible on your local machine.
var_1: &docker_image angular/ngcontainer:0.8.0

# CircleCI lets us pick the key for storing one or more caches, to speed up subsequent builds.
# We can use this to avoid re-fetching our dependencies from npm on every build.
# To ensure we don't load a stale cache, we invalidate it based on the entries in the key:
# - the checksum of Yarn's lock file
# - the branch we are on, which really shouldn't be needed since the yarn lock file should be hermetic
# - the docker image tag, working around an issue we saw where changing docker images causes permission
# errors when restoring the cache, like when the user we run as changes
var_2: &cache_key angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-0.8.0
var_1: &cache_key angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-0.8.0

# Each job will inherit these defaults
anchor_1: &job_defaults
var_2: &job_defaults
working_directory: ~/ng
docker:
- image: *docker_image
# Use the -browsers version just to get the right .so files on the disk
# We'll actually download a chromium version under the rules_webtesting
- image: circleci/node:10.12-browsers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comment on why -browers image is needed?


# After checkout, rebase on top of master, because we want to test the proposed merge of a
# onto the target branch, not just test what's on the user's fork.
# Similar to travis behavior, but not quite the same.
# See https://discuss.circleci.com/t/1662
anchor_2: &post_checkout
var_3: &post_checkout
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"

# Opt-in to the new goodness
Expand All @@ -34,15 +31,19 @@ version: 2
# These jobs will run in parallel, and report separate statuses to GitHub PRs
jobs:
lint:
<<: *job_defaults
docker:
- image: circleci/node:10.12
steps:
- checkout:
<<: *post_checkout

# Enforce that BUILD files are formatted. Note that this uses the version of buildifier
# from the docker image above - take care that you use the same version when you run
# buildifier locally on your change.
- run: 'buildifier -mode=check $(find . -type f \( -name BUILD.bazel -or -name BUILD \)) ||
- restore_cache:
key: *cache_key

# Install Bazel
- run: yarn
# Enforce that BUILD files are formatted.
- run: 'yarn buildifier -mode=check ||
(echo "BUILD files not formatted. Please run ''yarn buildifier''" ; exit 1)'

build:
Expand All @@ -52,14 +53,17 @@ jobs:
- checkout:
<<: *post_checkout

- restore_cache:
key: *cache_key

- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc

# Helpful for debugging, so you can check you have the same bazel version when you need
# to reproduce a failure.
- run: bazel info release
# Install Bazel from NPM
- run: yarn

# Build and Test
- run: bazel test //...
- run: yarn test
- run: yarn e2e

- store_artifacts:
path: dist/bin/src/bundle.min.js
Expand All @@ -78,9 +82,10 @@ jobs:
- restore_cache:
key: *cache_key

# Run the benchmark
# Install Bazel/ibazel from NPM
- run: yarn
- run: node_modules/.bin/ibazel-benchmark-runner //src:devserver src/hello-world/hello-world.component.ts --url=http://localhost:5432
# Run the benchmark
- run: yarn benchmark

# If we get this far, save the node_modules directory for use next time.
- save_cache:
Expand Down
51 changes: 21 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,55 @@ Follow https://github.com/angular/angular/issues/19058 for updates.

## Installation

Install Bazel from the distribution, see [install] instructions.
On Mac, if you have Homebrew installed you can
You only need to install one build tool, and which one you choose typically depends on what kind of development you do most often.

```bash
brew tap bazelbuild/tap
brew tap-pin bazelbuild/tap
brew install bazel
```

Bazel will install a hermetic version of Node, npm, and Yarn when
you run the first build.
If you're a frontend developer, you should install NodeJS and yarn.
The `package.json` file has an `engines` section which indicates the range of NodeJS and yarn versions that you could use.
You simply run `yarn` commands shown below, and don't need to install Bazel or any other dependencies.

[install]: https://bazel.build/versions/master/docs/install.html

Also add `ibazel` to your `$PATH`:

```
yarn global add @bazel/ibazel
```

or

```
npm install -g @bazel/ibazel
```
If you're a full-stack developer, you might be using Bazel for your backend already.
In this case, you should install Bazel following instructions at http://bazel.build.
Also install `ibazel`, which is a watch mode for Bazel not included in the standard distribution. See https://github.com/bazelbuild/bazel-watcher#installation.
The `WORKSPACE` file has a `check_bazel_version` call which will print an error if your Bazel version is not in the supported range.
You simply run `bazel` commands shown below, and don't need to install NodeJS, yarn, or any other dependencies.

## Development

Next we'll run the development server:
First we'll run the development server:

```bash
$ yarn serve
# or
$ ibazel run //src:devserver
```

> This script runs `ibazel`, which is a "watch mode"
> for Bazel. That means it will watch any files that are inputs to the devserver,
> and when they change it will ask Bazel to re-build them. The server stays
> running, and when the re-build is finished, it will trigger the LiveReload in
> the browser.
This runs in "watch mode", which means it will watch any files that are inputs to the devserver, and when they change it will ask Bazel to re-build them.
When the re-build is finished, it will trigger a LiveReload in the browser.

This command prints a URL on the terminal. Open that page to see the demo app
running. Now you can edit one of the source files (`src/lib/file.ts` is an easy
one to understand and see the effect). As soon as you save a change, the app
should refresh in the browser with the new content. Our intent is that this time
is less than two seconds, even for a large application.

Control-C twice to kill the devserver and also stop `ibazel`.
Control-C twice to kill the devserver.

## Testing

We can also run all the unit tests:

```bash
$ yarn test
# or
$ bazel test //src/...
```

Or run the end-to-end tests:

```bash
$ yarn e2e
# or
$ bazel test //e2e/...
```

In this example, there is a unit test for the `hello-world` component which uses
Expand All @@ -92,6 +81,8 @@ bundlers can be integrated with Bazel.

```bash
$ yarn serve-prod
# or
$ bazel run //src:prodserver
```

### Code splitting
Expand Down
3 changes: 0 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
workspace(name = "angular_bazel_example")

# The Bazel buildtools repo contains tools like the BUILD file formatter, buildifier
# This commit matches the version of buildifier in angular/ngcontainer
# If you change this, also check if it matches the version in the angular/ngcontainer
# version in /.circleci/config.yml
BAZEL_BUILDTOOLS_VERSION = "49a6c199e3fbf5d94534b2771868677d3f9c6de9"

http_archive(
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "0.0.1",
"description": "Demo of bazel rules for angular",
"license": "Apache 2.0",
"engines": {
"node": ">=10.9.0 <11.0.0",
"yarn": ">=1.9.2 <2.0.0"
},
"dependencies": {
"@ngrx/store": "6.1.0",
"rxjs": "6.3.3",
Expand All @@ -19,6 +23,7 @@
"@angular/common": "7.0.4",
"@angular/core": "7.0.4",
"@angular/material": "7.0.4",
"@bazel/bazel": "^0.19.1",
"@bazel/benchmark-runner": "0.1.0",
"@bazel/ibazel": "0.5.0",
"@bazel/karma": "0.20.3",
Expand All @@ -36,6 +41,7 @@
"serve-prod": "bazel run //src:prodserver",
"e2e": "bazel test //e2e:all",
"test": "bazel test //src/...",
"benchmark": "ibazel-benchmark-runner //src:devserver src/hello-world/hello-world.component.ts --url=http://localhost:5432",
"postinstall": "ngc -p postinstall.tsconfig.json",
"prebuildifier": "bazel build @com_github_bazelbuild_buildtools//buildifier",
"//": "note: working around https://github.com/alexeagle/angular-bazel-example/issues/60",
Expand Down
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@
dependencies:
tslib "^1.7.1"

"@bazel/bazel-darwin_x64@0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-0.19.1.tgz#58d779c8938bd1c136cab55e2f6473121f83741b"
integrity sha512-Rnk8zw5S9SZfuMQsGRodm7ZXme1FS2rpmYbIJVF0M+k7jaWLZJwV2w5T2vMyuluEjOxTbptXenbigTF80jETIA==

"@bazel/bazel-linux_x64@0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-0.19.1.tgz#aef363e0932d29d1bb48980da139d74bfb4b1ffb"
integrity sha512-dWKKYa0cwDEjVRRwUMVSy1WvQjTHQPiwrA6mDzNzoRX0D0KBX25QqdkQW6HS6fzyEOsFjT+yVtfqtxL0qO+FCA==

"@bazel/bazel-win32_x64@0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-0.19.1.tgz#273c43b0febc11675614c402ec82ae44b519f9ee"
integrity sha512-t6vOh2IOzUAk19ccS0q3Kho364Yxjtjv1v4utAjOSNw8GVwutfekdiojGBrR8ihvJi1Xp885mOkQnZA38B9tvQ==

"@bazel/bazel@^0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-0.19.1.tgz#22ce225b5172a4ad2a94496be66b14b7c7facca2"
integrity sha512-RGxp/Ny36ESzBG7l3yYG24yWfvjFyGE2VqNtXZdJfCfO5312zTNz0qRmZS8pNrCEN+F89jQDRvPhpdAyXKKwOg==
optionalDependencies:
"@bazel/bazel-darwin_x64" "0.19.1"
"@bazel/bazel-linux_x64" "0.19.1"
"@bazel/bazel-win32_x64" "0.19.1"

"@bazel/benchmark-runner@0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@bazel/benchmark-runner/-/benchmark-runner-0.1.0.tgz#a586394fcf7f2402b381319fbc2750627b5a06f1"
Expand Down