Skip to content

Commit f2e9d27

Browse files
committed
Refactor test-phpunit.yml
1 parent 7662e5f commit f2e9d27

File tree

1 file changed

+137
-205
lines changed

1 file changed

+137
-205
lines changed

.github/workflows/test-phpunit.yml

Lines changed: 137 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -31,221 +31,153 @@ concurrency:
3131
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
3232
cancel-in-progress: true
3333

34-
env:
35-
COVERAGE_PHP_VERSION: '8.1'
36-
NLS_LANG: 'AMERICAN_AMERICA.UTF8'
37-
NLS_DATE_FORMAT: 'YYYY-MM-DD HH24:MI:SS'
38-
NLS_TIMESTAMP_FORMAT: 'YYYY-MM-DD HH24:MI:SS'
39-
NLS_TIMESTAMP_TZ_FORMAT: 'YYYY-MM-DD HH24:MI:SS'
40-
4134
jobs:
42-
tests:
43-
name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
35+
# Any environment variables set in an env context defined at the workflow level
36+
# in the caller workflow are not propagated to the called workflow.
37+
coverage-php-version:
38+
name: Setup PHP Version for Code Coverage
4439
runs-on: ubuntu-22.04
45-
if: "!contains(github.event.head_commit.message, '[ci skip]')"
40+
outputs:
41+
version: ${{ steps.coverage-php-version.outputs.version }}
42+
steps:
43+
- id: coverage-php-version
44+
run: |
45+
echo "version=8.1" >> $GITHUB_OUTPUT
46+
47+
sanity-tests:
48+
needs: coverage-php-version
49+
50+
strategy:
51+
matrix:
52+
php-version:
53+
- '7.4'
54+
- '8.0'
55+
- '8.1'
56+
- '8.2'
57+
include:
58+
- php-version: '8.2'
59+
composer-option: '--ignore-platform-req=php'
60+
61+
uses: ./.github/workflows/reusable-phpunit-test.yml # @TODO Extract to codeigniter4/.github repo
62+
with:
63+
job-name: Sanity Tests
64+
php-version: ${{ matrix.php-version }}
65+
job-id: sanity-tests
66+
group-name: Others
67+
enable-artifact-upload: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
68+
enable-coverage: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
69+
enable-profiling: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
70+
extra-extensions: imagick, redis, memcached
71+
extra-composer-options: ${{ matrix.composer-option }}
72+
73+
database-live-tests:
74+
needs:
75+
- coverage-php-version
76+
- sanity-tests
4677

4778
strategy:
4879
fail-fast: false
4980
matrix:
50-
php-versions: ['7.4', '8.0', '8.1', '8.2']
51-
db-platforms: ['MySQLi', 'Postgre', 'SQLite3', 'SQLSRV', 'OCI8']
52-
mysql-versions: ['5.7']
81+
php-version:
82+
- '7.4'
83+
- '8.0'
84+
- '8.1'
85+
- '8.2'
86+
db-platform:
87+
- MySQLi
88+
- OCI8
89+
- Postgre
90+
- SQLSRV
91+
- SQLite3
92+
mysql-version:
93+
- '5.7'
5394
include:
54-
- php-versions: '7.4'
55-
db-platforms: MySQLi
56-
mysql-versions: '8.0'
57-
- php-versions: '8.2'
95+
- php-version: '7.4'
96+
db-platform: MySQLi
97+
mysql-version: '8.0'
98+
- php-version: '8.2'
5899
composer-option: '--ignore-platform-req=php'
59100

