ci.yml 11 KB

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