name: CI
on:
  pull_request:
  push:
    branches:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  setup-bazel:
    runs-on: ${{ matrix.os }}-latest
    strategy:
      fail-fast: false
      matrix:
        os:
          - macos
          - ubuntu
          - windows
    steps:
      - run: rm $(which bazel)
        if: matrix.os != 'windows'
      - run: Remove-Item -Path (Get-Command bazel.exe).Source
        if: matrix.os == 'windows'
      - uses: actions/checkout@v4
        with:
          repository: bazelbuild/examples
          sparse-checkout: java-maven
          sparse-checkout-cone-mode: false
      - run: mv java-maven/* .
      - uses: actions/checkout@v4
        with:
          path: setup-bazel
      - run: ls -l
      - uses: ./setup-bazel/
        with:
          bazelisk-cache: true
          bazelisk-version: 1.x
          remote-cache: true
          repository-cache: true
      - run: bazel build ...
        working-directory: java-maven
      - run: bazel test ...
        working-directory: java-maven
      - if: failure() && runner.debug == '1'
        uses: mxschmitt/action-tmate@v3
