|
| 1 | +name: Build and test |
| 2 | + |
| 3 | +on: |
| 4 | + # Only run workflow on pushes to main (includes PR merge), and on |
| 5 | + # opened pull-requests. |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + pull_request: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build_and_test: |
| 13 | + runs-on: ubuntu-24.04 |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + python-version: ["3.10"] |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python ${{ matrix.python-version }} |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: ${{ matrix.python-version }} |
| 25 | + cache: 'pip' |
| 26 | + |
| 27 | + - name: Display Python version |
| 28 | + run: python -c "import sys; print(sys.version)" |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: | |
| 32 | + python -m pip install --upgrade pip setuptools wheel |
| 33 | + . build/install_bazelisk.sh |
| 34 | +
|
| 35 | + # Load different caches depending on if this is a pull-request or merge. |
| 36 | + # If merge (or push commit), use a read-write cache based on the python |
| 37 | + # version, branch, and commit-sha. |
| 38 | + # If pull-request, use a read-only cache based on the target python |
| 39 | + # version, branch, and PR base sha. |
| 40 | + - if: github.event_name != 'pull_request' |
| 41 | + name: Mount bazel cache (main) |
| 42 | + uses: actions/cache@v4 |
| 43 | + with: |
| 44 | + path: "/home/runner/.cache/bazel" |
| 45 | + key: bazel-${{ matrix.python-version }}-${{ github.ref_name }}-${{ github.sha }} |
| 46 | + restore-keys: | |
| 47 | + bazel-${{ matrix.python-version }}-${{ github.ref_name }} |
| 48 | + bazel-${{ matrix.python-version }}- |
| 49 | + bazel- |
| 50 | +
|
| 51 | + - if: github.event_name == 'pull_request' |
| 52 | + name: Mount bazel cache (pull-request) |
| 53 | + uses: actions/cache/restore@v4 |
| 54 | + with: |
| 55 | + path: "/home/runner/.cache/bazel" |
| 56 | + key: bazel-${{ matrix.python-version }}-${{ github.base_ref }}-${{ github.event.pull_request.base.sha }} |
| 57 | + restore-keys: | |
| 58 | + bazel-${{ matrix.python-version }}-${{ github.base_ref }} |
| 59 | + bazel-${{ matrix.python-version }}- |
| 60 | + bazel- |
| 61 | +
|
| 62 | + - name: Build all targets |
| 63 | + run: | |
| 64 | + export HERMETIC_PYTHON_VERSION=${{ matrix.python-version }} |
| 65 | + bazel build //... |
| 66 | +
|
| 67 | + - name: Build pip wheel |
| 68 | + run: | |
| 69 | + bazel run //build:build_pip_package -- $PWD |
| 70 | +
|
| 71 | + - name: Run CPU tests |
| 72 | + run: | |
| 73 | + bazel test --config=cpu --test_output=errors --keep_going //... |
0 commit comments