name: Wikibase Secondary CI
on:
  push:
    branches: [ master ]

env:
  COMPOSER_HOME: ${{ github.workspace }}/.composer

jobs:
  secondary-ci:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
        - env:
            MW_BRANCH: master
            DBTYPE: sqlite
            LANG: ru
            WB: both
            IPMASKING: enabled
          php-versions: '8.3.30'
        - env:
            MW_BRANCH: master
            DBTYPE: sqlite
            LANG: en
            WB: client
            IPMASKING: disabled
          php-versions: '8.3.30'
        - env:
            MW_BRANCH: master
            DBTYPE: mysql
            LANG: en
            WB: repo
            IPMASKING: enabled
          php-versions: '8.3.30'
        - env:
            MW_BRANCH: master
            DBTYPE: sqlite
            LANG: ar
            WB: both
            IPMASKING: disabled
          php-versions: '8.3.30'
        - env:
            MW_BRANCH: master
            DBTYPE: mysql
            LANG: en
            WB: both
            IPMASKING: enabled
          php-versions: '8.3.30'
    steps:
    - name: Checkout
      uses: actions/checkout@v3
    - name: Set up MySQL
      uses: mirromutth/mysql-action@v1.1
      with:
        mysql version: '5.7'
        mysql database: 'test_db_wiki'
        mysql root password: 'root'
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php-versions }}
        extensions: pdo_sqlite, mysqlnd
    - name: Cache Composer cache
      uses: actions/cache@v4.2.3
      with:
        path: ${{ env.COMPOSER_HOME }}/cache
        key: composer-cache-php${{ matrix.php-versions }}
    - name: install.sh
      env: ${{ matrix.env }}
      run: |
        bash ./build/ci-scripts/install.sh
    - name: Apply WB settings
      env: ${{ matrix.env }}
      run: |
        bash ./build/ci-scripts/mw-apply-wb-settings.sh
    - name: Update DB
      env: ${{ matrix.env }}
      run: |
        bash ./build/ci-scripts/update-db.sh
    - name: Run script
      env: ${{ matrix.env }}
      run: |
        bash ./build/ci-scripts/script.sh
    - name: Send mail
      if: ${{ failure() }}
      uses: dawidd6/action-send-mail@v3.7.1
      with:
        server_address: smtp.gmail.com
        server_port: 465
        username: ${{secrets.WMDE_CI_MAIL_USERNAME}}
        password: ${{secrets.WMDE_CI_MAIL_PASSWORD}}
        subject: Github Action job failed for Wikibase
        html_body: |
          Job secondary-ci failed!
          The failed job can be found in <a href="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}">here</a>
          <h3>Specifications of the failed job:</h3>
          <ul>
          <li>php version: ${{ matrix.php-versions }}</li>
          <li>Database type: ${{ matrix.env.DBTYPE }}</li>
          <li>MediaWiki language: ${{ matrix.env.LANG }}</li>
          <li>Wikibase type: ${{ matrix.env.WB }}</li>
          <li>MediaWiki core branch: ${{ matrix.env.MW_BRANCH }}</li>
          </ul>
          CI specifications can be found in <a href="https://github.com/${{ github.repository }}/actions/workflows/secondaryCI.yml">here</a>
        to: wikidata-ci-status@wikimedia.de
        from: Wikibase Github Action CI
