Skip to content

Commit f13eeab

Browse files
committed
chore: update phpunit workflows
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 9d39da3 commit f13eeab

5 files changed

Lines changed: 646 additions & 225 deletions

File tree

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
with:
30+
persist-credentials: false
31+
32+
- name: Get version matrix
33+
id: versions
34+
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1
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+
- 'templates/**'
56+
- 'tests/**'
57+
- 'vendor/**'
58+
- 'vendor-bin/**'
59+
- '.php-cs-fixer.dist.php'
60+
- 'composer.json'
61+
- 'composer.lock'
62+
63+
phpunit-mariadb:
64+
runs-on: ubuntu-latest
65+
66+
needs: [changes, matrix]
67+
if: needs.changes.outputs.src != 'false'
68+
69+
strategy:
70+
matrix:
71+
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
72+
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
73+
mariadb-versions: ['10.6', '10.11']
74+
75+
name: MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
76+
77+
services:
78+
mariadb:
79+
image: ghcr.io/nextcloud/continuous-integration-mariadb-${{ matrix.mariadb-versions }}:latest
80+
ports:
81+
- 4444:3306/tcp
82+
env:
83+
MYSQL_ROOT_PASSWORD: rootpassword
84+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5
85+
86+
steps:
87+
- name: Set app env
88+
run: |
89+
# Split and keep last
90+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
91+
92+
- name: Checkout server
93+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
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@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
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+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
117+
- name: Enable ONLY_FULL_GROUP_BY MariaDB option
118+
run: |
119+
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
120+
echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
121+
122+
- name: Check composer file existence
123+
id: check_composer
124+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
125+
with:
126+
files: apps/${{ env.APP_NAME }}/composer.json
127+
128+
- name: Set up dependencies
129+
# Only run if phpunit config file exists
130+
if: steps.check_composer.outputs.files_exists == 'true'
131+
working-directory: apps/${{ env.APP_NAME }}
132+
run: |
133+
composer remove nextcloud/ocp --dev
134+
composer i
135+
136+
- name: Set up Nextcloud
137+
env:
138+
DB_PORT: 4444
139+
run: |
140+
mkdir data
141+
./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
142+
./occ app:enable --force ${{ env.APP_NAME }}
143+
144+
- name: Check PHPUnit script is defined
145+
id: check_phpunit
146+
continue-on-error: true
147+
working-directory: apps/${{ env.APP_NAME }}
148+
run: |
149+
composer run --list | grep '^ test:unit ' | wc -l | grep 1
150+
151+
- name: PHPUnit
152+
# Only run if phpunit config file exists
153+
if: steps.check_phpunit.outcome == 'success'
154+
working-directory: apps/${{ env.APP_NAME }}
155+
run: composer run test:unit
156+
157+
- name: Check PHPUnit integration script is defined
158+
id: check_integration
159+
continue-on-error: true
160+
working-directory: apps/${{ env.APP_NAME }}
161+
run: |
162+
composer run --list | grep '^ test:integration ' | wc -l | grep 1
163+
164+
- name: Run Nextcloud
165+
# Only run if phpunit integration config file exists
166+
if: steps.check_integration.outcome == 'success'
167+
run: php -S localhost:8080 &
168+
169+
- name: PHPUnit integration
170+
# Only run if phpunit integration config file exists
171+
if: steps.check_integration.outcome == 'success'
172+
working-directory: apps/${{ env.APP_NAME }}
173+
run: composer run test:integration
174+
175+
- name: Print logs
176+
if: always()
177+
run: |
178+
cat data/nextcloud.log
179+
180+
- name: Skipped
181+
# Fail the action when neither unit nor integration tests ran
182+
if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure'
183+
run: |
184+
echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts'
185+
exit 1
186+
187+
summary:
188+
permissions:
189+
contents: none
190+
runs-on: ubuntu-latest-low
191+
needs: [changes, phpunit-mariadb]
192+
193+
if: always()
194+
195+
name: phpunit-mariadb-summary
196+
197+
steps:
198+
- name: Summary status
199+
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-mariadb.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)