name: Push
on:
  push:
    paths-ignore:
      - docs/*
      - NEWS
      - UPGRADING
      - UPGRADING.INTERNALS
      - README.md
      - CONTRIBUTING.md
      - CODING_STANDARDS.md
    branches:
      - PHP-7.4
      - PHP-8.0
      - PHP-8.1
      - PHP-8.2
      - master
  pull_request:
    branches:
      - '**'
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.url || github.run_id }}
  cancel-in-progress: true
env:
  CC: ccache gcc
  CXX: ccache g++
jobs:
  LINUX_X64:
    strategy:
      fail-fast: false
      matrix:
        include:
          - debug: true
            zts: false
          - debug: false
            zts: true
    name: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}"
    runs-on: ubuntu-20.04
    steps:
      - name: git checkout
        uses: actions/checkout@v3
      - name: Create MSSQL container
        uses: ./.github/actions/setup-mssql
      - name: Create Oracle container
        uses: ./.github/actions/setup-oracle
      - name: apt
        uses: ./.github/actions/apt-x64
      - name: ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          # This duplicates the "job.name" expression above because
          # GitHub has no way to query the job name (github.job is the
          # job id, not the job name)
          key: "LINUX_X64_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}-${{hashFiles('main/php_version.h')}}"
          append-timestamp: false
      - name: ./configure
        uses: ./.github/actions/configure-x64
        with:
          configurationParameters: >-
            --${{ matrix.debug && 'enable' || 'disable' }}-debug
            --${{ matrix.zts && 'enable' || 'disable' }}-zts
      - name: make
        run: make -j$(/usr/bin/nproc) >/dev/null
      - name: make install
        uses: ./.github/actions/install-linux
      - name: Setup
        uses: ./.github/actions/setup-x64
      - name: Test
        uses: ./.github/actions/test-linux
        with:
          testArtifacts: ${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}
      - name: Test Tracing JIT
        uses: ./.github/actions/test-linux
        with:
          testArtifacts: ${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }} Tracing JIT
          runTestsParameters: >-
            -d zend_extension=opcache.so
            -d opcache.enable_cli=1
            -d opcache.jit_buffer_size=16M
      - name: Verify generated files are up to date
        uses: ./.github/actions/verify-generated-files
  LINUX_X32:
    name: LINUX_X32_DEBUG_ZTS
    runs-on: ubuntu-latest
    container:
      image: ubuntu:20.04
    env:
      MYSQL_TEST_HOST: mysql
      PDO_MYSQL_TEST_DSN: mysql:host=mysql;dbname=test
      PDO_MYSQL_TEST_HOST: mysql
    services:
      mysql:
        image: mysql:8
        ports:
          - 3306:3306
        env:
          MYSQL_DATABASE: test
          MYSQL_ROOT_PASSWORD: root
    steps:
      - name: git checkout
        uses: actions/checkout@v3
      - name: apt
        uses: ./.github/actions/apt-x32
      - name: ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: "${{github.job}}-${{hashFiles('main/php_version.h')}}"
          append-timestamp: false
      - name: ./configure
        uses: ./.github/actions/configure-x32
        with:
          configurationParameters: >-
            --enable-debug
            --enable-zts
      - name: make
        run: make -j$(/usr/bin/nproc) >/dev/null
      - name: make install
        uses: ./.github/actions/install-linux-x32
      - name: Test
        uses: ./.github/actions/test-linux
      - name: Test Tracing JIT
        uses: ./.github/actions/test-linux
        with:
          runTestsParameters: >-
            -d zend_extension=opcache.so
            -d opcache.enable_cli=1
            -d opcache.jit_buffer_size=16M
  MACOS_DEBUG_NTS:
    runs-on: macos-11
    steps:
      - name: git checkout
        uses: actions/checkout@v3
      - name: brew
        uses: ./.github/actions/brew
      - name: ccache
        uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: "${{github.job}}-${{hashFiles('main/php_version.h')}}"
          append-timestamp: false
      - name: ./configure
        uses: ./.github/actions/configure-macos
        with:
          configurationParameters: --enable-debug --disable-zts
      - name: make
        run: |-
          export PATH="/usr/local/opt/bison/bin:$PATH"
          make -j$(sysctl -n hw.logicalcpu) >/dev/null
      - name: make install
        run: sudo make install
      - name: Test
        uses: ./.github/actions/test-macos
        with:
          testArtifacts: ${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}
      - name: Test Tracing JIT
        uses: ./.github/actions/test-macos
        with:
          testArtifacts: ${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }} Tracing JIT
          runTestsParameters: >-
            -d zend_extension=opcache.so
            -d opcache.enable_cli=1
            -d opcache.protect_memory=1
            -d opcache.jit_buffer_size=16M
      - name: Verify generated files are up to date
        uses: ./.github/actions/verify-generated-files
  WINDOWS:
    strategy:
      fail-fast: false
      matrix:
        include:
          - x64: true
            zts: false
            opcache: true
          - x64: false
            zts: true
            opcache: false
    name: "WINDOWS_${{ matrix.x64 && 'X64' || 'X86' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}"
    runs-on: windows-2019
    env:
      PHP_BUILD_CACHE_BASE_DIR: C:\build-cache
      PHP_BUILD_OBJ_DIR: C:\obj
      PHP_BUILD_CACHE_SDK_DIR: C:\build-cache\sdk
      PHP_BUILD_SDK_BRANCH: php-sdk-2.2.0
      PHP_BUILD_CRT: vs16
      PLATFORM: ${{ matrix.x64 && 'x64' || 'x86' }}
      THREAD_SAFE: "${{ matrix.zts && '1' || '0' }}"
      INTRINSICS: "${{ matrix.zts && 'AVX2' || '' }}"
      PARALLEL: -j2
      OPCACHE: "${{ matrix.opcache && '1' || '0' }}"
    steps:
      - name: git config
        run: git config --global core.autocrlf false && git config --global core.eol lf
      - name: git checkout
        uses: actions/checkout@v3
      - name: Setup MySQL
        run: |
          choco install mysql -y --no-progress --params="/port:3306"
          mysql.exe --port=3306 --user=root --password="" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password12!'; FLUSH PRIVILEGES;"
      - name: Setup MSSQL
        run: |
          choco install sql-server-express -y --no-progress --install-arguments="/SECURITYMODE=SQL /SAPWD=Password12!"
      - name: Setup PostgreSQL
        run: |
          Set-Service -Name "postgresql-x64-14" -StartupType manual -Status Running
          pwsh -Command { $env:PGPASSWORD="root"; & "$env:PGBIN\psql" -U postgres -c "ALTER USER postgres WITH PASSWORD 'Password12!';" }
      - name: Build
        run: .github/scripts/windows/build.bat
      - name: Test
        run: .github/scripts/windows/test.bat
