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