Skip to content

Commit 787eb04

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

5 files changed

Lines changed: 651 additions & 225 deletions

File tree

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
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+
if: ${{ env.APP_NAME == '' }}
89+
run: |
90+
# Split and keep last
91+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
92+
93+
- name: Checkout server
94+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
95+
with:
96+
persist-credentials: false
97+
submodules: true
98+
repository: nextcloud/server
99+
ref: ${{ matrix.server-versions }}
100+
101+
- name: Checkout app
102+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
103+
with:
104+
persist-credentials: false
105+
path: apps/${{ env.APP_NAME }}
106+
107+
- name: Set up php ${{ matrix.php-versions }}
108+
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
109+
with:
110+
php-version: ${{ matrix.php-versions }}
111+
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
112+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql
113+
coverage: none
114+
ini-file: development
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
118+
- name: Enable ONLY_FULL_GROUP_BY MariaDB option
119+
run: |
120+
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
121+
echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
122+
123+
- name: Check composer file existence
124+
id: check_composer
125+
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
126+
with:
127+
files: apps/${{ env.APP_NAME }}/composer.json
128+
129+
- name: Set up dependencies
130+
# Only run if phpunit config file exists
131+
if: steps.check_composer.outputs.files_exists == 'true'
132+
working-directory: apps/${{ env.APP_NAME }}
133+
run: |
134+
composer remove nextcloud/ocp --dev
135+
composer i
136+
137+
- name: Set up Nextcloud
138+
env:
139+
DB_PORT: 4444
140+
run: |
141+
mkdir data
142+
./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
143+
./occ app:enable --force ${{ env.APP_NAME }}
144+
145+
- name: Check PHPUnit script is defined
146+
id: check_phpunit
147+
continue-on-error: true
148+
working-directory: apps/${{ env.APP_NAME }}
149+
run: |
150+
composer run --list | grep '^ test:unit ' | wc -l | grep 1
151+
152+
- name: PHPUnit
153+
# Only run if phpunit config file exists
154+
if: steps.check_phpunit.outcome == 'success'
155+
working-directory: apps/${{ env.APP_NAME }}
156+
run: composer run test:unit
157+
158+
- name: Check PHPUnit integration script is defined
159+
id: check_integration
160+
continue-on-error: true
161+
working-directory: apps/${{ env.APP_NAME }}
162+
run: |
163+
composer run --list | grep '^ test:integration ' | wc -l | grep 1
164+
165+
- name: Run Nextcloud
166+
# Only run if phpunit integration config file exists
167+
if: steps.check_integration.outcome == 'success'
168+
run: php -S localhost:8080 &
169+
170+
- name: PHPUnit integration
171+
# Only run if phpunit integration config file exists
172+
if: steps.check_integration.outcome == 'success'
173+
working-directory: apps/${{ env.APP_NAME }}
174+
run: composer run test:integration
175+
176+
- name: Print logs
177+
if: always()
178+
run: |
179+
cat data/nextcloud.log
180+
181+
- name: Skipped
182+
# Fail the action when neither unit nor integration tests ran
183+
if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure'
184+
run: |
185+
echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts'
186+
exit 1
187+
188+
summary:
189+
permissions:
190+
contents: none
191+
runs-on: ubuntu-latest-low
192+
needs: [changes, phpunit-mariadb]
193+
194+
if: always()
195+
196+
name: phpunit-mariadb-summary
197+
198+
steps:
199+
- name: Summary status
200+
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-mariadb.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)