build.yml 4.7 KB

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