name: Test

on: 
  push:
    branches:
      - main
    paths:
      - 'src/**'
      - 'include/**'
      - 'test/src/**'
      - 'test/reference/**'
      - 'Makefile'
      - '*.mk'
      - 'test/Makefile'
      - '.github/workflows/test.yml'

  pull_request:
    paths:
      - 'src/**'
      - 'include/**'
      - 'test/src/**'
      - 'test/reference/**'
      - 'Makefile'
      - '*.mk'
      - 'test/Makefile'
      - '.github/workflows/test.yml'

jobs:

  test:
    name: Test and coverage

    runs-on: ubuntu-latest
    env:
      CC: gcc
      FORTIFY: 3
    steps:

    - uses: actions/checkout@v4

    - name: install dependencies
      run: sudo apt-get install -y lcov

    - name: Run regression tests
      run: make test

    - name: Generate coverage data
      run: make coverage

    - name: Upload coverage to Codecov.io
      uses: codecov/codecov-action@v5
      continue-on-error: true
      with:
        fail_ci_if_error: false
        flags: unittests
        name: codecov
        token: ${{ secrets.CODECOV_TOKEN }}
        verbose: true

    - name: Upload coverage to Coveralls.io
      continue-on-error: true
      uses: coverallsapp/github-action@v2


  test-platforms:
    name: ${{ matrix.arch }}
    # The host should always be linux
    runs-on: ubuntu-latest

    # Run steps on a matrix of 4 arch/distro combinations
    strategy:
      matrix:
        include:
          - arch: armv7
            distro: ubuntu_latest
          - arch: aarch64
            distro: ubuntu_latest
          - arch: riscv64
            distro: ubuntu_latest
          - arch: s390x
            distro: ubuntu_latest
          - arch: ppc64le
            distro: ubuntu_latest
    steps:
      - uses: actions/checkout@v4
      - uses: uraimo/run-on-arch-action@v3
        name: Run regression tests
        id: test
        with:
          arch: ${{ matrix.arch }}
          distro: ${{ matrix.distro }}
          install: |
            apt-get update -q -y
            apt-get install -q -y make gcc gfortran
          run: make test

