|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | + |
| 17 | +name: Bazel Build and Test |
| 18 | + |
| 19 | +on: |
| 20 | + push: |
| 21 | + branches: [ main ] |
| 22 | + pull_request: |
| 23 | + branches: [ main ] |
| 24 | + |
| 25 | +permissions: read-all # Needed for security checks, adjust if necessary |
| 26 | + |
| 27 | +jobs: |
| 28 | + build_and_test: |
| 29 | + name: Build and Test |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Checkout Code |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + # Bazel needs a JDK. Setup Java 11 as required by the tests. |
| 37 | + - name: Setup Java JDK 11 |
| 38 | + uses: actions/setup-java@v4 |
| 39 | + with: |
| 40 | + distribution: 'temurin' |
| 41 | + java-version: '11' |
| 42 | + |
| 43 | + # Set up Go environment for go install |
| 44 | + - name: Setup Go |
| 45 | + uses: actions/setup-go@v5 |
| 46 | + with: |
| 47 | + go-version: '1.24.2' |
| 48 | + |
| 49 | + # Use bazelisk to manage Bazel versions based on .bazelversion |
| 50 | + - name: Install Bazelisk via Go |
| 51 | + run: go install github.com/bazelbuild/bazelisk@latest |
| 52 | + |
| 53 | + - name: Mount Bazel repository cache |
| 54 | + uses: actions/cache@v4 |
| 55 | + with: |
| 56 | + path: | |
| 57 | + ~/.cache/bazel/_bazel_${{ runner.os }}/repos |
| 58 | + ~/.cache/bazel/_bazel_${{ runner.os }}/external |
| 59 | + key: bazel-repo-${{ hashFiles('**/MODULE.bazel.lock', '**/maven_install.json', '**/pnpm-lock.yaml') }} |
| 60 | + restore-keys: | |
| 61 | + bazel-repo- |
| 62 | +
|
| 63 | + # Setup Bazel action cache |
| 64 | + # Caching build results can significantly speed up CI. |
| 65 | + # Be cautious with cache size and eviction. |
| 66 | + - name: Mount Bazel action cache |
| 67 | + uses: actions/cache@v4 |
| 68 | + with: |
| 69 | + path: ~/.cache/bazel/_bazel_${{ runner.os }}/execroot/**/bazel-out |
| 70 | + key: bazel-action-${{ github.sha }}-${{ hashFiles('**/MODULE.bazel.lock', '**/maven_install.json', '**/pnpm-lock.yaml') }} |
| 71 | + restore-keys: | |
| 72 | + bazel-action-${{ github.ref }}-${{ hashFiles('**/MODULE.bazel.lock', '**/maven_install.json', '**/pnpm-lock.yaml') }} |
| 73 | + bazel-action- |
| 74 | +
|
| 75 | + - name: Build all targets |
| 76 | + run: bazelisk build //... |
| 77 | + |
| 78 | + - name: Test all targets |
| 79 | + # --test_output=errors only shows logs for failed tests |
| 80 | + run: bazelisk test //... --test_output=errors |
0 commit comments