Skip to content

Commit 03ba84f

Browse files
committed
chore: run sharding tests in ci
Signed-off-by: Robin Appelman <[email protected]>
1 parent ea03ec7 commit 03ba84f

File tree

1 file changed

+248
-0
lines changed

1 file changed

+248
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
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-sharding-${{ 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@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
29+
30+
- name: Get version matrix
31+
id: versions
32+
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1
33+
34+
changes:
35+
runs-on: ubuntu-latest-low
36+
permissions:
37+
contents: read
38+
pull-requests: read
39+
40+
outputs:
41+
src: ${{ steps.changes.outputs.src}}
42+
43+
steps:
44+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
45+
id: changes
46+
continue-on-error: true
47+
with:
48+
filters: |
49+
src:
50+
- '.github/workflows/**'
51+
- 'appinfo/**'
52+
- 'lib/**'
53+
- 'templates/**'
54+
- 'tests/**'
55+
- 'vendor/**'
56+
- 'vendor-bin/**'
57+
- '.php-cs-fixer.dist.php'
58+
- 'composer.json'
59+
- 'composer.lock'
60+
61+
phpunit-mysql-sharding:
62+
runs-on: ubuntu-latest
63+
64+
needs: [changes, matrix]
65+
if: needs.changes.outputs.src != 'false'
66+
67+
strategy:
68+
matrix:
69+
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
70+
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
71+
mysql-versions:
72+
- 8.4
73+
74+
name: MySQL ${{ matrix.mysql-versions }} Sharding PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
75+
76+
services:
77+
mysql:
78+
image: ghcr.io/nextcloud/continuous-integration-mysql-${{ matrix.mysql-versions }}:latest
79+
ports:
80+
- 4444:3306/tcp
81+
env:
82+
MYSQL_ROOT_PASSWORD: rootpassword
83+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10
84+
shard1:
85+
image: ghcr.io/nextcloud/continuous-integration-mysql-${{ matrix.mysql-versions }}:latest
86+
ports:
87+
- 5001:3306/tcp
88+
env:
89+
MYSQL_ROOT_PASSWORD: rootpassword
90+
MYSQL_USER: oc_autotest
91+
MYSQL_PASSWORD: nextcloud
92+
MYSQL_DATABASE: nextcloud
93+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10
94+
shard2:
95+
image: ghcr.io/nextcloud/continuous-integration-mysql-${{ matrix.mysql-versions }}:latest
96+
ports:
97+
- 5002:3306/tcp
98+
env:
99+
MYSQL_ROOT_PASSWORD: rootpassword
100+
MYSQL_USER: oc_autotest
101+
MYSQL_PASSWORD: nextcloud
102+
MYSQL_DATABASE: nextcloud
103+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10
104+
shard3:
105+
image: ghcr.io/nextcloud/continuous-integration-mysql-${{ matrix.mysql-versions }}:latest
106+
ports:
107+
- 5003:3306/tcp
108+
env:
109+
MYSQL_ROOT_PASSWORD: rootpassword
110+
MYSQL_USER: oc_autotest
111+
MYSQL_PASSWORD: nextcloud
112+
MYSQL_DATABASE: nextcloud
113+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10
114+
shard4:
115+
image: ghcr.io/nextcloud/continuous-integration-mysql-${{ matrix.mysql-versions }}:latest
116+
ports:
117+
- 5004:3306/tcp
118+
env:
119+
MYSQL_ROOT_PASSWORD: rootpassword
120+
MYSQL_USER: oc_autotest
121+
MYSQL_PASSWORD: nextcloud
122+
MYSQL_DATABASE: nextcloud
123+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10
124+
125+
steps:
126+
- name: Set app env
127+
run: |
128+
# Split and keep last
129+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
130+
131+
- name: Checkout server
132+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
133+
with:
134+
submodules: true
135+
repository: nextcloud/server
136+
ref: ${{ matrix.server-versions }}
137+
138+
- name: Checkout Circles
139+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
140+
with:
141+
repository: nextcloud/circles
142+
ref: master
143+
path: apps/circles
144+
145+
- name: Checkout app
146+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
147+
with:
148+
path: apps/${{ env.APP_NAME }}
149+
150+
- name: Set up php ${{ matrix.php-versions }}
151+
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
152+
with:
153+
php-version: ${{ matrix.php-versions }}
154+
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
155+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql
156+
coverage: none
157+
ini-file: development
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160+
161+
- name: Enable ONLY_FULL_GROUP_BY MySQL option
162+
run: |
163+
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
164+
echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
165+
166+
- name: Set up Circles dependencies
167+
working-directory: apps/circles
168+
run: composer i
169+
170+
- name: Check composer file existence
171+
id: check_composer
172+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
173+
with:
174+
files: apps/${{ env.APP_NAME }}/composer.json
175+
176+
- name: Set up dependencies
177+
# Only run if phpunit config file exists
178+
if: steps.check_composer.outputs.files_exists == 'true'
179+
working-directory: apps/${{ env.APP_NAME }}
180+
run: composer i
181+
182+
- name: Set up Nextcloud
183+
env:
184+
DB_PORT: 4444
185+
SHARDING: 1
186+
run: |
187+
mkdir data
188+
cp tests/preseed-config.php config/config.php
189+
./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
190+
./occ app:enable --force circles
191+
./occ app:enable --force ${{ env.APP_NAME }}
192+
193+
- name: Check PHPUnit script is defined
194+
id: check_phpunit
195+
continue-on-error: true
196+
working-directory: apps/${{ env.APP_NAME }}
197+
run: |
198+
composer run --list | grep '^ test:unit ' | wc -l | grep 1
199+
200+
- name: PHPUnit
201+
# Only run if phpunit config file exists
202+
if: steps.check_phpunit.outcome == 'success'
203+
working-directory: apps/${{ env.APP_NAME }}
204+
run: composer run test:unit
205+
206+
- name: Check PHPUnit integration script is defined
207+
id: check_integration
208+
continue-on-error: true
209+
working-directory: apps/${{ env.APP_NAME }}
210+
run: |
211+
composer run --list | grep '^ test:integration ' | wc -l | grep 1
212+
213+
- name: Run Nextcloud
214+
# Only run if phpunit integration config file exists
215+
if: steps.check_integration.outcome == 'success'
216+
run: php -S localhost:8080 &
217+
218+
- name: PHPUnit integration
219+
# Only run if phpunit integration config file exists
220+
if: steps.check_integration.outcome == 'success'
221+
working-directory: apps/${{ env.APP_NAME }}
222+
run: composer run test:integration
223+
224+
- name: Print logs
225+
if: always()
226+
run: |
227+
cat data/nextcloud.log
228+
229+
- name: Skipped
230+
# Fail the action when neither unit nor integration tests ran
231+
if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure'
232+
run: |
233+
echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts'
234+
exit 1
235+
236+
summary:
237+
permissions:
238+
contents: none
239+
runs-on: ubuntu-latest-low
240+
needs: [changes, phpunit-mysql-sharding]
241+
242+
if: always()
243+
244+
name: phpunit-mysql-sharding-summary
245+
246+
steps:
247+
- name: Summary status
248+
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-mysql-sharding.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)