<commit_before>name: tests

on: [push, pull_request]

env:
  RE2C_VERSION: 2.2
  ZEPHIR_PARSER_VERSION: 1.4.1
  CACHE_DIR: .cache

jobs:
  analyze:
    runs-on: ubuntu-18.04
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
        with:
          fetch-depth: 1

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          coverage: none
          tools: php-cs-fixer, phpcs

      - name: Run PHP_CodeSniffer
        run: |
          phpcs --version
          phpcs --runtime-set ignore_warnings_on_exit true

      # @TODO: Apply fix from `feature/win-unix-builds
      - name: Run PHP CS Fixer
        if: always()
        run: |
          php-cs-fixer --version
          php-cs-fixer fix --diff --dry-run -v --using-cache=no || true

      - name: Run Shell Check
        if: always()
        run: shellcheck .ci/*.sh

  build-and-test:
    name: "PHP-${{ matrix.php }}-${{ matrix.build_type }}-${{ matrix.name }}-${{ matrix.compiler }}-${{ matrix.arch }}"
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false

      matrix:
        include:
          # Linux
          - name: ubuntu
            os: ubuntu-18.04
            php: '7.4'
            arch: 'x64'
            build_type: 'nts'
            compiler: gcc

          # macOS
          - name: macos
            os: macos-10.15
            php: '7.4'
            arch: 'x64'
            build_type: 'nts'
            compiler: clang

          # Windows
          - name: win32
            os: windows-2016
            php: '7.4'
            arch: 'x64'
            build_type: 'nts'
            compiler: vc15

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 5

      - name: Install PHP ${{ matrix.php }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: '${{ matrix.php }}'
          extensions: mbstring, fileinfo, gmp, sqlite, pdo_sqlite, psr, zip, mysqli, zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}
          tools: phpize, php-config
          coverage: xdebug
          # variables_order: https://github.com/zephir-lang/zephir/pull/1537
          # enable_dl:       https://github.com/zephir-lang/zephir/pull/1654
          # allow_url_fopen: https://github.com/zephir-lang/zephir/issues/1713
          # error_reporting: https://github.com/zendframework/zend-code/issues/160
          ini-values: >-
            variables_order=EGPCS,
            enable_dl=On,
            allow_url_fopen=On,
            error_reporting=-1,
            memory_limit=1G,
            date.timezone=UTC,
            xdebug.max_nesting_level=256
        env:
          PHPTS: ${{ matrix.build_type }}
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Get composer cache directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"

      - name: Set Up Composer Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-

      - name: Install Project Dependencies
        run: |
          echo "::group::Install composer dependencies"
          composer install --prefer-dist --no-interaction --no-ansi --no-progress
          echo "::endgroup::"

      - name: Fast Commands Test
        run: php zephir --help

      - name: Build Test Extension (Linux)
        if: runner.os == 'Linux'
        uses: ./.github/workflows/build-linux-ext
        with:
          compiler: ${{ matrix.compiler }}
          cflags: '-O2 -Wall -fvisibility=hidden -flto -DZEPHIR_RELEASE=1'
          ldflags: '--coverage'

      - name: Build Test Extension (macOS)
        if: runner.os == 'macOS'
        uses: ./.github/workflows/build-macos-ext
        with:
          compiler: ${{ matrix.compiler }}
          cflags: '-O2 -fvisibility=hidden -Wparentheses -flto -DZEPHIR_RELEASE=1'

      - name: Build Test Extension (Windows)
        if: runner.os == 'Windows'
        uses: ./.github/workflows/build-win-ext
        with:
          php_version: ${{ matrix.php }}
          ts: ${{ matrix.build_type }}
          msvc: ${{ matrix.compiler }}
          arch: ${{ matrix.arch }}
        env:
          CACHE_DIR: 'C:\Downloads'

      - name: Setup Extension Path
        shell: bash
        run: |
          case ${{ runner.os }} in
            Linux*)
              echo "STUB_EXT=./ext/modules/stub.so" >> $GITHUB_ENV
              echo "PHP=$(which php)" >> $GITHUB_ENV
              ;;
            macOS*)
              echo "STUB_EXT=./ext/modules/stub.so" >> $GITHUB_ENV
              echo "PHP=$(which php)" >> $GITHUB_ENV
              ;;
            Windows*)
              if [ "${{ matrix.arch }}" = "x64" ]; then
                echo "STUB_EXT=./ext/x64/Release/php_stub.dll" >> $GITHUB_ENV
              else
                echo "STUB_EXT=./ext/Release/php_stub.dll" >> $GITHUB_ENV
              fi

              echo "PHP=$(which php)" >> $GITHUB_ENV
              ;;
          esac

      - name: Stub Extension Info
        run: |
          php -d extension=${{ env.STUB_EXT }} --ri stub

      - name: Setup problem matchers for PHPUnit
        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

      - name: Unit Tests (Stub Extension)
        shell: bash
        run: |
          php -d extension=${{ env.STUB_EXT }} vendor/bin/phpunit -c phpunit.ext.xml

      - name: Unit Tests (Zephir)
        if: always()
        run: vendor/bin/phpunit --testsuite Zephir
        env:
          XDEBUG_MODE: coverage

      - name: Black-box Testing
        if: always() && runner.os != 'Windows'
        shell: bash
        working-directory: tests/sharness
        run: |
          make -j$(getconf _NPROCESSORS_ONLN)

      - name: Upload Code Coverage Report
        uses: codecov/codecov-action@v2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ./tests/output/clover.xml
          flags: unittests,${{ matrix.name }},php-${{ matrix.php }}
          name: codecov-umbrella

      - name: Upload build artifacts after Failure
        if: failure()
        uses: actions/upload-artifact@v2
        with:
          name: debug-${{ matrix.name }}-${{ matrix.php }}-${{ matrix.build_type }}-${{ matrix.name }}-${{ matrix.compiler }}-${{ matrix.arch }}
          path: |
            ${{ github.workspace }}/*.log
            ${{ github.workspace }}/ext/
            !${{ github.workspace }}/ext/kernel/
            !${{ github.workspace }}/ext/stub/
            !${{ github.workspace }}/ext/Release/
            !${{ github.workspace }}/ext/x64/Release/
          retention-days: 1
<commit_msg>Rework extension test runnner<commit_after>name: tests

on: [push, pull_request]

env:
  RE2C_VERSION: 2.2
  ZEPHIR_PARSER_VERSION: 1.4.1
  CACHE_DIR: .cache

jobs:
  analyze:
    runs-on: ubuntu-18.04
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
        with:
          fetch-depth: 1

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          coverage: none
          tools: php-cs-fixer, phpcs

      - name: Run PHP_CodeSniffer
        run: |
          phpcs --version
          phpcs --runtime-set ignore_warnings_on_exit true

      # @TODO: Apply fix from `feature/win-unix-builds
      - name: Run PHP CS Fixer
        if: always()
        run: |
          php-cs-fixer --version
          php-cs-fixer fix --diff --dry-run -v --using-cache=no || true

      - name: Run Shell Check
        if: always()
        run: shellcheck .ci/*.sh

  build-and-test:
    name: "PHP-${{ matrix.php }}-${{ matrix.build_type }}-${{ matrix.name }}-${{ matrix.compiler }}-${{ matrix.arch }}"
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false

      matrix:
        include:
          # Linux
          - name: ubuntu
            os: ubuntu-18.04
            php: '7.4'
            arch: 'x64'
            build_type: 'nts'
            compiler: gcc

          # macOS
          - name: macos
            os: macos-10.15
            php: '7.4'
            arch: 'x64'
            build_type: 'nts'
            compiler: clang

          # Windows
          - name: win32
            os: windows-2016
            php: '7.4'
            arch: 'x64'
            build_type: 'nts'
            compiler: vc15

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 5

      - name: Install PHP ${{ matrix.php }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: '${{ matrix.php }}'
          extensions: mbstring, fileinfo, gmp, sqlite, pdo_sqlite, psr, zip, mysqli, zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}
          tools: phpize, php-config
          coverage: xdebug
          # variables_order: https://github.com/zephir-lang/zephir/pull/1537
          # enable_dl:       https://github.com/zephir-lang/zephir/pull/1654
          # allow_url_fopen: https://github.com/zephir-lang/zephir/issues/1713
          # error_reporting: https://github.com/zendframework/zend-code/issues/160
          ini-values: >-
            variables_order=EGPCS,
            enable_dl=On,
            allow_url_fopen=On,
            error_reporting=-1,
            memory_limit=1G,
            date.timezone=UTC,
            xdebug.max_nesting_level=256
        env:
          PHPTS: ${{ matrix.build_type }}
          COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Get composer cache directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"

      - name: Set Up Composer Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-

      - name: Install Project Dependencies
        run: |
          echo "::group::Install composer dependencies"
          composer install --prefer-dist --no-interaction --no-ansi --no-progress
          echo "::endgroup::"

      - name: Fast Commands Test
        run: php zephir --help

      - name: Build Test Extension (Linux)
        if: runner.os == 'Linux'
        uses: ./.github/workflows/build-linux-ext
        with:
          compiler: ${{ matrix.compiler }}
          cflags: '-O2 -Wall -fvisibility=hidden -flto -DZEPHIR_RELEASE=1'
          ldflags: '--coverage'

      - name: Build Test Extension (macOS)
        if: runner.os == 'macOS'
        uses: ./.github/workflows/build-macos-ext
        with:
          compiler: ${{ matrix.compiler }}
          cflags: '-O2 -fvisibility=hidden -Wparentheses -flto -DZEPHIR_RELEASE=1'

      - name: Build Test Extension (Windows)
        if: runner.os == 'Windows'
        uses: ./.github/workflows/build-win-ext
        with:
          php_version: ${{ matrix.php }}
          ts: ${{ matrix.build_type }}
          msvc: ${{ matrix.compiler }}
          arch: ${{ matrix.arch }}
        env:
          CACHE_DIR: 'C:\Downloads'

      - name: Stub Extension Info
        run: |
          if ("${{ runner.os }}" -eq "Windows") {
            php --ri stub
          } else {
            php -d extension=./ext/modules/stub.so --ri stub
          }

      - name: Setup problem matchers for PHPUnit
        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

      - name: Unit Tests (Stub Extension)
        run: |
          if ("${{ runner.os }}" -eq "Windows") {
            php vendor/bin/phpunit -c phpunit.ext.xml
          } else {
            php -d extension=./ext/modules/stub.so vendor/bin/phpunit -c phpunit.ext.xml
          }

      - name: Unit Tests (Zephir)
        if: always()
        run: vendor/bin/phpunit --testsuite Zephir
        env:
          XDEBUG_MODE: coverage

      - name: Black-box Testing
        if: always() && runner.os != 'Windows'
        shell: bash
        working-directory: tests/sharness
        run: |
          make -j$(getconf _NPROCESSORS_ONLN)

      - name: Upload Code Coverage Report
        uses: codecov/codecov-action@v2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: ./tests/output/clover.xml
          flags: unittests,${{ matrix.name }},php-${{ matrix.php }}
          name: codecov-umbrella

      - name: Upload build artifacts after Failure
        if: failure()
        uses: actions/upload-artifact@v2
        with:
          name: debug-${{ matrix.name }}-${{ matrix.php }}-${{ matrix.build_type }}-${{ matrix.name }}-${{ matrix.compiler }}-${{ matrix.arch }}
          path: |
            ${{ github.workspace }}/*.log
            ${{ github.workspace }}/ext/
            !${{ github.workspace }}/ext/kernel/
            !${{ github.workspace }}/ext/stub/
            !${{ github.workspace }}/ext/Release/
            !${{ github.workspace }}/ext/x64/Release/
          retention-days: 1

{'fraction_non_alphanumeric': 0.13415379911328543, 'fraction_numerical': 0.011924782143403149, 'mean_word_length': 1.629748743718593, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4303020', 'n_tokens_mistral': 4334, 'n_tokens_neox': 4064, 'n_words': 900}