Skip to content

Commit fec0d21

Browse files
committed
Add CI workflow for testing
1 parent 7844010 commit fec0d21

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

.github/workflows/ci.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
6+
pull_request:
7+
branches:
8+
- '*'
9+
10+
jobs:
11+
testsuite:
12+
runs-on: ubuntu-22.04
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3']
17+
db-type: [sqlite, mysql, pgsql]
18+
prefer-lowest: ['']
19+
20+
steps:
21+
- name: Setup MySQL latest
22+
if: matrix.db-type == 'mysql'
23+
run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql --default-authentication-plugin=mysql_native_password --disable-log-bin
24+
25+
- name: Setup PostgreSQL latest
26+
if: matrix.db-type == 'pgsql'
27+
run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres
28+
29+
- uses: actions/checkout@v2
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ matrix.php-version }}
35+
extensions: mbstring, intl, apcu, sqlite, pdo_sqlite, pdo_${{ matrix.db-type }}, ${{ matrix.db-type }}
36+
ini-values: apc.enable_cli = 1
37+
coverage: pcov
38+
39+
- name: Get composer cache directory
40+
id: composer-cache
41+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
42+
43+
- name: Get date part for cache key
44+
id: key-date
45+
run: echo "::set-output name=date::$(date +'%Y-%m')"
46+
47+
- name: Cache composer dependencies
48+
uses: actions/cache@v1
49+
with:
50+
path: ${{ steps.composer-cache.outputs.dir }}
51+
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
52+
53+
- name: composer install
54+
run: |
55+
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
56+
composer update --prefer-lowest --prefer-stable
57+
else
58+
composer update
59+
fi
60+
61+
- name: Setup problem matchers for PHPUnit
62+
if: matrix.php-version == '8.1' && matrix.db-type == 'mysql'
63+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
64+
65+
- name: Run PHPUnit
66+
run: |
67+
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
68+
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp?encoding=utf8'; fi
69+
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
70+
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
71+
export CODECOVERAGE=1 && vendor/bin/phpunit --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
72+
else
73+
vendor/bin/phpunit
74+
fi
75+
76+
- name: Submit code coverage
77+
if: matrix.php-version == '8.1'
78+
uses: codecov/codecov-action@v1
79+
80+
cs-stan:
81+
name: Coding Standard & Static Analysis
82+
runs-on: ubuntu-22.04
83+
84+
steps:
85+
- uses: actions/checkout@v2
86+
87+
- name: Setup PHP
88+
uses: shivammathur/setup-php@v2
89+
with:
90+
php-version: '8.1'
91+
extensions: mbstring, intl, apcu
92+
coverage: none
93+
94+
- name: Get composer cache directory
95+
id: composer-cache
96+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
97+
98+
- name: Get date part for cache key
99+
id: key-date
100+
run: echo "::set-output name=date::$(date +'%Y-%m')"
101+
102+
- name: Cache composer dependencies
103+
uses: actions/cache@v1
104+
with:
105+
path: ${{ steps.composer-cache.outputs.dir }}
106+
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
107+
108+
- name: composer install
109+
run: composer stan-setup
110+
111+
- name: Run PHP CodeSniffer
112+
run: composer cs-check
113+
continue-on-error: true
114+
115+
- name: Run psalm
116+
if: success() || failure()
117+
run: vendor/bin/psalm.phar --output-format=github
118+
continue-on-error: true
119+
120+
- name: Run phpstan
121+
if: success() || failure()
122+
run: composer stan
123+
continue-on-error: true

0 commit comments

Comments
 (0)