native build & test #1194
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: native build & test | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
schedule: | |
# Run daily at 00:00 (https://crontab.guru/#0_0_*_*_*). | |
- cron: "0 0 * * *" | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
env: | |
XDG_CACHE_HOME: ~/.cache/bazel-repo | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install p4c system dependencies (Flex, Bison, GMP) | |
run: sudo apt-get update && sudo apt-get install bison flex libfl-dev libgmp-dev | |
- name: Mount bazel caches | |
uses: actions/cache/restore@v3 | |
id: restore-cache | |
with: | |
path: "~/.cache/bazel" | |
key: bazel-${{ hashFiles('**/*_deps.bzl', '**/*.bazelrc') }}-${{ github.ref_name }} | |
restore-keys: | | |
bazel-${{ hashFiles('**/*_deps.bzl', '**/*.bazelrc') }} | |
bazel | |
- name: Save start time | |
uses: josStorer/get-current-time@v2 | |
id: start-time | |
with: | |
# Unix timestamp -- seconds since 1970. | |
format: X | |
- name: bazel build //... | |
run: | | |
bazel \ | |
--bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc \ | |
build //... | |
- name: bazel test //... | |
run: | | |
bazel \ | |
--bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc \ | |
test //... | |
- 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" | |
# Bazel's `--disk-cache` currently grows without bounds, so we remove files | |
# that haven't been accessed in 30+ days manually. | |
# github.com/bazelbuild/bazel/issues/5139 tracks fixing this in Bazel. | |
- name: Compress disk cache | |
run: find $HOME/.cache/bazel -type f -atime +30 -delete | |
- name: Save 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 == 'master' || env.duration > 300 | |
with: | |
key: ${{ steps.restore-cache.outputs.cache-primary-key }}-${{ github.run_id }} | |
path: "~/.cache/bazel" |