60-
services:
61-
mysql:
62-
image: mysql:${{ matrix.mysql-versions }}
63-
env:
64-
MYSQL_ALLOW_EMPTY_PASSWORD: yes
65-
MYSQL_DATABASE: test
66-
ports:
67-
- 3306:3306
68-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
69-
70-
postgres:
71-
image: postgres
72-
env:
73-
POSTGRES_USER: postgres
74-
POSTGRES_PASSWORD: postgres
75-
POSTGRES_DB: test
76-
ports:
77-
- 5432:5432
78-
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
79-
80-
mssql:
81-
image: mcr.microsoft.com/mssql/server:2022-latest
82-
env:
83-
SA_PASSWORD: 1Secure*Password1
84-
ACCEPT_EULA: Y
85-
MSSQL_PID: Developer
86-
ports:
87-
- 1433:1433
88-
options: --health-cmd="/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q 'SELECT @@VERSION'" --health-interval=10s --health-timeout=5s --health-retries=3
89-
90-
oracle:
91-
image: gvenzl/oracle-xe:21
92-
env:
93-
ORACLE_RANDOM_PASSWORD: true
94-
APP_USER: ORACLE
95-
APP_USER_PASSWORD: ORACLE
96-
ports:
97-
- 1521:1521
98-
options: >-
99-
--health-cmd healthcheck.sh
100-
--health-interval 20s
101-
--health-timeout 10s
102-
--health-retries 10
103-
104-
redis:
105-
image: redis
106-
ports:
107-
- 6379:6379
108-
options: --health-cmd "redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
109-
110-
memcached:
111-
image: memcached:1.6-alpine
112-
ports:
113-
- 11211:11211
101+
uses: ./.github/workflows/reusable-phpunit-test.yml # @TODO Extract to codeigniter4/.github repo
102+
with:
103+
job-name: Database Live Tests
104+
php-version: ${{ matrix.php-version }}
105+
job-id: database-live-tests
106+
db-platform: ${{ matrix.db-platform }}
107+
mysql-version: ${{ matrix.mysql-version }}
108+
group-name: DatabaseLive
109+
enable-artifact-upload: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
110+
enable-coverage: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
111+
enable-profiling: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
112+
extra-extensions: mysqli, oci8, pgsql, sqlsrv-5.10.1, sqlite3
113+
extra-composer-options: ${{ matrix.composer-option }}
114+
115+
separate-process-tests:
116+
needs:
117+
- coverage-php-version
118+
- sanity-tests
114119

115-
steps:
116-
- name: Create database for MSSQL Server
117-
if: matrix.db-platforms == 'SQLSRV'
118-
run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test"
119-
120-
- name: Checkout
121-
uses: actions/checkout@v3
122-
123-
- name: Setup PHP, with composer and extensions
124-
uses: shivammathur/setup-php@v2
125-
with:
126-
php-version: ${{ matrix.php-versions }}
127-
tools: composer, pecl
128-
extensions: imagick, sqlsrv-5.10.1, gd, sqlite3, redis, memcached, oci8, pgsql
129-
coverage: ${{ env.COVERAGE_DRIVER }}
130-
env:
131-
update: true
132-
COVERAGE_DRIVER: ${{ matrix.php-versions == env.COVERAGE_PHP_VERSION && 'xdebug' || 'none'}}
133-
134-
- name: Install latest ImageMagick
135-
run: |
136-
sudo apt-get update
137-
sudo apt-get install --reinstall libgs9-common fonts-noto-mono libgs9:amd64 libijs-0.35:amd64 fonts-urw-base35 ghostscript poppler-data libjbig2dec0:amd64 gsfonts libopenjp2-7:amd64 fonts-droid-fallback fonts-dejavu-core
138-
sudo apt-get install -y imagemagick
139-
sudo apt-get install --fix-broken
140-
141-
- name: Get composer cache directory
142-
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV
143-
144-
- name: Cache dependencies
145-
uses: actions/cache@v3
146-
with:
147-
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
148-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
149-
restore-keys: ${{ runner.os }}-composer-
150-
151-
- name: Install dependencies
152-
run: |
153-
composer update --ansi --no-interaction ${{ matrix.composer-option }}
154-
composer remove --ansi --dev --unused ${{ matrix.composer-option }} -W -- rector/rector phpstan/phpstan friendsofphp/php-cs-fixer nexusphp/cs-config codeigniter/coding-standard
155-
156-
- name: Profile slow tests in PHP ${{ env.COVERAGE_PHP_VERSION }}
157-
if: matrix.php-versions == env.COVERAGE_PHP_VERSION
158-
run: echo "TACHYCARDIA_MONITOR_GA=enabled" >> $GITHUB_ENV
159-
160-
- name: Cache PHPUnit's static analysis cache
161-
uses: actions/cache@v3
162-
with:
163-
path: build/.phpunit.cache/code-coverage
164-
key: phpunit-code-coverage-${{ hashFiles('**/phpunit.*') }}
165-
restore-keys: |
166-
phpunit-code-coverage-
167-
168-
- name: Compute coverage option
169-
uses: actions/github-script@v6
170-
id: phpunit-coverage-option
171-
with:
172-
script: |
173-
const { COVERAGE_NAME } = process.env
174-
175-
return "${{ matrix.php-versions }}" == "${{ env.COVERAGE_PHP_VERSION }}" ? `--coverage-php build/cov/coverage-${COVERAGE_NAME}.cov` : "--no-coverage"
176-
result-encoding: string
177-
env:
178-
COVERAGE_NAME: php-v${{ env.COVERAGE_PHP_VERSION }}-${{ matrix.db-platforms }}
179-
180-
- name: Test with PHPUnit
181-
run: script -e -c "vendor/bin/phpunit --color=always --exclude-group=AutoReview ${{ steps.phpunit-coverage-option.outputs.result }}"
182-
env:
183-
DB: ${{ matrix.db-platforms }}
184-
TERM: xterm-256color
185-
186-
- name: Upload coverage file
187-
if: matrix.php-versions == env.COVERAGE_PHP_VERSION
188-
uses: actions/upload-artifact@v3
189-
with:
190-
name: ${{ env.COVERAGE_NAME }}
191-
path: build/cov/coverage-${{ env.COVERAGE_NAME }}.cov
192-
if-no-files-found: error
193-
retention-days: 1
194-
env:
195-
COVERAGE_NAME: php-v${{ env.COVERAGE_PHP_VERSION }}-${{ matrix.db-platforms }}
120+
strategy:
121+
matrix:
122+
php-version:
123+
- '7.4'
124+
- '8.0'
125+
- '8.1'
126+
- '8.2'
127+
include:
128+
- php-version: '8.2'
129+
composer-option: '--ignore-platform-req=php'
130+
131+
uses: ./.github/workflows/reusable-phpunit-test.yml # @TODO Extract to codeigniter4/.github repo
132+
with:
133+
job-name: Separate Process Tests
134+
php-version: ${{ matrix.php-version }}
135+
job-id: separate-process-tests
136+
group-name: SeparateProcess
137+
enable-artifact-upload: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
138+
enable-coverage: true # needs xdebug for assertHeaderEmitted() tests
139+
enable-profiling: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
140+
extra-extensions: mysqli, oci8, pgsql, sqlsrv-5.10.1, sqlite3
141+
extra-composer-options: ${{ matrix.composer-option }}
142+
143+
cache-live-tests:
144+
needs:
145+
- coverage-php-version
146+
- sanity-tests
147+
148+
strategy:
149+
matrix:
150+
php-version:
151+
- '7.4'
152+
- '8.0'
153+
- '8.1'
154+
- '8.2'
155+
include:
156+
- php-version: '8.2'
157+
composer-option: '--ignore-platform-req=php'
158+
159+
uses: ./.github/workflows/reusable-phpunit-test.yml # @TODO Extract to codeigniter4/.github repo
160+
with:
161+
job-name: Cache Live Tests
162+
php-version: ${{ matrix.php-version }}
163+
job-id: cache-live-tests
164+
group-name: CacheLive
165+
enable-artifact-upload: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
166+
enable-coverage: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
167+
enable-profiling: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
168+
extra-extensions: redis, memcached
169+
extra-composer-options: ${{ matrix.composer-option }}
196170

