Skip to content

Commit

Permalink
build: Add lint and Bazel jobs to CircleCI (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored and MikeRyanDev committed Feb 16, 2018
1 parent 72bfff2 commit 9fd6b3d
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .circleci/bazel.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# These options are enabled when running on CI
# We do this by copying this file to /etc/bazel.bazelrc at the start of the build.

# Don't be spammy in the logs
build --noshow_progress

# Don't run manual tests
test --test_tag_filters=-manual

# Prevent unstable environment variables from tainting cache keys
build --experimental_strict_action_env

# Workaround https://github.com/bazelbuild/bazel/issues/3645
# Bazel doesn't calculate the memory ceiling correctly when running under Docker.
# Limit Bazel to consuming resources that fit in CircleCI "medium" class which is the default:
# https://circleci.com/docs/2.0/configuration-reference/#resource_class
build --local_resources=3072,2.0,1.0

# Retry in the event of flakes, eg. https://circleci.com/gh/angular/angular/31309
test --flaky_test_attempts=2
69 changes: 66 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,78 @@
# This file configures the build at https://circleci.com/gh/ngrx/platform

# Opt-in to newer CircleCI system
# Complete documentation is at https://circleci.com/docs/2.0/
version: 2

# Note: YAML anchors allow an object to be re-used, reducing duplication.
# The ampersand declares an alias for an object, then later the `<<: *name`
# syntax dereferences it.
# See http://blog.daemonl.com/2016/02/yaml.html
# To validate changes, use an online parser, eg.
# http://yaml-online-parser.appspot.com/
var_1: &cache_key yarn-cache-{{ checksum "yarn.lock" }}
var_2: &run_in_ngcontainer
docker:
- image: angular/ngcontainer:0.1.0
var_3: &set_bazel_options
run:
command: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc

jobs:

# Enforce some static analysis invariants.
# Note that generally, these should be checked only on the delta in each change,
# otherwise any change to the static analysis config requires updating all the
# code in the repo.
# Also analyzing everything makes the lint job slow.
lint:
<<: *run_in_ngcontainer
steps:
- checkout
- *set_bazel_options

# Enforce that BUILD files are formatted.
# Note that this uses the version of buildifier from the docker image -
# 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 \)) ||
(echo "BUILD files not formatted. Please run ''yarn buildifier''" ; exit 1)'

bazel:
<<: *run_in_ngcontainer
steps:
- checkout
- *set_bazel_options

- restore_cache:
key: *cache_key

# 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 the dependencies from NPM, using the node and yarn binaries managed by Bazel
- run: bazel run @yarn//:yarn

# Build and Test
# Use bazel query so that we explicitly ask for all buildable targets to
# be built even though we run `bazel test`
# See https://github.com/bazelbuild/bazel/issues/4257
- run: bazel query --output=label //... | xargs bazel test

test:
docker:
- image: circleci/node:latest-browsers
steps:
- checkout
- restore_cache:
key: yarn-cache
key: *cache_key
- run: yarn
- run: yarn run ci
- run: yarn run example:build:prod
- run: yarn run example:test --watch=false
- save_cache:
key: yarn-cache
key: *cache_key
paths:
- ~/.cache/yarn
- node_modules
Expand All @@ -22,14 +82,17 @@ jobs:
steps:
- checkout
- restore_cache:
key: yarn-cache
key: *cache_key
- run: yarn
- run: yarn run build
- run: yarn run deploy:builds

workflows:
version: 2
build-test-deploy:
jobs:
- lint
- bazel
- test
- deploy:
requires:
Expand Down
13 changes: 13 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@
# Needed so that tsconfig.json can be referenced from BUILD rules.

exports_files(["tsconfig.json"])

# Temporary target to allow `bazel test ...`
# TODO(alexeagle): remove as soon as there is any other test in the repo
genrule(
name = "true",
outs = ["true.sh"],
cmd = "echo true > $@",
)

sh_test(
name = "tautology_test",
srcs = [":true.sh"],
)

0 comments on commit 9fd6b3d

Please sign in to comment.