name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
  workflow_dispatch:

jobs:

  test:

    runs-on: ubuntu-22.04
    continue-on-error: ${{ matrix.experimental }}

    strategy:
      matrix:
        include:
          - mediawiki_version: '1.39'
            smw_version: 5.1.0
            php_version: 8.1
            mm_version: 6.0.1
            database_type: mysql
            database_image: "mariadb:11.2"
            coverage: false
            experimental: false
          - mediawiki_version: '1.40'
            smw_version: 5.1.0
            php_version: 8.1
            mm_version: 6.0.1
            database_type: mysql
            database_image: "mariadb:11.2"
            coverage: true
            experimental: false
          - mediawiki_version: '1.41'
            smw_version: 5.1.0
            pf_version: 5.9
            sfs_version: dev-master
            php_version: 8.1
            mm_version: 6.0.1
            database_type: mysql
            database_image: "mariadb:11.2"
            coverage: false
            experimental: false
          - mediawiki_version: '1.42'
            smw_version: 5.1.0
            pf_version: 5.9
            sfs_version: dev-master
            php_version: 8.1
            mm_version: 6.0.1
            database_type: mysql
            database_image: "mariadb:11.2"
            coverage: false
            experimental: false
          - mediawiki_version: '1.43.1'
            smw_version: dev-master
            pf_version: 5.9
            sfs_version: dev-master
            php_version: 8.1
            mm_version: 6.0.1
            database_type: mysql
            database_image: "mariadb:11.2"
            coverage: false
            experimental: false

    env:
      MW_VERSION: ${{ matrix.mediawiki_version }}
      SMW_VERSION: ${{ matrix.smw_version }}
      PF_VERSION: ${{ matrix.pf_version }}
      SFS_VERSION: ${{ matrix.sfs_version }}
      PHP_VERSION: ${{ matrix.php_version }}
      DB_TYPE: ${{ matrix.database_type }}
      DB_IMAGE: ${{ matrix.database_image }}
      MM_VERSION: ${{ matrix.mm_version }} 

      
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive
                   
      - name: Update submodules
        run: git submodule update --init --remote

      - name: Run tests
        run: make ci
        if: matrix.coverage == false

      - name: Run tests with coverage
        run: make ci-coverage
        if: matrix.coverage == true

      - name: Upload code coverage
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: coverage/php/coverage.xml
        if: matrix.coverage == true
