name: Continuous Integration

on:
  push:
    branches:
      - master
  pull_request:

env:
  EXTNAME: GTag
  MW_INSTALL_PATH: ${{ github.workspace }}

jobs:
  style:
    name: Code Style
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ ubuntu-latest ]
        php: [ '8.1', '8.2', '8.3', '8.4' ]
        mediawiki: [ REL1_43, master ]
    steps:
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: mbstring, intl
          coverage: none
          tools: composer
      - name: Setup MediaWiki
        uses: actions/checkout@v4
        with:
          repository: wikimedia/mediawiki
          ref: ${{ matrix.mediawiki }}
      - name: Setup Extension
        uses: actions/checkout@v4
        with:
          path: extensions/${{ env.EXTNAME }}
      - name: Setup Composer
        run: |
          echo '{"extra":{"merge-plugin":{"include":["extensions/*/composer.json","skins/*/composer.json"]}}}' > composer.local.json
          composer update
          composer update
      - name: Lint
        run: ./vendor/bin/parallel-lint --exclude node_modules --exclude vendor extensions/${{ env.EXTNAME }}
      - name: PHP Code Sniffer
        run: ./vendor/bin/phpcs -sp --standard=vendor/mediawiki/mediawiki-codesniffer/MediaWiki extensions/${{ env.EXTNAME }}

  security:
    name: Static Analysis
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ ubuntu-latest ]
        php: [ '8.1', '8.2', '8.3', '8.4' ]
        target: [ '8.1' ]
        mediawiki: [ REL1_43, master ]
        exclude:
          # 1.43 phan is broken on php 8.4
          - php: '8.4'
            mediawiki: REL1_43
    steps:
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          extensions: mbstring, intl, ast
          coverage: none
          tools: composer
      - name: Setup MediaWiki
        uses: actions/checkout@v4
        with:
          repository: wikimedia/mediawiki
          ref: ${{ matrix.mediawiki }}
      - name: Setup Extension
        uses: actions/checkout@v4
        with:
          path: extensions/${{ env.EXTNAME }}
      - name: Setup Composer
        run: |
          echo '{"extra":{"merge-plugin":{"include":["extensions/*/composer.json","skins/*/composer.json"]}}}' > composer.local.json
          composer update
          composer update
      - name: Phan
        run: ./vendor/bin/phan -d extensions/${{ env.EXTNAME }} --minimum-target-php-version=${{ matrix.target }} --long-progress-bar
