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+
30+ - name : Get version matrix
31+ id : versions
32+ uses : icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1
33+
34+ changes :
35+ runs-on : ubuntu-latest-low
36+ permissions :
37+ contents : read
38+ pull-requests : read
39+
40+ outputs :
41+ src : ${{ steps.changes.outputs.src}}
42+
43+ steps :
44+ - uses : dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
45+ id : changes
46+ continue-on-error : true
47+ with :
48+ filters : |
49+ src:
50+ - '.github/workflows/**'
51+ - 'appinfo/**'
52+ - 'lib/**'
53+ - 'templates/**'
54+ - 'tests/**'
55+ - 'vendor/**'
56+ - 'vendor-bin/**'
57+ - '.php-cs-fixer.dist.php'
58+ - 'composer.json'
59+ - 'composer.lock'
60+
61+ phpunit-mariadb :
62+ runs-on : ubuntu-latest
63+
64+ needs : [changes, matrix]
65+ if : needs.changes.outputs.src != 'false'
66+
67+ strategy :
68+ matrix :
69+ php-versions : ${{ fromJson(needs.matrix.outputs.php-version) }}
70+ server-versions : ${{ fromJson(needs.matrix.outputs.server-max) }}
71+ mariadb-versions : ['10.6', '10.11']
72+
73+ name : MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
74+
75+ services :
76+ mariadb :
77+ image : ghcr.io/nextcloud/continuous-integration-mariadb-${{ matrix.mariadb-versions }}:latest
78+ ports :
79+ - 4444:3306/tcp
80+ env :
81+ MYSQL_ROOT_PASSWORD : rootpassword
82+ options : --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5
83+
84+ steps :
85+ - name : Set app env
86+ run : |
87+ # Split and keep last
88+ echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
89+
90+ - name : Checkout server
91+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
92+ with :
93+ submodules : true
94+ repository : nextcloud/server
95+ ref : ${{ matrix.server-versions }}
96+
97+ - name : Checkout app
98+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
99+ with :
100+ path : apps/${{ env.APP_NAME }}
101+
102+ - name : Checkout teams dependency
103+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
104+ with :
105+ repository : nextcloud/circles
106+ ref : ${{ matrix.server-versions }}
107+ path : apps/circles
108+
109+ - name : Set up php ${{ matrix.php-versions }}
110+ uses : shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
111+ with :
112+ php-version : ${{ matrix.php-versions }}
113+ # https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
114+ extensions : bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, mysql, pdo_mysql
115+ coverage : none
116+ ini-file : development
117+ env :
118+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
119+
120+ - name : Enable ONLY_FULL_GROUP_BY MariaDB option
121+ run : |
122+ echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
123+ echo 'SELECT @@sql_mode;' | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
124+
125+ - name : Check composer file existence
126+ id : check_composer
127+ uses : andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
128+ with :
129+ files : apps/${{ env.APP_NAME }}/composer.json
130+
131+ - name : Set up dependencies
132+ # Only run if phpunit config file exists
133+ if : steps.check_composer.outputs.files_exists == 'true'
134+ working-directory : apps/${{ env.APP_NAME }}
135+ run : 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