build.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. name: build
  2. on:
  3. - push
  4. - pull_request
  5. jobs:
  6. tests:
  7. name: PHP ${{ matrix.php }} Test on ${{ matrix.os }}
  8. env:
  9. extensions: bz2, dom, iconv, fileinfo, openssl, xml, zlib
  10. key: cache-v1
  11. PHPUNIT_COVERAGE: 0
  12. PHP_INI: date.timezone='UTC', memory_limit=-1, opcache.enable=1, opcache.enable_cli=1
  13. strategy:
  14. matrix:
  15. os:
  16. - ubuntu-latest
  17. - windows-latest
  18. - macos-latest
  19. php:
  20. - '7.4'
  21. - '8.0'
  22. - '8.1'
  23. - '8.2'
  24. - '8.3'
  25. - '8.4'
  26. runs-on: ${{ matrix.os }}
  27. steps:
  28. -
  29. name: Checkout
  30. uses: actions/checkout@v4
  31. -
  32. name: Install linux dependencies
  33. if: matrix.os == 'ubuntu-latest'
  34. run: sudo apt-get install unzip p7zip-full
  35. -
  36. name: Install windows dependencies
  37. if: matrix.os == 'windows-latest'
  38. run: choco install zip unzip 7zip
  39. -
  40. name: Install macos dependencies
  41. if: matrix.os == 'macos-latest'
  42. run: brew install zip unzip p7zip
  43. -
  44. name: Disable JIT for PHP 8 on Linux and Mac
  45. if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') && matrix.php != '7.4'
  46. run: echo "PHP_INI=\"${PHP_INI}, opcache.jit=0, opcache.jit_buffer_size=0\"" >> $GITHUB_ENV
  47. -
  48. name: Disable JIT for PHP 8 on Windows
  49. if: matrix.os == 'windows-latest' && matrix.php != '7.4'
  50. run: echo "PHP_INI=\"$PHP_INI, opcache.jit=0, opcache.jit_buffer_size=0\"" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
  51. -
  52. name: Install PHP with extensions
  53. uses: shivammathur/setup-php@v2
  54. with:
  55. php-version: ${{ matrix.php }}
  56. extensions: ${{ env.extensions }}
  57. coverage: pcov
  58. ini-values: ${{ env.PHP_INI }}
  59. tools: composer:v2, cs2pr
  60. -
  61. name: Determine composer cache directory on Linux or MacOS
  62. if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
  63. run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
  64. -
  65. name: Determine composer cache directory on Windows
  66. if: matrix.os == 'windows-latest'
  67. run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
  68. -
  69. name: Set coverage args
  70. if: matrix.os == 'ubuntu-latest' && matrix.php == '7.4'
  71. run: echo "PHPUNIT_COVERAGE=1" >> $GITHUB_ENV
  72. -
  73. name: Cache composer dependencies
  74. uses: actions/cache@v4
  75. with:
  76. path: ${{ env.COMPOSER_CACHE_DIR }}
  77. key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
  78. restore-keys: php${{ matrix.php }}-composer-
  79. -
  80. name: Check PHP Version
  81. run: php -v
  82. -
  83. name: Check Composer Version
  84. run: composer -V
  85. -
  86. name: Check PHP Extensions
  87. run: php -m
  88. -
  89. name: Validate composer.json and composer.lock
  90. run: composer validate
  91. -
  92. name: Install dependencies with composer
  93. run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
  94. -
  95. name: Run tests with phpunit
  96. if: env.PHPUNIT_COVERAGE == 0
  97. run: vendor/bin/phpunit -v --testsuite "all_tests" --group small,medium,large
  98. -
  99. name: Run tests with phpunit and coverage
  100. if: env.PHPUNIT_COVERAGE == 1
  101. run: vendor/bin/phpunit -v --coverage-clover=coverage.clover --testsuite "all_tests" --group small,medium,large
  102. -
  103. name: Static analysis
  104. run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle | cs2pr --graceful-warnings --colorize
  105. -
  106. name: Upload code coverage scrutinizer
  107. if: env.PHPUNIT_COVERAGE == 1
  108. run: |
  109. wget https://scrutinizer-ci.com/ocular.phar
  110. php ocular.phar code-coverage:upload --format=php-clover coverage.clover