Skip to content

native build & test #1936

native build & test

native build & test #1936

Workflow file for this run

# SPDX-FileCopyrightText: 2020 The P4-Constraints Authors
#
# SPDX-License-Identifier: Apache-2.0
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 * * *" # 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:
jobs:
build:
strategy:
matrix:
# We only test on the oldest version we want to support and latest.
# We trust that things also work for versions in the middle.
os: [ubuntu-22.04, ubuntu-latest]
bazel_version: [7.x, latest]
# Don't abort other runs when one of them fails, to ease debugging.
fail-fast: false
runs-on: ${{ matrix.os }}
env:
# This tells Bazelisk (installed as `bazel`) to use specified version.
# https://github.com/bazelbuild/bazelisk?tab=readme-ov-file#how-does-bazelisk-know-which-bazel-version-to-run
USE_BAZEL_VERSION: ${{ matrix.bazel_version }}
CACHE_KEY: ${{ matrix.os }}_bazel-${{ matrix.bazel_version }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- 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 --test_output=errors //...
- name: Test
run: bazel test --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 }}