|
| 1 | +name: Moodle Plugin CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + test: |
| 12 | + runs-on: ubuntu-22.04 |
| 13 | + |
| 14 | + services: |
| 15 | + postgres: |
| 16 | + image: postgres:13 |
| 17 | + env: |
| 18 | + POSTGRES_USER: 'postgres' |
| 19 | + POSTGRES_HOST_AUTH_METHOD: 'trust' |
| 20 | + ports: |
| 21 | + - 5432:5432 |
| 22 | + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 |
| 23 | + |
| 24 | + mariadb: |
| 25 | + image: mariadb:10 |
| 26 | + env: |
| 27 | + MYSQL_USER: 'root' |
| 28 | + MYSQL_ALLOW_EMPTY_PASSWORD: "true" |
| 29 | + MYSQL_CHARACTER_SET_SERVER: "utf8mb4" |
| 30 | + MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" |
| 31 | + ports: |
| 32 | + - 3306:3306 |
| 33 | + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 |
| 34 | + |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + # Use explicit include to pair each Moodle branch with its |
| 39 | + # compatible PHP version and alternate databases across entries. |
| 40 | + # |
| 41 | + # Moodle/PHP compatibility (official): |
| 42 | + # Moodle 3.11: PHP 7.3 - 8.0 |
| 43 | + # Moodle 4.0: PHP 7.3 - 8.0 |
| 44 | + # Moodle 4.1: PHP 7.4 - 8.1 |
| 45 | + # Moodle 4.2: PHP 8.0 - 8.2 |
| 46 | + # Moodle 4.3: PHP 8.0 - 8.2 |
| 47 | + include: |
| 48 | + # Moodle 3.11 - oldest supported branch, lowest PHP. |
| 49 | + - php: '7.4' |
| 50 | + moodle-branch: 'MOODLE_311_STABLE' |
| 51 | + database: pgsql |
| 52 | + |
| 53 | + # Moodle 4.0 - test with MariaDB for DB coverage. |
| 54 | + - php: '8.0' |
| 55 | + moodle-branch: 'MOODLE_400_STABLE' |
| 56 | + database: mariadb |
| 57 | + |
| 58 | + # Moodle 4.1 LTS - critical long-term-support branch. |
| 59 | + - php: '8.0' |
| 60 | + moodle-branch: 'MOODLE_401_STABLE' |
| 61 | + database: pgsql |
| 62 | + |
| 63 | + - php: '8.1' |
| 64 | + moodle-branch: 'MOODLE_401_STABLE' |
| 65 | + database: mariadb |
| 66 | + |
| 67 | + # Moodle 4.2 - mid-range branch. |
| 68 | + - php: '8.1' |
| 69 | + moodle-branch: 'MOODLE_402_STABLE' |
| 70 | + database: pgsql |
| 71 | + |
| 72 | + # Moodle 4.3 - newest supported branch, highest PHP. |
| 73 | + - php: '8.2' |
| 74 | + moodle-branch: 'MOODLE_403_STABLE' |
| 75 | + database: pgsql |
| 76 | + |
| 77 | + - php: '8.2' |
| 78 | + moodle-branch: 'MOODLE_403_STABLE' |
| 79 | + database: mariadb |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Check out repository code |
| 83 | + uses: actions/checkout@v4 |
| 84 | + with: |
| 85 | + path: plugin |
| 86 | + |
| 87 | + - name: Setup PHP ${{ matrix.php }} |
| 88 | + uses: shivammathur/setup-php@v2 |
| 89 | + with: |
| 90 | + php-version: ${{ matrix.php }} |
| 91 | + extensions: pgsql, mysqli, zip, gd, xmlrpc, soap, intl |
| 92 | + ini-values: max_input_vars=5000 |
| 93 | + # Use 'none' unless you need code coverage reports. |
| 94 | + # For coverage, use 'pcov' (Moodle 3.10+) or 'xdebug'. |
| 95 | + coverage: none |
| 96 | + |
| 97 | + - name: Initialise moodle-plugin-ci |
| 98 | + run: | |
| 99 | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 |
| 100 | + echo $(cd ci/bin; pwd) >> $GITHUB_PATH |
| 101 | + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH |
| 102 | + sudo locale-gen en_AU.UTF-8 |
| 103 | + echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV |
| 104 | +
|
| 105 | + - name: Install moodle-plugin-ci |
| 106 | + run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 |
| 107 | + env: |
| 108 | + DB: ${{ matrix.database }} |
| 109 | + MOODLE_BRANCH: ${{ matrix.moodle-branch }} |
| 110 | + |
| 111 | + # --------------------------------------------------------------- |
| 112 | + # Static analysis checks. |
| 113 | + # Each step uses `if: ${{ !cancelled() }}` so that all checks |
| 114 | + # run even if a previous check fails. This gives a complete |
| 115 | + # picture of all issues in a single CI run. |
| 116 | + # --------------------------------------------------------------- |
| 117 | + |
| 118 | + - name: PHP Lint |
| 119 | + if: ${{ !cancelled() }} |
| 120 | + run: moodle-plugin-ci phplint |
| 121 | + |
| 122 | + - name: PHP Mess Detector |
| 123 | + continue-on-error: true |
| 124 | + if: ${{ !cancelled() }} |
| 125 | + run: moodle-plugin-ci phpmd |
| 126 | + |
| 127 | + - name: Moodle Code Checker |
| 128 | + if: ${{ !cancelled() }} |
| 129 | + run: moodle-plugin-ci phpcs --max-warnings 0 |
| 130 | + |
| 131 | + - name: Moodle PHPDoc Checker |
| 132 | + if: ${{ !cancelled() }} |
| 133 | + run: moodle-plugin-ci phpdoc --max-warnings 0 |
| 134 | + |
| 135 | + - name: Validating |
| 136 | + if: ${{ !cancelled() }} |
| 137 | + run: moodle-plugin-ci validate |
| 138 | + |
| 139 | + - name: Check upgrade savepoints |
| 140 | + if: ${{ !cancelled() }} |
| 141 | + run: moodle-plugin-ci savepoints |
| 142 | + |
| 143 | + - name: Mustache Lint |
| 144 | + if: ${{ !cancelled() }} |
| 145 | + run: moodle-plugin-ci mustache |
| 146 | + |
| 147 | + - name: Grunt |
| 148 | + if: ${{ !cancelled() }} |
| 149 | + run: moodle-plugin-ci grunt --max-lint-warnings 0 |
| 150 | + |
| 151 | + # --------------------------------------------------------------- |
| 152 | + # Tests. Enable these once test files exist in the plugin. |
| 153 | + # --------------------------------------------------------------- |
| 154 | + |
| 155 | + # Uncomment once PHPUnit tests are added under tests/: |
| 156 | + # - name: PHPUnit tests |
| 157 | + # if: ${{ !cancelled() }} |
| 158 | + # run: moodle-plugin-ci phpunit --fail-on-warning |
| 159 | + |
| 160 | + # Uncomment once Behat features are added under tests/behat/: |
| 161 | + # - name: Behat features |
| 162 | + # id: behat |
| 163 | + # if: ${{ !cancelled() }} |
| 164 | + # run: moodle-plugin-ci behat --profile chrome |
| 165 | + |
| 166 | + # - name: Upload Behat Faildump |
| 167 | + # if: ${{ failure() && steps.behat.outcome == 'failure' }} |
| 168 | + # uses: actions/upload-artifact@v4 |
| 169 | + # with: |
| 170 | + # name: Behat Faildump (${{ join(matrix.*, ', ') }}) |
| 171 | + # path: ${{ github.workspace }}/moodledata/behat_dump |
| 172 | + # retention-days: 7 |
| 173 | + # if-no-files-found: ignore |
| 174 | + |
| 175 | + - name: Mark cancelled jobs as failed. |
| 176 | + if: ${{ cancelled() }} |
| 177 | + run: exit 1 |
0 commit comments