1 |
efrain |
1 |
# Runs tests and code analysis.
|
|
|
2 |
# Based on:
|
|
|
3 |
# https://github.com/moodlehq/moodle-plugin-ci/blob/main/gha.dist.yml
|
|
|
4 |
|
|
|
5 |
# Title of the workflow
|
|
|
6 |
name: Moodle Plugin CI
|
|
|
7 |
|
|
|
8 |
# Run this workflow every time a new commit pushed to your repository or PR created.
|
|
|
9 |
on: [push, pull_request]
|
|
|
10 |
|
|
|
11 |
# Give just enough permissions to fetch code (actions/checkout).
|
|
|
12 |
permissions:
|
|
|
13 |
contents: read
|
|
|
14 |
|
|
|
15 |
jobs:
|
|
|
16 |
# Set the job key. The key is displayed as the job name when a job name is not provided
|
|
|
17 |
test:
|
|
|
18 |
# Virtual environment to use.
|
|
|
19 |
runs-on: ubuntu-22.04
|
|
|
20 |
|
|
|
21 |
# DB services you need for testing.
|
|
|
22 |
services:
|
|
|
23 |
postgres:
|
|
|
24 |
image: postgres:13
|
|
|
25 |
env:
|
|
|
26 |
POSTGRES_USER: 'postgres'
|
|
|
27 |
POSTGRES_HOST_AUTH_METHOD: 'trust'
|
|
|
28 |
ports:
|
|
|
29 |
- 5432:5432
|
|
|
30 |
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
|
|
|
31 |
|
|
|
32 |
mariadb:
|
|
|
33 |
image: mariadb:10.6.7
|
|
|
34 |
env:
|
|
|
35 |
MYSQL_USER: 'root'
|
|
|
36 |
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
|
|
|
37 |
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
|
|
|
38 |
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
|
|
|
39 |
ports:
|
|
|
40 |
- 3306:3306
|
|
|
41 |
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
|
|
|
42 |
|
|
|
43 |
# Determines build matrix. This is a list of PHP versions, databases and
|
|
|
44 |
# branches to test our project against. For each combination a separate
|
|
|
45 |
# build will be created. For example below, builds will be created in
|
|
|
46 |
# total (7.4-pgsql, 7.4-mariadb, 8.0-pgsql, 8.0-mariadb, etc.).
|
|
|
47 |
strategy:
|
|
|
48 |
fail-fast: false
|
|
|
49 |
matrix:
|
|
|
50 |
include:
|
|
|
51 |
# Next version of Moodle (main).
|
|
|
52 |
# - php: '8.3'
|
|
|
53 |
# moodle-branch: 'main'
|
|
|
54 |
# database: 'pgsql'
|
|
|
55 |
# - php: '8.3'
|
|
|
56 |
# moodle-branch: 'main'
|
|
|
57 |
# database: 'mariadb'
|
|
|
58 |
# - php: '8.2'
|
|
|
59 |
# moodle-branch: 'main'
|
|
|
60 |
# database: 'mariadb'
|
|
|
61 |
# Moodle 4.4.x (MOODLE_404_STABLE).
|
|
|
62 |
- php: '8.3'
|
|
|
63 |
moodle-branch: 'MOODLE_404_STABLE'
|
|
|
64 |
database: 'pgsql'
|
|
|
65 |
- php: '8.3'
|
|
|
66 |
moodle-branch: 'MOODLE_404_STABLE'
|
|
|
67 |
database: 'mariadb'
|
|
|
68 |
- php: '8.2'
|
|
|
69 |
moodle-branch: 'MOODLE_404_STABLE'
|
|
|
70 |
database: 'mariadb'
|
|
|
71 |
- php: '8.1'
|
|
|
72 |
moodle-branch: 'MOODLE_404_STABLE'
|
|
|
73 |
database: 'pgsql'
|
|
|
74 |
# Moodle 4.3.x (MOODLE_403_STABLE).
|
|
|
75 |
- php: '8.2'
|
|
|
76 |
moodle-branch: 'MOODLE_403_STABLE'
|
|
|
77 |
database: 'pgsql'
|
|
|
78 |
- php: '8.0'
|
|
|
79 |
moodle-branch: 'MOODLE_403_STABLE'
|
|
|
80 |
database: 'mariadb'
|
|
|
81 |
# Moodle 4.2.x (MOODLE_402_STABLE).
|
|
|
82 |
- php: '8.2'
|
|
|
83 |
moodle-branch: 'MOODLE_402_STABLE'
|
|
|
84 |
database: 'mariadb'
|
|
|
85 |
- php: '8.0'
|
|
|
86 |
moodle-branch: 'MOODLE_402_STABLE'
|
|
|
87 |
database: 'pgsql'
|
|
|
88 |
# Moodle 4.1.x (MOODLE_401_STABLE).
|
|
|
89 |
- php: '8.1'
|
|
|
90 |
moodle-branch: 'MOODLE_401_STABLE'
|
|
|
91 |
database: 'pgsql'
|
|
|
92 |
- php: '7.4'
|
|
|
93 |
moodle-branch: 'MOODLE_401_STABLE'
|
|
|
94 |
database: 'mariadb'
|
|
|
95 |
|
|
|
96 |
steps:
|
|
|
97 |
# Check out this repository code in ./plugin directory
|
|
|
98 |
- name: Check out repository code
|
|
|
99 |
uses: actions/checkout@v4
|
|
|
100 |
with:
|
|
|
101 |
path: plugin
|
|
|
102 |
|
|
|
103 |
# Install PHP of required version. For possible options see https://github.com/shivammathur/setup-php
|
|
|
104 |
- name: Setup PHP ${{ matrix.php }}
|
|
|
105 |
uses: shivammathur/setup-php@v2
|
|
|
106 |
with:
|
|
|
107 |
php-version: ${{ matrix.php }}
|
|
|
108 |
extensions: ${{ matrix.extensions }}
|
|
|
109 |
ini-values: max_input_vars=6000
|
|
|
110 |
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
|
|
|
111 |
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
|
|
|
112 |
coverage: pcov
|
|
|
113 |
|
|
|
114 |
# Install this project into a directory called "ci", updating PATH and locale, define nvm location.
|
|
|
115 |
- name: Initialise moodle-plugin-ci
|
|
|
116 |
run: |
|
|
|
117 |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
|
|
|
118 |
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
|
|
|
119 |
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
|
|
|
120 |
sudo locale-gen en_AU.UTF-8
|
|
|
121 |
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
|
|
|
122 |
|
|
|
123 |
# Run the default install.
|
|
|
124 |
# Optionally, it is possible to specify a different Moodle repo to use
|
|
|
125 |
# (https://github.com/moodle/moodle.git is used by default) and define
|
|
|
126 |
# ignore directives or any other env vars for install step. For more
|
|
|
127 |
# details on configuring for specific requirements please refer to the
|
|
|
128 |
# 'Help' page.
|
|
|
129 |
#
|
|
|
130 |
# env:
|
|
|
131 |
# MOODLE_REPO=https://github.com/username/moodle.git
|
|
|
132 |
# IGNORE_PATHS: 'ignore'
|
|
|
133 |
# IGNORE_NAMES: 'ignore_name.php'
|
|
|
134 |
# MUSTACHE_IGNORE_NAMES: 'broken.mustache'
|
|
|
135 |
# CODECHECKER_IGNORE_PATHS: 'ignoreme'
|
|
|
136 |
# CODECHECKER_IGNORE_NAMES: 'ignoreme_name.php'
|
|
|
137 |
#
|
|
|
138 |
# Other env vars are available for install, namely:
|
|
|
139 |
# - DB_USER / DB_PASS / DB_NAME / DB_HOST / DB_PORT: used
|
|
|
140 |
# by install to feed the corresponding --db-xxxx options.
|
|
|
141 |
# - MOODLE_APP: used to install dependencies to run Behat tests
|
|
|
142 |
# using the Moodle App.
|
|
|
143 |
- name: Install moodle-plugin-ci
|
|
|
144 |
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
|
|
|
145 |
env:
|
|
|
146 |
DB: ${{ matrix.database }}
|
|
|
147 |
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
|
|
|
148 |
# Uncomment this to run Behat tests using the Moodle App.
|
|
|
149 |
# MOODLE_APP: 'true'
|
|
|
150 |
|
|
|
151 |
# Steps that are run for the purpose of testing. Any of these steps
|
|
|
152 |
# can be re-ordered or removed to your liking. And of course, you can
|
|
|
153 |
# add any of your own custom steps.
|
|
|
154 |
- name: PHP Lint
|
|
|
155 |
continue-on-error: true # This step will show errors but will not fail
|
|
|
156 |
if: ${{ !cancelled() }}
|
|
|
157 |
run: moodle-plugin-ci phplint
|
|
|
158 |
|
|
|
159 |
- name: PHP Copy/Paste Detector
|
|
|
160 |
continue-on-error: true # This step will show errors but will not fail
|
|
|
161 |
if: ${{ !cancelled() }}
|
|
|
162 |
run: moodle-plugin-ci phpcpd
|
|
|
163 |
|
|
|
164 |
- name: PHP Mess Detector
|
|
|
165 |
continue-on-error: true # This step will show errors but will not fail
|
|
|
166 |
if: ${{ !cancelled() }}
|
|
|
167 |
run: moodle-plugin-ci phpmd
|
|
|
168 |
|
|
|
169 |
- name: Moodle Code Checker
|
|
|
170 |
continue-on-error: true # This step will show errors but will not fail
|
|
|
171 |
if: ${{ !cancelled() }}
|
|
|
172 |
run: moodle-plugin-ci phpcs --max-warnings 0
|
|
|
173 |
|
|
|
174 |
- name: Moodle PHPDoc Checker
|
|
|
175 |
continue-on-error: true # This step will show errors but will not fail
|
|
|
176 |
if: ${{ !cancelled() }}
|
|
|
177 |
run: moodle-plugin-ci phpdoc --max-warnings 0
|
|
|
178 |
|
|
|
179 |
- name: Validating
|
|
|
180 |
continue-on-error: true # This step will show errors but will not fail
|
|
|
181 |
if: ${{ !cancelled() }}
|
|
|
182 |
run: moodle-plugin-ci validate
|
|
|
183 |
|
|
|
184 |
- name: Check upgrade savepoints
|
|
|
185 |
if: ${{ !cancelled() }}
|
|
|
186 |
run: moodle-plugin-ci savepoints
|
|
|
187 |
|
|
|
188 |
# This plugin does not use Mustache templates.
|
|
|
189 |
# - name: Mustache Lint
|
|
|
190 |
# if: ${{ !cancelled() }}
|
|
|
191 |
# run: moodle-plugin-ci mustache
|
|
|
192 |
|
|
|
193 |
- name: Grunt
|
|
|
194 |
continue-on-error: true # This step will show errors but will not fail
|
|
|
195 |
if: ${{ !cancelled() }}
|
|
|
196 |
run: moodle-plugin-ci grunt --max-lint-warnings 0
|
|
|
197 |
|
|
|
198 |
- name: PHPUnit tests
|
|
|
199 |
continue-on-error: true # This step will show errors but will not fail
|
|
|
200 |
if: ${{ !cancelled() }}
|
|
|
201 |
run: moodle-plugin-ci phpunit --fail-on-warning
|
|
|
202 |
|
|
|
203 |
# - name: Behat features
|
|
|
204 |
# id: behat
|
|
|
205 |
# if: ${{ !cancelled() }}
|
|
|
206 |
# run: moodle-plugin-ci behat --profile chrome
|
|
|
207 |
|
|
|
208 |
# This step allows to upload Behat faildump (screenshots) as workflow artifact
|
|
|
209 |
# so it can be downloaded and inspected. You don't need this step if you
|
|
|
210 |
# are not running Behat test. Artifact will be retained for 7 days.
|
|
|
211 |
|
|
|
212 |
# - name: Upload Behat Faildump
|
|
|
213 |
# if: ${{ failure() && steps.behat.outcome == 'failure' }}
|
|
|
214 |
# uses: actions/upload-artifact@v4
|
|
|
215 |
# with:
|
|
|
216 |
# name: Behat Faildump (${{ join(matrix.*, ', ') }})
|
|
|
217 |
# path: ${{ github.workspace }}/moodledata/behat_dump
|
|
|
218 |
# retention-days: 7
|
|
|
219 |
# if-no-files-found: ignore
|
|
|
220 |
|
|
|
221 |
- name: Mark cancelled jobs as failed.
|
|
|
222 |
if: ${{ cancelled() }}
|
|
|
223 |
run: exit 1
|