|
| 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 | + push: |
| 11 | + branches: |
| 12 | + - master |
| 13 | + - stable* |
| 14 | + |
| 15 | +env: |
| 16 | + # Location of the phpunit.xml and phpunit.integration.xml files |
| 17 | + PHPUNIT_CONFIG: ./tests/phpunit.xml |
| 18 | + PHPUNIT_INTEGRATION_CONFIG: ./tests/phpunit.integration.xml |
| 19 | + |
| 20 | +jobs: |
| 21 | + phpunit-mysql: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + strategy: |
| 25 | + matrix: |
| 26 | + php-versions: ['7.4', '8.0', '8.1'] |
| 27 | + server-versions: ["${{ github.base_ref }}"] |
| 28 | + |
| 29 | + services: |
| 30 | + mysql: |
| 31 | + image: mariadb:10.5 |
| 32 | + ports: |
| 33 | + - 4444:3306/tcp |
| 34 | + env: |
| 35 | + MYSQL_ROOT_PASSWORD: rootpassword |
| 36 | + options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5 |
| 37 | + |
| 38 | + steps: |
| 39 | + - name: Set app env |
| 40 | + run: | |
| 41 | + # Split and keep last |
| 42 | + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV |
| 43 | +
|
| 44 | + - name: Enable ONLY_FULL_GROUP_BY MySQL option |
| 45 | + run: | |
| 46 | + echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword |
| 47 | + echo "SELECT @@sql_mode;" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword |
| 48 | +
|
| 49 | + - name: Checkout server |
| 50 | + uses: actions/checkout@v3 |
| 51 | + with: |
| 52 | + submodules: true |
| 53 | + repository: nextcloud/server |
| 54 | + ref: ${{ matrix.server-versions }} |
| 55 | + |
| 56 | + - name: Checkout app |
| 57 | + uses: actions/checkout@v3 |
| 58 | + with: |
| 59 | + path: apps/${{ env.APP_NAME }} |
| 60 | + |
| 61 | + - name: Set up php ${{ matrix.php-versions }} |
| 62 | + uses: shivammathur/setup-php@v2 |
| 63 | + with: |
| 64 | + php-version: ${{ matrix.php-versions }} |
| 65 | + tools: phpunit |
| 66 | + extensions: mbstring, iconv, fileinfo, intl, mysql, pdo_mysql |
| 67 | + coverage: none |
| 68 | + |
| 69 | + - name: Set up PHPUnit |
| 70 | + working-directory: apps/${{ env.APP_NAME }} |
| 71 | + run: composer i |
| 72 | + |
| 73 | + - name: Set up Nextcloud |
| 74 | + env: |
| 75 | + DB_PORT: 4444 |
| 76 | + run: | |
| 77 | + mkdir data |
| 78 | + ./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 |
| 79 | + ./occ app:enable ${{ env.APP_NAME }} |
| 80 | +
|
| 81 | + - name: Check PHPUnit config file existence |
| 82 | + id: check_phpunit |
| 83 | + uses: andstor/file-existence-action@v1 |
| 84 | + with: |
| 85 | + files: apps/${{ env.APP_NAME }}/${{ env.PHPUNIT_CONFIG }} |
| 86 | + |
| 87 | + - name: PHPUnit |
| 88 | + # Only run if phpunit config file exists |
| 89 | + if: steps.check_phpunit.outputs.files_exists == 'true' |
| 90 | + working-directory: apps/${{ env.APP_NAME }} |
| 91 | + run: ./vendor/phpunit/phpunit/phpunit -c ${{ env.PHPUNIT_CONFIG }} |
| 92 | + |
| 93 | + - name: Check PHPUnit integration config file existence |
| 94 | + id: check_integration |
| 95 | + uses: andstor/file-existence-action@v1 |
| 96 | + with: |
| 97 | + files: apps/${{ env.APP_NAME }}/${{ env.PHPUNIT_INTEGRATION_CONFIG }} |
| 98 | + |
| 99 | + - name: Run Nextcloud |
| 100 | + # Only run if phpunit integration config file exists |
| 101 | + if: steps.check_integration.outputs.files_exists == 'true' |
| 102 | + run: php -S localhost:8080 & |
| 103 | + |
| 104 | + - name: PHPUnit integration |
| 105 | + # Only run if phpunit integration config file exists |
| 106 | + if: steps.check_integration.outputs.files_exists == 'true' |
| 107 | + working-directory: apps/${{ env.APP_NAME }} |
| 108 | + run: ./vendor/phpunit/phpunit/phpunit -c ${{ env.PHPUNIT_INTEGRATION_CONFIG }} |
| 109 | + |
| 110 | + summary: |
| 111 | + runs-on: ubuntu-latest |
| 112 | + needs: phpunit-mysql |
| 113 | + |
| 114 | + if: always() |
| 115 | + |
| 116 | + name: phpunit-mysql-summary |
| 117 | + |
| 118 | + steps: |
| 119 | + - name: Summary status |
| 120 | + run: if ${{ needs.phpunit-mysql.result != 'success' }}; then exit 1; fi |
0 commit comments