name: Build and Run Tests by Bazel
on:
  pull_request:
    types: [opened, reopened, synchronize]
  push:
    branches:
      - master
      - develop
      - bazel

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
  build:
    name: "bazel-compile (${{ matrix.os }})"
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
    steps:
      - uses: actions/checkout@v4
      - name: Cache Bazel repository
        uses: actions/cache@v4
        with:
          path: |
            ~/.cache/bazel
          key: bazel-repo-${{ runner.os }}-${{ hashFiles('WORKSPACE') }}
          restore-keys: |
            bazel-repo-${{ runner.os }}-
      - name: Build
        run: bazel build --config=remote //...
      - name: Run Tests
        run: bazel test --config=remote //...