---
name: CI

on:
  push:
    branches: [master]
    paths:
      - "scripts.js"
      - "common/*"
      - "*/grammar.js"
      - "*/src/**"
      - "bindings/**"
      - "binding.gyp"
  pull_request:
    paths:
      - "scripts.js"
      - "common/*"
      - "*/grammar.js"
      - "*/src/**"
      - "bindings/**"
      - "binding.gyp"

concurrency:
  group: ${{github.workflow}}-${{github.ref}}
  cancel-in-progress: true

jobs:
  test:
    name: Test parsers
    runs-on: ${{matrix.os}}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-14]
    steps:
      - name: Checkout repository
        uses: actions/checkout@v5
      - name: Set up tree-sitter
        uses: tree-sitter/setup-action/cli@v2
      - name: Set up examples
        run: |-
          git clone https://github.com/laravel/laravel examples/laravel --single-branch --depth=1 --filter=blob:none
          git clone https://github.com/laravel/framework examples/framework --single-branch --depth=1 --filter=blob:none
          git clone https://github.com/phacility/phabricator examples/phabricator --single-branch --depth=1 --filter=blob:none
          git clone https://github.com/sebastianbergmann/phpunit examples/phpunit --single-branch --depth=1 --filter=blob:none
          git clone https://github.com/WordPress/WordPress examples/WordPress --single-branch --depth=1 --filter=blob:none
          git clone https://github.com/wikimedia/mediawiki examples/mediawiki --single-branch --depth=1 --filter=blob:none
      - name: Run tests
        uses: tree-sitter/parser-test-action@v2
        with:
          generate: false
          test-rust: true
          test-node: true
          test-python: false
          test-go: true
          test-swift: false
      - name: Parse examples
        id: test
        uses: tree-sitter/parse-action@v4
        with:
          files: |
            examples/**/*.php
          invalid-files: |
            examples/framework/tests/Foundation/fixtures/bad-syntax-strategy.php
            examples/WordPress/wp-includes/php-compat/readonly.php
