ci.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. name: CI
  2. on:
  3. - pull_request
  4. - push
  5. permissions:
  6. contents: read # to fetch code (actions/checkout)
  7. concurrency:
  8. group: ci-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches
  9. cancel-in-progress: true
  10. env:
  11. PHP_MAX: '8.3'
  12. PHP_MIN: '7.4'
  13. jobs:
  14. tests:
  15. continue-on-error: ${{ matrix.operating-system == 'macos-latest' }}
  16. strategy:
  17. fail-fast: false
  18. matrix:
  19. include:
  20. - operating-system: 'ubuntu-24.04'
  21. php-version: '7.4'
  22. job-description: 'Fixer with lowest deps'
  23. run-fixer: 'yes'
  24. composer-flags: '--prefer-lowest' # should be checked on the lowest supported PHP version
  25. execute-flex-with-symfony-version: '^5' # explicit check for Symfony 5.x compatibility
  26. - operating-system: 'ubuntu-24.04'
  27. php-version: '7.4'
  28. job-description: 'tests with lowest deps'
  29. run-tests: 'yes'
  30. composer-flags: '--prefer-lowest' # should be checked on the lowest supported PHP version
  31. execute-flex-with-symfony-version: '^5' # explicit check for Symfony 5.x compatibility
  32. - operating-system: 'ubuntu-24.04'
  33. php-version: '8.0'
  34. job-description: 'Fixer'
  35. run-fixer: 'yes'
  36. - operating-system: 'ubuntu-24.04'
  37. php-version: '8.0'
  38. job-description: 'tests'
  39. run-tests: 'yes'
  40. - operating-system: 'ubuntu-24.04'
  41. php-version: '8.1'
  42. job-description: 'Fixer with Symfony ^6'
  43. run-fixer: 'yes'
  44. execute-flex-with-symfony-version: '^6' # explicit check for Symfony 6.x compatibility
  45. - operating-system: 'ubuntu-24.04'
  46. php-version: '8.1'
  47. job-description: 'tests with Symfony ^6'
  48. run-tests: 'yes'
  49. execute-flex-with-symfony-version: '^6' # explicit check for Symfony 6.x compatibility
  50. - operating-system: 'ubuntu-24.04'
  51. php-version: '8.2'
  52. job-description: 'Fixer'
  53. run-fixer: 'yes'
  54. - operating-system: 'ubuntu-24.04'
  55. php-version: '8.2'
  56. job-description: 'tests'
  57. run-tests: 'yes'
  58. - operating-system: 'ubuntu-24.04'
  59. php-version: '8.3'
  60. job-description: 'Fixer'
  61. run-fixer: 'yes'
  62. - operating-system: 'ubuntu-24.04'
  63. php-version: '8.3'
  64. job-description: 'tests'
  65. run-tests: 'yes'
  66. - operating-system: 'ubuntu-24.04'
  67. php-version: '8.3'
  68. job-description: 'Fixer with migration rules'
  69. run-fixer: 'yes'
  70. run-migration-rules: 'yes' # should be checked on the highest supported PHP version
  71. - operating-system: 'ubuntu-24.04'
  72. php-version: '8.3'
  73. job-description: 'tests with migration rules'
  74. run-tests: 'yes'
  75. run-migration-rules: 'yes' # should be checked on the highest supported PHP version
  76. - operating-system: 'ubuntu-24.04'
  77. php-version: '8.3'
  78. job-description: 'Fixer with Symfony ^7'
  79. run-fixer: 'yes'
  80. execute-flex-with-symfony-version: '^7' # explicit check for Symfony 7.x compatibility
  81. - operating-system: 'ubuntu-24.04'
  82. php-version: '8.3'
  83. job-description: 'tests with Symfony ^7'
  84. run-tests: 'yes'
  85. execute-flex-with-symfony-version: '^7' # explicit check for Symfony 7.x compatibility
  86. - operating-system: 'ubuntu-24.04'
  87. php-version: '8.3'
  88. job-description: 'code coverage'
  89. run-tests: 'yes'
  90. collect-code-coverage: 'yes'
  91. - operating-system: 'ubuntu-24.04'
  92. php-version: '8.3'
  93. job-description: 'mutation tests'
  94. run-mutation-tests: 'yes'
  95. - operating-system: 'windows-latest'
  96. php-version: '8.3'
  97. job-description: 'Fixer on Windows'
  98. run-fixer: 'yes'
  99. FAST_LINT_TEST_CASES: 1 # we need full syntax check on one job at least, no need to do it on additional
  100. - operating-system: 'windows-latest'
  101. php-version: '8.3'
  102. job-description: 'tests on Windows'
  103. run-tests: 'yes'
  104. FAST_LINT_TEST_CASES: 1 # we need full syntax check on one job at least, no need to do it on additional systems
  105. - operating-system: 'macos-latest'
  106. php-version: '8.3'
  107. job-description: 'Fixer on macOS'
  108. run-fixer: 'yes'
  109. FAST_LINT_TEST_CASES: 1 # we need full syntax check on one job at least, no need to do it on additional systems
  110. - operating-system: 'macos-latest'
  111. php-version: '8.3'
  112. job-description: 'tests on macOS'
  113. run-tests: 'yes'
  114. FAST_LINT_TEST_CASES: 1 # we need full syntax check on one job at least, no need to do it on additional
  115. - operating-system: 'ubuntu-24.04'
  116. php-version: '8.4'
  117. job-description: 'Fixer'
  118. run-fixer: 'yes'
  119. PHP_CS_FIXER_IGNORE_ENV: 1
  120. - operating-system: 'ubuntu-24.04'
  121. php-version: '8.4'
  122. job-description: 'tests'
  123. run-tests: 'yes'
  124. PHP_CS_FIXER_IGNORE_ENV: 1
  125. name: PHP ${{ matrix.php-version }} ${{ matrix.job-description }}
  126. runs-on: ${{ matrix.operating-system }}
  127. steps:
  128. - name: Checkout code
  129. uses: actions/checkout@v4
  130. - name: Remove Infection requirement if not needed
  131. # TODO: Fix it properly. It somehow stopped working on MacOS (Composer not available)
  132. if: matrix.operating-system != 'macos-latest' && matrix.run-mutation-tests != 'yes'
  133. run: composer remove --dev infection/infection --no-update
  134. - name: Setup PHP with Composer deps
  135. uses: ./.github/composite-actions/setup-php-with-composer-deps
  136. with:
  137. os: ${{ runner.os }}
  138. php: ${{ matrix.php-version }}
  139. php-coverage: ${{ matrix.collect-code-coverage || matrix.run-mutation-tests }}
  140. composer-flags: ${{ matrix.composer-flags }}
  141. composer-flex-with-symfony-version: ${{ matrix.execute-flex-with-symfony-version }}
  142. # Execute migration rules before running tests and self-fixing,
  143. # so we know that our codebase is future-ready.
  144. # Should be checked on the highest supported PHP version.
  145. - name: Run PHP CS Fixer with migration rules
  146. if: env.PHP_MAX == matrix.php-version && matrix.run-migration-rules == 'yes'
  147. env:
  148. PHP_CS_FIXER_FUTURE_MODE: 1
  149. run: php php-cs-fixer fix --diff --config .php-cs-fixer.php-highest.php
  150. - name: Custom PHPUnit config for code coverage
  151. if: matrix.collect-code-coverage == 'yes' || matrix.run-mutation-tests
  152. run: sed -e 's/enforceTimeLimit="true"/enforceTimeLimit="false"/g' -e 's/coverage/source/g' phpunit.xml.dist > phpunit.xml
  153. - name: Disable time limit for tests under Windows # due to https://github.com/sebastianbergmann/phpunit/issues/5589
  154. if: matrix.operating-system == 'windows-latest'
  155. run: (Get-Content phpunit.xml.dist) -replace 'enforceTimeLimit="true"', 'enforceTimeLimit="false"' | Out-File phpunit.xml
  156. - name: Fix PHP 8.4 deprecations for tests
  157. if: matrix.run-tests == 'yes' && matrix.php-version == '8.4'
  158. env:
  159. PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
  160. run: php php-cs-fixer fix --rules=no_unreachable_default_argument_value,nullable_type_declaration_for_default_null_value --diff vendor
  161. - name: Run tests
  162. if: matrix.run-tests == 'yes' && matrix.collect-code-coverage != 'yes'
  163. env:
  164. PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
  165. FAST_LINT_TEST_CASES: ${{ matrix.FAST_LINT_TEST_CASES }}
  166. run: vendor/bin/paraunit run --testsuite unit,integration
  167. - name: Run tests with "short_open_tag" enabled
  168. if: matrix.run-tests == 'yes' && matrix.collect-code-coverage != 'yes'
  169. env:
  170. PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
  171. FAST_LINT_TEST_CASES: ${{ matrix.FAST_LINT_TEST_CASES }}
  172. run: composer test:short-open-tag
  173. - name: Run tests and collect code coverage
  174. if: matrix.run-tests == 'yes' && matrix.collect-code-coverage == 'yes'
  175. env:
  176. FAST_LINT_TEST_CASES: 1
  177. run: vendor/bin/paraunit coverage --testsuite unit --pass-through=--exclude-group=covers-nothing --clover=build/logs/clover.xml
  178. - name: Run mutation tests (Infection)
  179. # Run only on pull requests because we run mutations tests only for diff between branches
  180. if: github.event_name == 'pull_request' && matrix.run-mutation-tests == 'yes'
  181. env:
  182. FAST_LINT_TEST_CASES: 1
  183. run: |
  184. git fetch origin $GITHUB_BASE_REF
  185. vendor/bin/infection --threads=max --map-source-class-to-test --git-diff-lines --git-diff-base=origin/$GITHUB_BASE_REF --ignore-msi-with-no-mutations --only-covered
  186. - name: Upload coverage results to Coveralls
  187. if: matrix.run-tests == 'yes' && matrix.collect-code-coverage == 'yes'
  188. env:
  189. COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  190. run: php vendor/bin/php-coveralls --verbose
  191. - name: Run PHP CS Fixer
  192. if: matrix.run-fixer == 'yes'
  193. env:
  194. PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
  195. PHP_CS_FIXER_FUTURE_MODE: 1
  196. run: php php-cs-fixer check --diff -v
  197. # Should be checked on the lowest supported PHP version.
  198. # If any type can be converted from PHPDoc to native type on lowest supported PHP, we should commit such change.
  199. - name: Run PHP CS Fixer with PHPDoc to type rules
  200. if: env.PHP_MIN == matrix.php-version && matrix.run-fixer == 'yes'
  201. env:
  202. PHP_CS_FIXER_FUTURE_MODE: 1
  203. run: php php-cs-fixer check --diff -vvv --config .php-cs-fixer.php-lowest.php
  204. deployment:
  205. needs: tests
  206. name: Deployment checks
  207. runs-on: 'ubuntu-24.04'
  208. env:
  209. php-version: '8.3'
  210. steps:
  211. - name: Checkout code
  212. uses: actions/checkout@v4
  213. - name: Setup PHP with Composer deps
  214. uses: ./.github/composite-actions/setup-php-with-composer-deps
  215. with:
  216. os: ${{ runner.os }}
  217. php: ${{ env.php-version }}
  218. - name: Cache dev-tools
  219. uses: actions/cache@v4
  220. with:
  221. path: dev-tools/bin/
  222. key: Build-${{ hashFiles('dev-tools/build.sh') }}
  223. - name: Build phar
  224. run: ./dev-tools/build.sh
  225. - name: Run smoke tests
  226. env:
  227. FAST_LINT_TEST_CASES: 1
  228. run: vendor/bin/phpunit --testsuite smoke