name: Unit tests

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, reopened, synchronize]
  workflow_dispatch:

permissions:
  contents: read

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
        compiler: ['gcc', 'clang']
        exclude:
          - os: macos-latest
            compiler: gcc  # gcc is clang on macOS

    runs-on: ${{ matrix.os }}

    env:
        CC: ${{ matrix.compiler }}

    steps:
    - uses: actions/checkout@v4
    - name: Log compiler version
      run: |
        "$CC" --version
    - name: make test    # unit tests
      run: make test
    # TODO(creachadair): As of 25-Jan-2024, the GMP compatibility tests
    # on gcc no longer work correctly when run in containers either
    # locally or in github actions. They work fine from the CLI, but
    # for now turn them off in CI.
    - name: make check   # unit and compatibility tests
      if: matrix.compiler != 'gcc'  # `make check` is failing on gcc
      run: make check
