Skip to content

Commit c0289e3

Browse files
chore(ci): update PHPUnit workflow for PostgreSQL with enhanced job structure and conditional execution
Signed-off-by: Misha M.-Kupriyanov <[email protected]>
1 parent 7396ce1 commit c0289e3

File tree

1 file changed

+119
-33
lines changed

1 file changed

+119
-33
lines changed
Lines changed: 119 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-FileCopyrightText: Nextcloud contributors
22
# SPDX-License-Identifier: AGPL-3.0-or-later
3-
name: PHPUnit
3+
name: PHPUnit PostgreSQL
44

55
on:
66
pull_request:
@@ -9,23 +9,75 @@ on:
99
- master
1010
- stable*
1111

12-
env:
13-
# Location of the phpunit.xml and phpunit.integration.xml files
14-
PHPUNIT_CONFIG: ./tests/phpunit.xml
15-
PHPUNIT_INTEGRATION_CONFIG: ./tests/phpunit.integration.xml
12+
permissions:
13+
contents: read
14+
15+
concurrency:
16+
group: phpunit-pgsql-${{ github.head_ref || github.run_id }}
17+
cancel-in-progress: true
1618

1719
jobs:
20+
matrix:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
php-version: ${{ steps.versions.outputs.php-available-list }}
24+
server-max: ${{ steps.versions.outputs.branches-max-list }}
25+
steps:
26+
- name: Checkout app
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
persist-credentials: false
30+
31+
- name: Get version matrix
32+
id: versions
33+
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1
34+
35+
changes:
36+
runs-on: ubuntu-latest
37+
permissions:
38+
contents: read
39+
pull-requests: read
40+
41+
outputs:
42+
src: ${{ steps.changes.outputs.src }}
43+
44+
steps:
45+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
46+
id: changes
47+
continue-on-error: true
48+
with:
49+
filters: |
50+
src:
51+
- '.github/workflows/**'
52+
- 'appinfo/**'
53+
- 'lib/**'
54+
- 'js/**'
55+
- 'templates/**'
56+
- 'tests/**'
57+
- 'vendor/**'
58+
- 'vendor-bin/**'
59+
- '.php-cs-fixer.dist.php'
60+
- 'composer.json'
61+
- 'composer.lock'
62+
1863
phpunit-pgsql:
1964
runs-on: ubuntu-latest
2065

66+
needs: [changes, matrix]
67+
if: needs.changes.outputs.src != 'false'
68+
env:
69+
APP_NAME: googleanalytics
70+
2171
strategy:
2272
matrix:
23-
php-versions: ['8.3']
24-
server-versions: ['stable31']
73+
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
74+
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
75+
76+
name: PostgreSQL PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
2577

2678
services:
2779
postgres:
28-
image: postgres
80+
image: ghcr.io/nextcloud/continuous-integration-postgres-14:latest
2981
ports:
3082
- 4444:5432/tcp
3183
env:
@@ -36,79 +88,113 @@ jobs:
3688

3789
steps:
3890
- name: Set app env
91+
if: ${{ env.APP_NAME == '' }}
3992
run: |
4093
# Split and keep last
41-
echo "APP_NAME=googleanalytics" >> $GITHUB_ENV
94+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
4295
4396
- name: Checkout server
44-
uses: actions/checkout@v3
97+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4598
with:
99+
persist-credentials: false
46100
submodules: true
47101
repository: nextcloud/server
48102
ref: ${{ matrix.server-versions }}
49103

50104
- name: Checkout app
51-
uses: actions/checkout@v3
105+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
52106
with:
107+
persist-credentials: false
53108
path: apps/${{ env.APP_NAME }}
54109

55110
- name: Set up php ${{ matrix.php-versions }}
56-
uses: shivammathur/setup-php@v2
111+
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
57112
with:
58113
php-version: ${{ matrix.php-versions }}
59-
tools: phpunit
60-
extensions: mbstring, iconv, fileinfo, intl, pgsql, pdo_pgsql
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, pgsql, pdo_pgsql
61116
coverage: none
117+
ini-file: development
118+
# Temporary workaround for missing pcntl_* in PHP 8.3
119+
ini-values: disable_functions=
120+
env:
121+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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
62128

63-
- name: Set up PHPUnit
129+
- name: Set up dependencies
130+
# Only run if phpunit config file exists
131+
if: steps.check_composer.outputs.files_exists == 'true'
64132
working-directory: apps/${{ env.APP_NAME }}
65-
run: composer i
133+
run: |
134+
composer remove nextcloud/ocp --dev
135+
composer i
66136
67137
- name: Set up Nextcloud
68138
env:
69139
DB_PORT: 4444
70140
run: |
71141
mkdir data
72-
./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
73-
./occ app:enable ${{ env.APP_NAME }}
142+
./occ maintenance:install --verbose --database=pgsql --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 }}
74144
75-
- name: Check PHPUnit config file existence
145+
- name: Check PHPUnit script is defined
76146
id: check_phpunit
77-
uses: andstor/file-existence-action@v1
78-
with:
79-
files: apps/${{ env.APP_NAME }}/${{ env.PHPUNIT_CONFIG }}
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
80151
81152
- name: PHPUnit
82153
# Only run if phpunit config file exists
83-
if: steps.check_phpunit.outputs.files_exists == 'true'
154+
if: steps.check_phpunit.outcome == 'success'
84155
working-directory: apps/${{ env.APP_NAME }}
85-
run: ./vendor/phpunit/phpunit/phpunit -c ${{ env.PHPUNIT_CONFIG }}
156+
run: composer run test:unit
86157

87-
- name: Check PHPUnit integration config file existence
158+
- name: Check PHPUnit integration script is defined
88159
id: check_integration
89-
uses: andstor/file-existence-action@v1
90-
with:
91-
files: apps/${{ env.APP_NAME }}/${{ env.PHPUNIT_INTEGRATION_CONFIG }}
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
92164
93165
- name: Run Nextcloud
94166
# Only run if phpunit integration config file exists
95-
if: steps.check_integration.outputs.files_exists == 'true'
167+
if: steps.check_integration.outcome == 'success'
96168
run: php -S localhost:8080 &
97169

98170
- name: PHPUnit integration
99171
# Only run if phpunit integration config file exists
100-
if: steps.check_integration.outputs.files_exists == 'true'
172+
if: steps.check_integration.outcome == 'success'
101173
working-directory: apps/${{ env.APP_NAME }}
102-
run: ./vendor/phpunit/phpunit/phpunit -c ${{ env.PHPUNIT_INTEGRATION_CONFIG }}
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
103187
104188
summary:
189+
permissions:
190+
contents: none
105191
runs-on: ubuntu-latest
106-
needs: phpunit-pgsql
192+
needs: [changes, phpunit-pgsql]
107193

108194
if: always()
109195

110196
name: phpunit-pgsql-summary
111197

112198
steps:
113199
- name: Summary status
114-
run: if ${{ needs.phpunit-pgsql.result != 'success' }}; then exit 1; fi
200+
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-pgsql.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)