Skip to content

Commit

Permalink
Restructure CI config (#163)
Browse files Browse the repository at this point in the history
- Upgrade `bazel` to `0.24.0`
- Restructure `.circleci/config.yml` to use `machine` executor. This removes memory limitations (see bazelbuild/bazel#3645) and removes the need to upgrade `libstdc++` (Ubuntu's bundled on is up-to-date enough)
- Disable building code multiple times on CircleCI
  • Loading branch information
vmax authored Apr 9, 2019
1 parent 1744309 commit ba0ca7d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 118 deletions.
31 changes: 0 additions & 31 deletions .circleci/bazel.rc

This file was deleted.

125 changes: 55 additions & 70 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,92 +1,77 @@
# Based on config from github.com/alexeagle/angular-bazel-example
version: 2

# 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.10.0

# Each job will inherit these defaults
anchor_1: &job_defaults
working_directory: ~/ng
docker:
- image: *docker_image

# 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
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"

version: 2.1
commands:
install-bazel:
steps:
- run:
name: Install bazel
command: |
curl -OL https://github.com/bazelbuild/bazel/releases/download/0.24.0/bazel-0.24.0-installer-linux-x86_64.sh
chmod +x bazel-0.24.0-installer-linux-x86_64.sh
sudo ./bazel-0.24.0-installer-linux-x86_64.sh
rm ./bazel-0.24.0-installer-linux-x86_64.sh
bazel info release
install-deps:
steps:
- run:
name: Install extra dependencies (yapf3)
command: |
pip install yapf
restore-caches:
steps:
- restore_cache:
keys:
- "android_sdk"
- restore_cache:
keys:
- "v4-bazel_cache"
save-caches:
steps:
- save_cache:
key: "android_sdk"
paths:
- "/home/circleci/android_sdk"

# These jobs will run in parallel, and report separate statuses to GitHub PRs
- save_cache:
key: "v4-bazel_cache"
paths:
- "/home/circleci/.cache/bazel/"
jobs:
lint:
<<: *job_defaults
working_directory: ~/code/
machine:
enabled: true
image: ubuntu-1604:201903-01
steps:
- checkout:
<<: *post_checkout
- restore_cache:
key: "v3-bazel_cache"
# Fixes Debian upstream repos: https://discuss.circleci.com/t/failed-to-fetch-jessie-updates/29246
- run: |
sudo rm /etc/apt/sources.list
echo "deb http://archive.debian.org/debian/ jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://archive.debian.org/debian/ jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "Acquire::Check-Valid-Until false;" | sudo tee -a /etc/apt/apt.conf.d/10-nocheckvalid
echo 'Package: *\nPin: origin "archive.debian.org"\nPin-Priority: 500' | sudo tee -a /etc/apt/preferences.d/10-archive-pin
sudo apt-get update
- run: sudo apt -y install yapf3 clang-format python3-pkg-resources libstdc++6
- run: sudo ln -s /usr/bin/yapf3 /usr/bin/yapf
- checkout
- install-bazel
- install-deps
- run: './tools/checkstyle/check-for-missing-targets.sh'
- run: './fix-formatting.sh'

build:
<<: *job_defaults
working_directory: ~/code/
machine:
enabled: true
image: ubuntu-1604:201903-01
steps:
- checkout:
<<: *post_checkout

- restore_cache:
key: "android_sdk"

- restore_cache:
key: "v3-bazel_cache"

# Fixes Debian upstream repos: https://discuss.circleci.com/t/failed-to-fetch-jessie-updates/29246
- run: |
sudo rm /etc/apt/sources.list
echo "deb http://archive.debian.org/debian/ jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://archive.debian.org/debian/ jessie-backports main" | sudo tee -a /etc/apt/sources.list
echo "Acquire::Check-Valid-Until false;" | sudo tee -a /etc/apt/apt.conf.d/10-nocheckvalid
echo 'Package: *\nPin: origin "archive.debian.org"\nPin-Priority: 500' | sudo tee -a /etc/apt/preferences.d/10-archive-pin
sudo apt-get update
- run: sudo apt -y install libstdc++6
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
- run: bazel info release
- run: npm install
- run: bash tools/get_android_sdk.sh
- checkout
- install-bazel
- install-deps
- restore-caches
- run: './tools/get_android_sdk.sh'
- run:
name: "Hasadna: building"
command: ./compile.sh build
environment:
ANDROID_HOME: /home/circleci/android_sdk/
- run:
name: "Hasadna: testing"
command: ./compile.sh test
environment:
ANDROID_HOME: /home/circleci/android_sdk/

- save_cache:
key: "android_sdk"
paths:
- "/home/circleci/android_sdk"
key: "v3-bazel_cache"
paths:
- "/home/circleci/.cache/bazel/"

- save-caches

workflows:
version: 2
default_workflow:
jobs:
- lint
Expand Down
17 changes: 0 additions & 17 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
RED=$(tput setaf 1)
RESET=$(tput sgr0)

CIRCLECI_MAX_ATTEMPTS=10

function bazel_build() {
if [[ -z "$ANDROID_HOME" ]]; then
# Ignore third_party and android targets
Expand All @@ -23,20 +21,5 @@ if [[ $1 != "build" && $1 != "test" ]]; then
exit 1
fi

if [[ ! -z "$CIRCLECI" ]]; then
echo "$RED""Due to flakiness in bazel execution on CircleCI, trying to build several times"
for i in $(seq 1 ${CIRCLECI_MAX_ATTEMPTS}); do
echo "$RED""[Attempt $i/${CIRCLECI_MAX_ATTEMPTS}]: building$RESET"
bazel $1 //...
if [[ $? -eq 0 ]]; then
echo "$GREEN""[Attempt $i/${CIRCLECI_MAX_ATTEMPTS}]: successful$RESET"
exit 0
fi
done

echo "$RED""[Attempts exhausted]: Seems it's a problem with your code and not a CircleCI flake.$RESET"
exit 1
fi

bazel_build $1
exit $?

0 comments on commit ba0ca7d

Please sign in to comment.