Skip to content

Commit f602f96

Browse files
committed
ci: Move phpunit to github workflow templates
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent d4d59fa commit f602f96

6 files changed

Lines changed: 663 additions & 119 deletions

File tree

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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
7+
8+
on:
9+
pull_request:
10+
paths:
11+
- '.github/workflows/**'
12+
- 'appinfo/**'
13+
- 'lib/**'
14+
- 'templates/**'
15+
- 'tests/**'
16+
- 'vendor/**'
17+
- 'vendor-bin/**'
18+
- '.php-cs-fixer.dist.php'
19+
- 'composer.json'
20+
- 'composer.lock'
21+
22+
push:
23+
branches:
24+
- main
25+
- master
26+
- stable*
27+
28+
permissions:
29+
contents: read
30+
31+
concurrency:
32+
group: phpunit-mysql-${{ github.head_ref || github.run_id }}
33+
cancel-in-progress: true
34+
35+
jobs:
36+
phpunit-mysql:
37+
runs-on: ubuntu-latest
38+
39+
strategy:
40+
matrix:
41+
php-versions: ['8.0', '8.1']
42+
server-versions: ['master']
43+
44+
services:
45+
mysql:
46+
image: mariadb:10.5
47+
ports:
48+
- 4444:3306/tcp
49+
env:
50+
MYSQL_ROOT_PASSWORD: rootpassword
51+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5
52+
53+
steps:
54+
- name: Set app env
55+
run: |
56+
# Split and keep last
57+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
58+
59+
- name: Enable ONLY_FULL_GROUP_BY MySQL option
60+
run: |
61+
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
62+
echo "SELECT @@sql_mode;" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
63+
64+
- name: Checkout server
65+
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
66+
with:
67+
submodules: true
68+
repository: nextcloud/server
69+
ref: ${{ matrix.server-versions }}
70+
71+
- name: Checkout app
72+
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
73+
with:
74+
path: apps/${{ env.APP_NAME }}
75+
76+
- name: Set up php ${{ matrix.php-versions }}
77+
uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2
78+
with:
79+
php-version: ${{ matrix.php-versions }}
80+
extensions: mbstring, iconv, fileinfo, intl, mysql, pdo_mysql
81+
coverage: none
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Check composer file existence
86+
id: check_composer
87+
uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
88+
with:
89+
files: apps/${{ env.APP_NAME }}/composer.json
90+
91+
- name: Set up dependencies
92+
# Only run if phpunit config file exists
93+
if: steps.check_composer.outputs.files_exists == 'true'
94+
working-directory: apps/${{ env.APP_NAME }}
95+
run: composer i
96+
97+
- name: Set up Nextcloud
98+
env:
99+
DB_PORT: 4444
100+
run: |
101+
mkdir data
102+
./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 password
103+
./occ app:enable --force ${{ env.APP_NAME }}
104+
105+
- name: Check PHPUnit script is defined
106+
id: check_phpunit
107+
continue-on-error: true
108+
working-directory: apps/${{ env.APP_NAME }}
109+
run: |
110+
composer run --list | grep "^ test:unit " | wc -l | grep 1
111+
112+
- name: PHPUnit
113+
# Only run if phpunit config file exists
114+
if: steps.check_phpunit.outcome == 'success'
115+
working-directory: apps/${{ env.APP_NAME }}
116+
run: composer run test:unit
117+
118+
- name: Check PHPUnit integration script is defined
119+
id: check_integration
120+
continue-on-error: true
121+
working-directory: apps/${{ env.APP_NAME }}
122+
run: |
123+
composer run --list | grep "^ test:integration " | wc -l | grep 1
124+
125+
- name: Run Nextcloud
126+
# Only run if phpunit integration config file exists
127+
if: steps.check_integration.outcome == 'success'
128+
run: php -S localhost:8080 &
129+
130+
- name: PHPUnit integration
131+
# Only run if phpunit integration config file exists
132+
if: steps.check_integration.outcome == 'success'
133+
working-directory: apps/${{ env.APP_NAME }}
134+
run: composer run test:integration
135+
136+
- name: Skipped
137+
# Fail the action when neither unit nor integration tests ran
138+
if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure'
139+
run: |
140+
echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts'
141+
exit 1
142+
143+
summary:
144+
permissions:
145+
contents: none
146+
runs-on: ubuntu-latest
147+
needs: phpunit-mysql
148+
149+
if: always()
150+
151+
name: phpunit-mysql-summary
152+
153+
steps:
154+
- name: Summary status
155+
run: if ${{ needs.phpunit-mysql.result != 'success' }}; then exit 1; fi

