Skip to content

Commit 1a7fddd

Browse files
authored
Merge pull request #650 from nextcloud/fix/phpunit
chore: update phpunit workflows
2 parents 9d39da3 + a68af06 commit 1a7fddd

7 files changed

Lines changed: 657 additions & 214 deletions

File tree

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

0 commit comments

Comments
 (0)