name: Verify Pull Request

env:
  MAVEN_ARGS: -V -ntp -e

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

on:
  pull_request:
    branches: [ main ]
  workflow_dispatch:

jobs:
  check_format_and_tests:
    strategy:
      matrix:
        os: [ ubuntu-latest, windows-latest, macos-latest ]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Set up Java and Maven
        uses: actions/setup-java@v3
        with:
          distribution: temurin
          java-version: 17
          cache: 'maven'
      - name: Check code format
        run: |
          ./mvnw ${MAVEN_ARGS} formatter:validate -Dconfigfile=$PWD/contributing/eclipse-google-style.xml --file pom.xml
          ./mvnw ${MAVEN_ARGS} impsort:check --file pom.xml
      - name: Run unit tests
        run: ./mvnw ${MAVEN_ARGS} -B test --file pom.xml