2828permissions :
2929 contents : read
3030
31- concurrency :
31+ concurrency :
3232 group : phpunit-mysql-${{ github.head_ref || github.run_id }}
3333 cancel-in-progress : true
3434
35- env :
36- # Location of the phpunit.xml and phpunit.integration.xml files
37- PHPUNIT_CONFIG : ./tests/phpunit.xml
38- PHPUNIT_INTEGRATION_CONFIG : ./tests/phpunit.integration.xml
39-
4035jobs :
4136 phpunit-mysql :
4237 runs-on : ubuntu-latest
4338
4439 strategy :
4540 matrix :
46- php-versions : ['7.4', ' 8.0', '8.1']
41+ php-versions : ['8.0', '8.1']
4742 server-versions : ['master']
4843
4944 services :
@@ -67,32 +62,33 @@ jobs:
6762 echo "SELECT @@sql_mode;" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
6863
6964 - name : Checkout server
70- uses : actions/checkout@v3
65+ uses : actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
7166 with :
7267 submodules : true
7368 repository : nextcloud/server
7469 ref : ${{ matrix.server-versions }}
7570
7671 - name : Checkout app
77- uses : actions/checkout@v3
72+ uses : actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
7873 with :
7974 path : apps/${{ env.APP_NAME }}
8075
8176 - name : Set up php ${{ matrix.php-versions }}
82- uses : shivammathur/setup-php@v2
77+ uses : shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2
8378 with :
8479 php-version : ${{ matrix.php-versions }}
85- tools : phpunit
8680 extensions : mbstring, iconv, fileinfo, intl, mysql, pdo_mysql
8781 coverage : none
82+ env :
83+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
8884
8985 - name : Check composer file existence
9086 id : check_composer
91- uses : andstor/file-existence-action@v1
87+ uses : andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
9288 with :
9389 files : apps/${{ env.APP_NAME }}/composer.json
9490
95- - name : Set up PHPUnit
91+ - name : Set up dependencies
9692 # Only run if phpunit config file exists
9793 if : steps.check_composer.outputs.files_exists == 'true'
9894 working-directory : apps/${{ env.APP_NAME }}
@@ -106,34 +102,43 @@ jobs:
106102 ./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
107103 ./occ app:enable --force ${{ env.APP_NAME }}
108104
109- - name : Check PHPUnit config file existence
105+ - name : Check PHPUnit script is defined
110106 id : check_phpunit
111- uses : andstor/file-existence-action@v1
112- with :
113- files : apps/${{ env.APP_NAME }}/${{ env.PHPUNIT_CONFIG }}
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
114111
115112 - name : PHPUnit
116113 # Only run if phpunit config file exists
117- if : steps.check_phpunit.outputs.files_exists == 'true '
114+ if : steps.check_phpunit.outcome == 'success '
118115 working-directory : apps/${{ env.APP_NAME }}
119- run : ./vendor/phpunit/phpunit/phpunit -c ${{ env.PHPUNIT_CONFIG }}
116+ run : composer run test:unit
120117
121- - name : Check PHPUnit integration config file existence
118+ - name : Check PHPUnit integration script is defined
122119 id : check_integration
123- uses : andstor/file-existence-action@v1
124- with :
125- files : apps/${{ env.APP_NAME }}/${{ env.PHPUNIT_INTEGRATION_CONFIG }}
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
126124
127125 - name : Run Nextcloud
128126 # Only run if phpunit integration config file exists
129- if : steps.check_integration.outputs.files_exists == 'true '
127+ if : steps.check_integration.outcome == 'success '
130128 run : php -S localhost:8080 &
131129
132130 - name : PHPUnit integration
133131 # Only run if phpunit integration config file exists
134- if : steps.check_integration.outputs.files_exists == 'true '
132+ if : steps.check_integration.outcome == 'success '
135133 working-directory : apps/${{ env.APP_NAME }}
136- run : ./vendor/phpunit/phpunit/phpunit -c ${{ env.PHPUNIT_INTEGRATION_CONFIG }}
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
137142
138143 summary :
139144 permissions :
0 commit comments