Skip to content

build

build #922

Workflow file for this run

name: build
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
# Run daily at midnight to ensure we catch regressions.
- cron: "0 0 * * *"
# Allow manual triggering of the workflow.
# https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow
workflow_dispatch:
# Cancel any preceding run on the pull request.
concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
build:
runs-on: ubuntu-latest
env:
CACHE_KEY: bazel
steps:
- uses: actions/checkout@v4
- name: Mount bazel cache
uses: actions/cache/restore@v4
with:
# See https://docs.bazel.build/versions/master/output_directories.html
path: "~/.cache/bazel"
# Create a new cache entry whenever Bazel files change.
# See https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/*.bazel*', '**/*.bzl') }}
restore-keys: |
${{ env.CACHE_KEY }}
- name: Save start time
run: echo "start_time=$(date +%s)" >> "$GITHUB_ENV"
- name: Build
run: bazel build --verbose_failures --test_output=errors //...
- name: Test
run: bazel test --verbose_failures --test_output=errors //...
- name: Calculate build duration
# Always calculate the build duration so we can update the cache if needed.
if: always()
run: |
end_time=$(date +%s)
echo "duration=$(( end_time - start_time ))" >> "$GITHUB_ENV"
- name: Compress cache
# Always compress the cache so we can update the cache if needed.
if: always()
run: rm -rf $(bazel info repository_cache)
- name: Save bazel cache
uses: actions/cache/save@v4
# Only create a new cache entry if we're on the main branch or the build takes >3mins.
#
# NOTE: Even though `always()` evaluates to true, and `true && x == x`,
# the `always() &&` prefix is not redundant! The call to `always()` has a
# side effect, which is to override the default behavior of automagically
# canceling this step if a previous step failed.
# (Don't blame me, blame GitHub Actions!)
if: always() && (github.ref_name == 'main' || env.duration > 180)
with:
path: "~/.cache/bazel"
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/*.bazel*', '**/*.bzl') }}-${{ github.run_id }}