name: CI

on:
  push:
    branches:
      - '*'
  pull_request:
    branches:
      - '*'

# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners

concurrency:
  # On master/release, we don't want any jobs cancelled so the sha is used to name the group
  # On PR branches, we cancel the job if new commits are pushed
  # More info: https://stackoverflow.com/a/68422069/253468
  group: ${{ (github.ref == 'refs/heads/branch_1.2.18' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release' ) && format('ci-main-{0}', github.sha) || format('ci-main-{0}', github.ref) }}
  cancel-in-progress: true

# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
# 
permissions:
  contents: read

jobs:
  Test:
    name: JDK ${{ matrix.jdk }}, ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        jdk: [8, 11, 17]
        os: [ubuntu-latest, windows-latest, macos-latest]
      fail-fast: true
      max-parallel: 4
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 50
    - name: Set up Java 8
      id: setup-java-8
      uses: actions/setup-java@v1
      with:
        java-version: 8
    - name: Set up Java ${{ matrix.jdk }}
      if: ${{ matrix.jdk != '8' }}
      uses: actions/setup-java@v1
      with:
        java-version: ${{ matrix.jdk }}
    - name: Compile
      # download dependencies, etc, so test log looks better
      run: mvn -B --toolchains .github/workflows/toolchains.xml compile
      env:
        JAVA_HOME_8: ${{ steps.setup-java-8.outputs.path }}
    - name: Test
      run: mvn -B --toolchains .github/workflows/toolchains.xml verify
      env:
        JAVA_HOME_8: ${{ steps.setup-java-8.outputs.path }}
