Skip to content

Commit 79a1978

Browse files
authored
Merge pull request #29 from LibreCodeCoop/feature/test-with-more-databases
test with mysql
2 parents 957ed7f + 3d7f9ef commit 79a1978

File tree

3 files changed

+555
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)