name: Test
on:
  push:
    paths-ignore: &ignore_paths
      - .circleci/**
      - .github/CODEOWNERS
      - .github/ISSUE_TEMPLATE/**
      - '**/*.md'
      - '**/*.rst'
      - docs/**
      - EXTENSIONS
      - LICENSE
      - NEWS
      - UPGRADING
      - UPGRADING.INTERNALS
    branches:
      - PHP-8.2
      - PHP-8.3
      - PHP-8.4
      - PHP-8.5
      - master
  pull_request:
    paths-ignore: *ignore_paths
    branches:
      - '**'
  schedule:
   - cron: "0 1 * * *"
  workflow_dispatch: ~
permissions:
  contents: read
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.url || github.run_id }}
  cancel-in-progress: true
jobs:
  GENERATE_MATRIX:
    name: Generate Matrix
    if: github.repository == 'php/php-src' || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
    runs-on: ubuntu-latest
    outputs:
      all_variations: ${{ steps.set-matrix.outputs.all_variations }}
      branches: ${{ steps.set-matrix.outputs.branches }}
    steps:
      - uses: actions/checkout@v6
        with:
          # When running nightly, set fetch-depth to 0 to clone the full
          # repository including all branches. This is required to find the
          # correct commit hashes.
          fetch-depth: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && '0' || '1' }}
      - name: Grab the commit mapping
        if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
        uses: actions/cache@v5
        with:
          path: branch-commit-cache.json
          # The cache key needs to change every time for the
          # cache to be updated after this job finishes.
          key: nightly-${{ github.run_id }}-${{ github.run_attempt }}
          restore-keys: |
            nightly-
      - name: Generate Matrix
        id: set-matrix
        run: php .github/matrix.php "${{ github.event_name }}" "${{ github.run_attempt }}" "${{ github.event_name == 'pull_request' && github.ref || github.ref_name }}" '${{ toJSON(github.event.pull_request.labels) }}' "${{ github.repository }}"
  TEST:
    needs: GENERATE_MATRIX
    if: ${{ needs.GENERATE_MATRIX.outputs.branches != '[]' }}
    name: ${{ matrix.branch.name }}
    uses: ./.github/workflows/test-suite.yml
    strategy:
      fail-fast: false
      matrix:
        branch: ${{ fromJson(needs.GENERATE_MATRIX.outputs.branches) }}
    with:
      all_variations: ${{ needs.GENERATE_MATRIX.outputs.all_variations == 'true' }}
      branch: ${{ toJSON(matrix.branch) }}
    secrets: inherit
