ci.yml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. name: CI
  2. on:
  3. push:
  4. branches:
  5. - '4.x'
  6. - '4.next'
  7. - '5.x'
  8. pull_request:
  9. branches:
  10. - '*'
  11. schedule:
  12. - cron: "0 0 * * *"
  13. workflow_dispatch:
  14. permissions:
  15. contents: read # to fetch code (actions/checkout)
  16. jobs:
  17. testsuite:
  18. runs-on: ubuntu-22.04
  19. strategy:
  20. fail-fast: false
  21. matrix:
  22. php-version: ['7.4', '8.0']
  23. db-type: [sqlite, pgsql]
  24. prefer-lowest: ['']
  25. exclude:
  26. - php-version: '7.4'
  27. db-type: 'mysql'
  28. include:
  29. - php-version: '7.4'
  30. db-type: 'mariadb'
  31. - php-version: '7.4'
  32. db-type: 'mysql'
  33. prefer-lowest: 'prefer-lowest'
  34. - php-version: '8.1'
  35. db-type: 'mysql'
  36. - php-version: '8.2'
  37. db-type: 'mysql'
  38. - php-version: '8.3'
  39. db-type: 'mysql'
  40. services:
  41. redis:
  42. image: redis
  43. ports:
  44. - 6379/tcp
  45. memcached:
  46. image: memcached
  47. ports:
  48. - 11211/tcp
  49. steps:
  50. - name: Setup MySQL latest
  51. if: matrix.db-type == 'mysql' && matrix.php-version == '7.4'
  52. run: |
  53. sudo service mysql start
  54. mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp;'
  55. - name: Setup MySQL 5.6
  56. if: matrix.db-type == 'mysql' && matrix.php-version != '7.4'
  57. run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql:5.6 --character-set-server=utf8
  58. - name: Setup PostgreSQL latest
  59. if: matrix.db-type == 'pgsql' && matrix.php-version == '7.4'
  60. run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres
  61. - name: Setup PostgreSQL 9.4
  62. if: matrix.db-type == 'pgsql' && matrix.php-version != '7.4'
  63. run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres:9.4
  64. - uses: getong/mariadb-action@v1.1
  65. if: matrix.db-type == 'mariadb'
  66. with:
  67. mysql database: 'cakephp'
  68. mysql root password: 'root'
  69. - uses: actions/checkout@v4
  70. - name: Setup PHP
  71. uses: shivammathur/setup-php@v2
  72. with:
  73. php-version: ${{ matrix.php-version }}
  74. extensions: mbstring, intl, apcu, memcached, redis, pdo_${{ matrix.db-type }}
  75. ini-values: apc.enable_cli = 1
  76. coverage: pcov
  77. - name: Get composer cache directory
  78. id: composer-cache
  79. run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
  80. - name: Get date part for cache key
  81. id: key-date
  82. run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
  83. - name: Cache composer dependencies
  84. uses: actions/cache@v4
  85. with:
  86. path: ${{ steps.composer-cache.outputs.dir }}
  87. key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
  88. - name: Install packages
  89. run: |
  90. sudo locale-gen da_DK.UTF-8
  91. sudo locale-gen de_DE.UTF-8
  92. - name: Composer install
  93. run: |
  94. if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
  95. composer update --prefer-lowest --prefer-stable
  96. else
  97. composer update
  98. fi
  99. - name: Setup problem matchers for PHPUnit
  100. if: matrix.php-version == '7.4' && matrix.db-type == 'mysql'
  101. run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
  102. - name: Wait for MySQL
  103. if: matrix.db-type == 'mysql' || matrix.db-type == 'mariadb'
  104. run: while ! `mysqladmin ping -h 127.0.0.1 --silent`; do printf 'Waiting for MySQL...\n'; sleep 2; done;
  105. - name: Run PHPUnit
  106. env:
  107. REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
  108. MEMCACHED_PORT: ${{ job.services.memcached.ports['11211'] }}
  109. run: |
  110. if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
  111. if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} == '7.4' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp'; fi
  112. if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} != '7.4' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
  113. if [[ ${{ matrix.db-type }} == 'mariadb' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp'; fi
  114. if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
  115. if [[ ${{ matrix.php-version }} == '8.0' ]]; then
  116. export CODECOVERAGE=1
  117. vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
  118. CAKE_TEST_AUTOQUOTE=1 vendor/bin/phpunit --verbose --testsuite=database
  119. vendor/bin/phpunit --verbose --testsuite=globalfunctions --coverage-clover=coverage-functions.xml
  120. else
  121. vendor/bin/phpunit
  122. CAKE_TEST_AUTOQUOTE=1 vendor/bin/phpunit --testsuite=database
  123. fi
  124. - name: Prefer lowest check
  125. if: matrix.prefer-lowest == 'prefer-lowest'
  126. run: composer require --dev dereuromark/composer-prefer-lowest && vendor/bin/validate-prefer-lowest -m
  127. - name: Submit code coverage
  128. if: matrix.php-version == '8.0'
  129. uses: codecov/codecov-action@v3
  130. with:
  131. files: coverage.xml,coverage-functions.xml
  132. testsuite-windows:
  133. runs-on: windows-2022
  134. name: Windows - PHP 8.0 & SQL Server
  135. env:
  136. EXTENSIONS: mbstring, intl, apcu, redis, wincache, pdo_sqlsrv
  137. PHP_VERSION: '8.0'
  138. steps:
  139. - uses: actions/checkout@v4
  140. - name: Get date part for cache key
  141. id: key-date
  142. run: echo "date=$(date +'%Y-%m')" >> $env:GITHUB_OUTPUT
  143. - name: Setup PHP extensions cache
  144. id: php-ext-cache
  145. uses: shivammathur/cache-extensions@v1
  146. with:
  147. php-version: ${{ env.PHP_VERSION }}
  148. extensions: ${{ env.EXTENSIONS }}
  149. key: ${{ steps.key-date.outputs.date }}
  150. - name: Cache PHP extensions
  151. uses: actions/cache@v4
  152. with:
  153. path: ${{ steps.php-ext-cache.outputs.dir }}
  154. key: ${{ runner.os }}-php-ext-${{ steps.php-ext-cache.outputs.key }}
  155. restore-keys: ${{ runner.os }}-php-ext-${{ steps.php-ext-cache.outputs.key }}
  156. - name: Setup PHP
  157. uses: shivammathur/setup-php@v2
  158. with:
  159. php-version: ${{ env.PHP_VERSION }}
  160. extensions: ${{ env.EXTENSIONS }}
  161. ini-values: apc.enable_cli = 1, extension = php_fileinfo.dll
  162. coverage: none
  163. - name: Setup SQLServer
  164. run: |
  165. # MSSQLLocalDB is the default SQL LocalDB instance
  166. SqlLocalDB start MSSQLLocalDB
  167. SqlLocalDB info MSSQLLocalDB
  168. sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "create database cakephp;"
  169. - name: Get composer cache directory
  170. id: composer-cache
  171. run: echo "dir=$(composer config cache-files-dir)" >> $env:GITHUB_OUTPUT
  172. - name: Cache composer dependencies
  173. uses: actions/cache@v4
  174. with:
  175. path: ${{ steps.composer-cache.outputs.dir }}
  176. key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
  177. - name: Composer install
  178. run: composer update
  179. - name: Run PHPUnit
  180. env:
  181. DB_URL: 'sqlserver://@(localdb)\MSSQLLocalDB/cakephp'
  182. run: |
  183. set CAKE_DISABLE_GLOBAL_FUNCS=1
  184. vendor/bin/phpunit --verbose
  185. - name: Run PHPUnit (autoquote enabled)
  186. env:
  187. DB_URL: 'sqlserver://@(localdb)\MSSQLLocalDB/cakephp'
  188. run: |
  189. set CAKE_TEST_AUTOQUOTE=1
  190. vendor/bin/phpunit --verbose --testsuite=database
  191. cs-stan:
  192. name: Coding Standard & Static Analysis
  193. runs-on: ubuntu-22.04
  194. steps:
  195. - uses: actions/checkout@v4
  196. - name: Setup PHP
  197. uses: shivammathur/setup-php@v2
  198. with:
  199. php-version: '7.4'
  200. extensions: mbstring, intl, apcu, memcached, redis
  201. coverage: none
  202. tools: phive, cs2pr
  203. env:
  204. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  205. - name: Get composer cache directory
  206. id: composer-cache
  207. run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
  208. - name: Get date part for cache key
  209. id: key-date
  210. run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
  211. - name: Cache composer dependencies
  212. uses: actions/cache@v4
  213. with:
  214. path: ${{ steps.composer-cache.outputs.dir }}
  215. key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
  216. - name: Composer install
  217. run: composer update
  218. - name: Install PHP tools with phive.
  219. run: phive install --trust-gpg-keys 'CF1A108D0E7AE720,51C67305FFC2E5C0,12CE0F1D262429A5'
  220. - name: Run phpcs
  221. if: always()
  222. run: vendor/bin/phpcs --report=checkstyle src/ tests/ | cs2pr
  223. - name: Run psalm
  224. if: always()
  225. run: tools/psalm --output-format=github
  226. - name: Run phpstan
  227. if: always()
  228. run: tools/phpstan analyse --error-format=github
  229. - name: Run phpstan for tests
  230. if: always()
  231. run: tools/phpstan analyse -c tests/phpstan.neon --error-format=github
  232. - name: Run class deprecation aliasing validaton script
  233. if: always()
  234. run: php contrib/validate-deprecation-aliases.php