Skip to content

Commit e850c4c

Browse files
authored
Merge pull request #275 from nextcloud/fix/test-runner-workflow
fix(test): adjust tests and add phpunit workflow
2 parents b69f745 + 116ee54 commit e850c4c

10 files changed

Lines changed: 856 additions & 28 deletions

File tree

.github/workflows/integration-test-cron.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ jobs:
6565
databases: pgsql
6666
php-versions: 8.3
6767
encryption: 'on'
68+
- server-versions: stable35
69+
databases: pgsql
70+
php-versions: 8.3
71+
encryption: 'on'
6872
- server-versions: stable32
6973
databases: pgsql
7074
php-versions: 8.1
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
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@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
48+
id: changes
49+
continue-on-error: true
50+
with:
51+
filters: |
52+
src:
53+
- '.github/workflows/**'
54+
- 'appinfo/**'
55+
- 'lib/**'
56+
- 'templates/**'
57+
- 'tests/**'
58+
- 'vendor/**'
59+
- 'vendor-bin/**'
60+
- '.php-cs-fixer.dist.php'
61+
- 'composer.json'
62+
- 'composer.lock'
63+
64+
phpunit-mysql:
65+
runs-on: ubuntu-latest
66+
67+
needs: [changes, matrix]
68+
if: needs.changes.outputs.src != 'false'
69+
70+
strategy:
71+
fail-fast: false
72+
matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
73+
74+
name: MySQL ${{ matrix.mysql-versions }} 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 # zizmor: ignore[unpinned-images]
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+
85+
steps:
86+
- name: Set app env
87+
if: ${{ env.APP_NAME == '' }}
88+
run: |
89+
# Split and keep last
90+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
91+
92+
- name: Checkout server
93+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
94+
with:
95+
persist-credentials: false
96+
submodules: true
97+
repository: nextcloud/server
98+
ref: ${{ matrix.server-versions }}
99+
100+
- name: Checkout app
101+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
102+
with:
103+
persist-credentials: false
104+
path: apps/${{ env.APP_NAME }}
105+
106+
- name: Set up php ${{ matrix.php-versions }}
107+
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2
108+
with:
109+
php-version: ${{ matrix.php-versions }}
110+
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
111+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql
112+
coverage: none
113+
ini-file: development
114+
# Temporary workaround for missing pcntl_* in PHP 8.3
115+
ini-values: disable_functions=
116+
env:
117+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118+
119+
- name: Enable ONLY_FULL_GROUP_BY MySQL option
120+
run: |
121+
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
122+
echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
123+
124+
- name: Check composer file existence
125+
id: check_composer
126+
uses: andstor/file-existence-action@558493d6c74bf472d87c84eab196434afc2fa029 # v3.1.0
127+
with:
128+
files: apps/${{ env.APP_NAME }}/composer.json
129+
130+
- name: Remove nextcloud/ocp
131+
# Only run if phpunit config file exists
132+
if: steps.check_composer.outputs.files_exists == 'true'
133+
working-directory: apps/${{ env.APP_NAME }}
134+
run: |
135+
composer remove nextcloud/ocp --dev --no-scripts
136+
137+
- name: Install composer dependencies
138+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
139+
with:
140+
working-directory: apps/${{ env.APP_NAME }}
141+
142+
- name: Set up Nextcloud
143+
env:
144+
DB_PORT: 4444
145+
run: |
146+
mkdir data
147+
./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
148+
./occ app:enable --force ${{ env.APP_NAME }}
149+
150+
- name: Check PHPUnit script is defined
151+
id: check_phpunit
152+
continue-on-error: true
153+
working-directory: apps/${{ env.APP_NAME }}
154+
run: |
155+
composer run --list | grep '^ test:unit ' | wc -l | grep 1
156+
157+
- name: PHPUnit
158+
# Only run if phpunit config file exists
159+
if: steps.check_phpunit.outcome == 'success'
160+
working-directory: apps/${{ env.APP_NAME }}
161+
run: composer run test:unit
162+
163+
- name: Check PHPUnit integration script is defined
164+
id: check_integration
165+
continue-on-error: true
166+
working-directory: apps/${{ env.APP_NAME }}
167+
run: |
168+
composer run --list | grep '^ test:integration ' | wc -l | grep 1
169+
170+
- name: Run Nextcloud
171+
# Only run if phpunit integration config file exists
172+
if: steps.check_integration.outcome == 'success'
173+
run: php -S localhost:8080 &
174+
175+
- name: PHPUnit integration
176+
# Only run if phpunit integration config file exists
177+
if: steps.check_integration.outcome == 'success'
178+
working-directory: apps/${{ env.APP_NAME }}
179+
run: composer run test:integration
180+
181+
- name: Print logs
182+
if: always()
183+
run: |
184+
cat data/nextcloud.log
185+
186+
- name: Skipped
187+
# Fail the action when neither unit nor integration tests ran
188+
if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure'
189+
run: |
190+
echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts'
191+
exit 1
192+
193+
summary:
194+
permissions:
195+
contents: none
196+
runs-on: ubuntu-latest-low
197+
needs: [changes, phpunit-mysql]
198+
199+
if: always()
200+
201+
name: phpunit-mysql-summary
202+
203+
steps:
204+
- name: Summary status
205+
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-mysql.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)