Skip to content

Commit fd4a323

Browse files
miaulalalaclaude
andcommitted
Add PHPUnit CI workflows for SQLite, MySQL, MariaDB, PostgreSQL
Each workflow uses the nextcloud-version-matrix action to test against all supported NC/PHP version combinations, runs both unit and integration test suites via composer scripts, and includes a path-filter to skip unchanged code. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 53e2046 commit fd4a323

4 files changed

Lines changed: 739 additions & 0 deletions

File tree

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# This workflow is provided via the organization template repository
2+
#
3+
# https://github.com/nextcloud/.github
4+
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5+
#
6+
# SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
7+
# SPDX-License-Identifier: MIT
8+
9+
name: PHPUnit MariaDB
10+
11+
on: pull_request
12+
13+
permissions:
14+
contents: read
15+
16+
concurrency:
17+
group: phpunit-mariadb-${{ github.head_ref || github.run_id }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
matrix:
22+
runs-on: ubuntu-latest-low
23+
outputs:
24+
php-version: ${{ steps.versions.outputs.php-available-list }}
25+
server-max: ${{ steps.versions.outputs.branches-max-list }}
26+
steps:
27+
- name: Checkout app
28+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
with:
30+
persist-credentials: false
31+
32+
- name: Get version matrix
33+
id: versions
34+
uses: icewind1991/nextcloud-version-matrix@8a7bac6300b2f0f3100088b297995a229558ddba # v1.3.2
35+
36+
changes:
37+
runs-on: ubuntu-latest-low
38+
permissions:
39+
contents: read
40+
pull-requests: read
41+
42+
outputs:
43+
src: ${{ steps.changes.outputs.src}}
44+
45+
steps:
46+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
47+
id: changes
48+
continue-on-error: true
49+
with:
50+
filters: |
51+
src:
52+
- '.github/workflows/**'
53+
- 'appinfo/**'
54+
- 'lib/**'
55+
- 'tests/**'
56+
- 'vendor-bin/**'
57+
- 'composer.json'
58+
- 'composer.lock'
59+
60+
phpunit-mariadb:
61+
runs-on: ubuntu-latest
62+
63+
needs: [changes, matrix]
64+
if: needs.changes.outputs.src != 'false'
65+
66+
strategy:
67+
matrix:
68+
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
69+
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
70+
mariadb-versions: ['10.6', '11.4']
71+
72+
name: MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
73+
74+
services:
75+
mariadb:
76+
image: ghcr.io/nextcloud/continuous-integration-mariadb-${{ matrix.mariadb-versions }}:latest # zizmor: ignore[unpinned-images]
77+
ports:
78+
- 4444:3306/tcp
79+
env:
80+
MARIADB_ROOT_PASSWORD: rootpassword
81+
options: --health-cmd="mariadb-admin ping" --health-interval 5s --health-timeout 2s --health-retries 5
82+
83+
steps:
84+
- name: Set app env
85+
if: ${{ env.APP_NAME == '' }}
86+
run: |
87+
# Split and keep last
88+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
89+
90+
- name: Checkout server
91+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
92+
with:
93+
persist-credentials: false
94+
submodules: true
95+
repository: nextcloud/server
96+
ref: ${{ matrix.server-versions }}
97+
98+
- name: Checkout app
99+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
100+
with:
101+
persist-credentials: false
102+
path: apps/${{ env.APP_NAME }}
103+
104+
- name: Set up php ${{ matrix.php-versions }}
105+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
106+
with:
107+
php-version: ${{ matrix.php-versions }}
108+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql
109+
coverage: none
110+
ini-file: development
111+
ini-values: disable_functions=
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
115+
- name: Enable ONLY_FULL_GROUP_BY MariaDB option
116+
run: |
117+
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
118+
echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
119+
120+
- name: Check composer file existence
121+
id: check_composer
122+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
123+
with:
124+
files: apps/${{ env.APP_NAME }}/composer.json
125+
126+
- name: Set up dependencies
127+
if: steps.check_composer.outputs.files_exists == 'true'
128+
working-directory: apps/${{ env.APP_NAME }}
129+
run: composer install
130+
131+
- name: Set up Nextcloud
132+
env:
133+
DB_PORT: 4444
134+
run: |
135+
mkdir data
136+
./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
137+
./occ app:enable --force ${{ env.APP_NAME }}
138+
139+
- name: Check PHPUnit script is defined
140+
id: check_phpunit
141+
continue-on-error: true
142+
working-directory: apps/${{ env.APP_NAME }}
143+
run: |
144+
composer run --list | grep '^ test:unit ' | wc -l | grep 1
145+
146+
- name: PHPUnit
147+
if: steps.check_phpunit.outcome == 'success'
148+
working-directory: apps/${{ env.APP_NAME }}
149+
run: composer run test:unit
150+
151+
- name: Check PHPUnit integration script is defined
152+
id: check_integration
153+
continue-on-error: true
154+
working-directory: apps/${{ env.APP_NAME }}
155+
run: |
156+
composer run --list | grep '^ test:integration ' | wc -l | grep 1
157+
158+
- name: Run Nextcloud
159+
if: steps.check_integration.outcome == 'success'
160+
run: php -S localhost:8080 &
161+
162+
- name: PHPUnit integration
163+
if: steps.check_integration.outcome == 'success'
164+
working-directory: apps/${{ env.APP_NAME }}
165+
run: composer run test:integration
166+
167+
- name: Print logs
168+
if: always()
169+
run: |
170+
cat data/nextcloud.log
171+
172+
- name: Skipped
173+
if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure'
174+
run: |
175+
echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts'
176+
exit 1
177+
178+
summary:
179+
permissions:
180+
contents: none
181+
runs-on: ubuntu-latest-low
182+
needs: [changes, phpunit-mariadb]
183+
184+
if: always()
185+
186+
name: phpunit-mariadb-summary
187+
188+
steps:
189+
- name: Summary status
190+
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-mariadb.result != 'success' }}; then exit 1; fi
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# This workflow is provided via the organization template repository
2+
#
3+
# https://github.com/nextcloud/.github
4+
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
5+
#
6+
# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
7+
# SPDX-License-Identifier: MIT
8+
9+
name: PHPUnit MySQL
10+
11+
on: pull_request
12+
13+
permissions:
14+
contents: read
15+
16+
concurrency:
17+
group: phpunit-mysql-${{ github.head_ref || github.run_id }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
matrix:
22+
runs-on: ubuntu-latest-low
23+
outputs:
24+
matrix: ${{ steps.versions.outputs.sparse-matrix }}
25+
steps:
26+
- name: Checkout app
27+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28+
with:
29+
persist-credentials: false
30+
31+
- name: Get version matrix
32+
id: versions
33+
uses: icewind1991/nextcloud-version-matrix@8a7bac6300b2f0f3100088b297995a229558ddba # v1.3.2
34+
with:
35+
matrix: '{"mysql-versions": ["8.4"]}'
36+
37+
changes:
38+
runs-on: ubuntu-latest-low
39+
permissions:
40+
contents: read
41+
pull-requests: read
42+
43+
outputs:
44+
src: ${{ steps.changes.outputs.src}}
45+
46+
steps:
47+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
48+
id: changes
49+
continue-on-error: true
50+
with:
51+
filters: |
52+
src:
53+
- '.github/workflows/**'
54+
- 'appinfo/**'
55+
- 'lib/**'
56+
- 'tests/**'
57+
- 'vendor-bin/**'
58+
- 'composer.json'
59+
- 'composer.lock'
60+
61+
phpunit-mysql:
62+
runs-on: ubuntu-latest
63+
64+
needs: [changes, matrix]
65+
if: needs.changes.outputs.src != 'false'
66+
67+
strategy:
68+
matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
69+
70+
name: MySQL ${{ matrix.mysql-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
71+
72+
services:
73+
mysql:
74+
image: ghcr.io/nextcloud/continuous-integration-mysql-${{ matrix.mysql-versions }}:latest # zizmor: ignore[unpinned-images]
75+
ports:
76+
- 4444:3306/tcp
77+
env:
78+
MYSQL_ROOT_PASSWORD: rootpassword
79+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10
80+
81+
steps:
82+
- name: Set app env
83+
if: ${{ env.APP_NAME == '' }}
84+
run: |
85+
# Split and keep last
86+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
87+
88+
- name: Checkout server
89+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
90+
with:
91+
persist-credentials: false
92+
submodules: true
93+
repository: nextcloud/server
94+
ref: ${{ matrix.server-versions }}
95+
96+
- name: Checkout app
97+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
98+
with:
99+
persist-credentials: false
100+
path: apps/${{ env.APP_NAME }}
101+
102+
- name: Set up php ${{ matrix.php-versions }}
103+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
104+
with:
105+
php-version: ${{ matrix.php-versions }}
106+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql
107+
coverage: none
108+
ini-file: development
109+
ini-values: disable_functions=
110+
env:
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
113+
- name: Enable ONLY_FULL_GROUP_BY MySQL option
114+
run: |
115+
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
116+
echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
117+
118+
- name: Check composer file existence
119+
id: check_composer
120+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
121+
with:
122+
files: apps/${{ env.APP_NAME }}/composer.json
123+
124+
- name: Set up dependencies
125+
if: steps.check_composer.outputs.files_exists == 'true'
126+
working-directory: apps/${{ env.APP_NAME }}
127+
run: composer install
128+
129+
- name: Set up Nextcloud
130+
env:
131+
DB_PORT: 4444
132+
run: |
133+
mkdir data
134+
./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
135+
./occ app:enable --force ${{ env.APP_NAME }}
136+
137+
- name: Check PHPUnit script is defined
138+
id: check_phpunit
139+
continue-on-error: true
140+
working-directory: apps/${{ env.APP_NAME }}
141+
run: |
142+
composer run --list | grep '^ test:unit ' | wc -l | grep 1
143+
144+
- name: PHPUnit
145+
if: steps.check_phpunit.outcome == 'success'
146+
working-directory: apps/${{ env.APP_NAME }}
147+
run: composer run test:unit
148+
149+
- name: Check PHPUnit integration script is defined
150+
id: check_integration
151+
continue-on-error: true
152+
working-directory: apps/${{ env.APP_NAME }}
153+
run: |
154+
composer run --list | grep '^ test:integration ' | wc -l | grep 1
155+
156+
- name: Run Nextcloud
157+
if: steps.check_integration.outcome == 'success'
158+
run: php -S localhost:8080 &
159+
160+
- name: PHPUnit integration
161+
if: steps.check_integration.outcome == 'success'
162+
working-directory: apps/${{ env.APP_NAME }}
163+
run: composer run test:integration
164+
165+
- name: Print logs
166+
if: always()
167+
run: |
168+
cat data/nextcloud.log
169+
170+
- name: Skipped
171+
if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure'
172+
run: |
173+
echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts'
174+
exit 1
175+
176+
summary:
177+
permissions:
178+
contents: none
179+
runs-on: ubuntu-latest-low
180+
needs: [changes, phpunit-mysql]
181+
182+
if: always()
183+
184+
name: phpunit-mysql-summary
185+
186+
steps:
187+
- name: Summary status
188+
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-mysql.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)