-
Notifications
You must be signed in to change notification settings - Fork 26
92 lines (80 loc) · 3.01 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: "build"
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
# Run daily at midnight to ensure we catch regressions.
# https://crontab.guru/#0_0_*_*_*
- cron: "0 0 * * *"
jobs:
build:
runs-on: ubuntu-22.04
env:
BAZEL_CACHE_USER: github
BAZEL_CACHE_PWD: ${{ secrets.BAZEL_CACHE_PWD }}
BAZEL_CACHE_URL: pins-bazel-cache.onf.dev:9090
steps:
- uses: actions/checkout@v3
- name: Install system dependencies
run: ./install_dependencies.sh
- name: Install bazelisk
run: |
ARCH=$(dpkg --print-architecture)
sudo curl -fsSL -o /usr/local/bin/bazel \
https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-${ARCH}
sudo chmod +x /usr/local/bin/bazel
- name: Mount bazel cache
uses: actions/cache/restore@v3
with:
path: "~/.cache/bazel"
key: ci-${{ hashFiles('**/*_deps.bzl', '.bazelrc') }}-${{ github.ref_name }}
# The last key, `test-Linux`, is there just for boostrapping-purposes -- it matches the
# cache key schema prior to 2023-06-29. It can be revoved in a subsequent PR.
restore-keys: |
ci-${{ hashFiles('**/*_deps.bzl', '.bazelrc') }}
ci
test-Linux
- name: Save start time
uses: josStorer/get-current-time@v2
id: start-time
with:
# Unix timestamp -- seconds since 1970.
format: X
# Authentication is enabled for R/W access for builds on main and branch PRs
# Unauthenticated reads are allowed for PRs from forks
- name: Build and Test
run: |
mkdir -p /tmp/repo-cache
BAZEL_OPTS="--repository_cache=/tmp/repo-cache"
[ ! -z "$BAZEL_CACHE_USER" ] && [ ! -z "$BAZEL_CACHE_PWD" ] && \
AUTH="${BAZEL_CACHE_USER}:${BAZEL_CACHE_PWD}@"
BAZEL_OPTS+=" --remote_cache=https://${AUTH}${BAZEL_CACHE_URL}"
BAZEL_OPTS+=" --remote_download_minimal"
bazel build ${BAZEL_OPTS} //...
bazel test ${BAZEL_OPTS} //...
- name: Save end time
uses: josStorer/get-current-time@v2
id: end-time
with:
# Unix timestamp -- seconds since 1970.
format: X
- name: Calculate build duration
run: |
START=${{ steps.start-time.outputs.formattedTime }}
END=${{ steps.end-time.outputs.formattedTime }}
DURATION=$(( $END - $START ))
echo "duration=$DURATION" | tee "$GITHUB_ENV"
- name: Compress cache
# This deletes cached archives while keeping the build cache.
run: rm -rf $(./$BAZEL info repository_cache)
- name: Save bazel cache
uses: actions/cache/save@v3
# We create a new cache entry if either of the following is true:
# - We are on the master branch.
# - It took more than 5 minutes to build and test.
if: github.ref_name == 'main' || env.duration > 300
with:
path: "~/.cache/bazel"
key: ci-${{ hashFiles('**/*_deps.bzl', '.bazelrc') }}-${{ github.ref_name }}-${{ github.run_id }}