197171
coveralls:
172+
name: Upload coverage results to Coveralls
198173
if: github.repository_owner == 'codeigniter4'
199-
needs: tests
200-
runs-on: ubuntu-22.04
201-
202-
steps:
203-
- name: Checkout
204-
uses: actions/checkout@v3
205-
206-
- name: Setup PHP, with composer and extensions
207-
uses: shivammathur/setup-php@v2
208-
with:
209-
php-version: ${{ env.COVERAGE_PHP_VERSION }}
210-
tools: composer
211-
coverage: xdebug
212-
env:
213-
update: true
214-
215-
- name: Download coverage files
216-
uses: actions/download-artifact@v3
217-
with:
218-
path: build/cov
219-
220-
- name: Display structure of downloaded files
221-
run: ls -R
222-
working-directory: build/cov
223-
224-
- name: Get composer cache directory
225-
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV
226-
227-
- name: Cache dependencies
228-
uses: actions/cache@v3
229-
with:
230-
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
231-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
232-
restore-keys: ${{ runner.os }}-composer-
233-
234-
- name: Install dependencies
235-
run: composer update --ansi --no-interaction
236-
237-
- name: Cache PHPUnit's static analysis cache
238-
uses: actions/cache@v3
239-
with:
240-
path: build/.phpunit.cache/code-coverage
241-
key: phpunit-code-coverage-${{ hashFiles('**/phpunit.*') }}
242-
restore-keys: |
243-
phpunit-code-coverage-
244-
245-
- name: Merge coverage files
246-
run: vendor/bin/phpcov merge --clover build/logs/clover.xml build/cov
247-
248-
- name: Upload coverage to Coveralls
249-
run: vendor/bin/php-coveralls --verbose --exclude-no-stmt --ansi
250-
env:
251-
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
174+
needs:
175+
- coverage-php-version
176+
- sanity-tests
177+
- cache-live-tests
178+
- database-live-tests
179+
- separate-process-tests
180+
181+
uses: ./.github/workflows/reusable-coveralls.yml # @TODO Extract to codeigniter4/.github repo
182+
with:
183+
php-version: ${{ needs.coverage-php-version.outputs.version }}

0 commit comments

Comments
 (0)