|
| 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 |
0 commit comments