.github/workflows/phpunit-oci.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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
7+
8+
on:
9+
pull_request:
10+
paths:
11+
- '.github/workflows/**'
12+
- 'appinfo/**'
13+
- 'lib/**'
14+
- 'templates/**'
15+
- 'tests/**'
16+
- 'vendor/**'
17+
- 'vendor-bin/**'
18+
- '.php-cs-fixer.dist.php'
19+
- 'composer.json'
20+
- 'composer.lock'
21+
22+
push:
23+
branches:
24+
- main
25+
- master
26+
- stable*
27+
28+
permissions:
29+
contents: read
30+
31+
concurrency:
32+
group: phpunit-oci-${{ github.head_ref || github.run_id }}
33+
cancel-in-progress: true
34+
35+
jobs:
36+
phpunit-oci:
37+
runs-on: ubuntu-latest
38+
39+
strategy:
40+
matrix:
41+
php-versions: ['8.0']
42+
server-versions: ['master']
43+
44+
services:
45+
oracle:
46+
image: deepdiver/docker-oracle-xe-11g # 'wnameless/oracle-xe-11g-r2'
47+
ports:
48+
- 1521:1521/tcp
49+
50+
steps:
51+
- name: Set app env
52+
run: |
53+
# Split and keep last
54+
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
55+
56+
- name: Checkout server
57+
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
58+
with:
59+
submodules: true
60+
repository: nextcloud/server
61+
ref: ${{ matrix.server-versions }}
62+
63+
- name: Checkout app
64+
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
65+
with:
66+
path: apps/${{ env.APP_NAME }}
67+
68+
- name: Set up php ${{ matrix.php-versions }}
69+
uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2
70+
with:
71+
php-version: ${{ matrix.php-versions }}
72+
extensions: mbstring, fileinfo, intl, sqlite, pdo_sqlite, oci8
73+
coverage: none
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
77+
- name: Check composer file existence
78+
id: check_composer
79+
uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
80+
with:
81+
files: apps/${{ env.APP_NAME }}/composer.json
82+
83+
- name: Set up dependencies
84+
# Only run if phpunit config file exists
85+
if: steps.check_composer.outputs.files_exists == 'true'
86+
working-directory: apps/${{ env.APP_NAME }}
87+
run: composer i
88+
89+
- name: Set up Nextcloud
90+
env:
91+
DB_PORT: 1521
92+
run: |
93+
mkdir data
94+
./occ maintenance:install --verbose --database=oci --database-name=XE --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=autotest --database-pass=owncloud --admin-user admin --admin-pass admin
95+
./occ app:enable --force ${{ env.APP_NAME }}
96+
97+
- name: Check PHPUnit script is defined
98+
id: check_phpunit
99+
continue-on-error: true
100+
working-directory: apps/${{ env.APP_NAME }}
101+
run: |
102+
composer run --list | grep "^ test:unit " | wc -l | grep 1
103+
104+
- name: PHPUnit
105+
# Only run if phpunit config file exists
106+
if: steps.check_phpunit.outcome == 'success'
107+
working-directory: apps/${{ env.APP_NAME }}
108+
run: composer run test:unit
109+
110+
- name: Check PHPUnit integration script is defined
111+
id: check_integration
112+
continue-on-error: true
113+
working-directory: apps/${{ env.APP_NAME }}
114+
run: |
115+
composer run --list | grep "^ test:integration " | wc -l | grep 1
116+
117+
- name: Run Nextcloud
118+
# Only run if phpunit integration config file exists
119+
if: steps.check_integration.outcome == 'success'
120+
run: php -S localhost:8080 &
121+
122+
- name: PHPUnit integration
123+
# Only run if phpunit integration config file exists
124+
if: steps.check_integration.outcome == 'success'
125+
working-directory: apps/${{ env.APP_NAME }}
126+
run: composer run test:integration
127+
128+
- name: Skipped
129+
# Fail the action when neither unit nor integration tests ran
130+
if: steps.check_phpunit.outcome == 'failure' && steps.check_integration.outcome == 'failure'
131+
run: |
132+
echo 'Neither PHPUnit nor PHPUnit integration tests are specified in composer.json scripts'
133+
exit 1
134+
135+
summary:
136+
permissions:
137+
contents: none
138+
runs-on: ubuntu-latest
139+
needs: phpunit-oci
140+
141+
if: always()
142+
143+
name: phpunit-oci-summary
144+
145+
steps:
146+
- name: Summary status
147+
run: if ${{ needs.phpunit-oci.result != 'success' }}; then exit 1; fi

0 commit comments

Comments
 (0)