|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: GitHub Actions CI workflow file explained |
| 4 | +--- |
| 5 | + |
| 6 | +Below is the |
| 7 | +[gha.dist.yml](https://github.com/moodlehq/moodle-plugin-ci/blob/master/gha.dist.yml) |
| 8 | +file with comments added to explain what each section is doing. For additional |
| 9 | +information please refer to [workflow syntax reference](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions). |
| 10 | + |
| 11 | +If you are familiar with Travis, this should be strightforward to understand |
| 12 | +the syntax, you may find this [migration |
| 13 | +manual](https://docs.github.com/en/actions/learn-github-actions/migrating-from-travis-ci-to-github-actions) |
| 14 | +useful. |
| 15 | + |
| 16 | +```yaml |
| 17 | +# Title of the workflow |
| 18 | +name: Moodle Plugin CI |
| 19 | + |
| 20 | +# Run this workflow every time a new commit pushed to your repository or PR |
| 21 | +# created. |
| 22 | +on: [push, pull_request] |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Set the job key. The key is displayed as the job name |
| 26 | + # when a job name is not provided |
| 27 | + test: |
| 28 | + # Virtual environment to use. |
| 29 | + runs-on: ubuntu-18.04 |
| 30 | + |
| 31 | + # DB services you need for testing. |
| 32 | + services: |
| 33 | + postgres: |
| 34 | + image: postgres:9.6 |
| 35 | + env: |
| 36 | + POSTGRES_USER: 'postgres' |
| 37 | + POSTGRES_HOST_AUTH_METHOD: 'trust' |
| 38 | + ports: |
| 39 | + - 5432:5432 |
| 40 | + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 |
| 41 | + mariadb: |
| 42 | + image: mariadb:10 |
| 43 | + env: |
| 44 | + MYSQL_USER: 'root' |
| 45 | + MYSQL_ALLOW_EMPTY_PASSWORD: "true" |
| 46 | + ports: |
| 47 | + - 3306:3306 |
| 48 | + options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 |
| 49 | + |
| 50 | + # Determines build matrix. This is a list of PHP versions, databases and |
| 51 | + # branches to test our project against. For each combination a separate |
| 52 | + # build will be created. For example below 6 builds will be created in |
| 53 | + # total (7.2-pgsql, 7.2-mariadb, 7.3-pgsql, 7.3-mariadb, etc.). If we add |
| 54 | + # another branch, total number of builds will become 12. |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + matrix: |
| 58 | + php: ['7.2', '7.3', '7.4'] |
| 59 | + moodle-branch: ['MOODLE_310_STABLE'] |
| 60 | + database: [pgsql, mariadb] |
| 61 | + |
| 62 | + # There is an alterantive way allowing to define explicitly define which php, moodle-branch |
| 63 | + # and database to use: |
| 64 | + # |
| 65 | + # matrix: |
| 66 | + # include: |
| 67 | + # - php: '7.4' |
| 68 | + # moodle-branch: 'MOODLE_310_STABLE' |
| 69 | + # database: pgsql |
| 70 | + # - php: '7.3' |
| 71 | + # moodle-branch: 'MOODLE_310_STABLE' |
| 72 | + # database: mariadb |
| 73 | + # - php: '7.2' |
| 74 | + # moodle-branch: 'MOODLE_39_STABLE' |
| 75 | + # database: pgsql |
| 76 | + |
| 77 | + steps: |
| 78 | + # Check out this repository code in ./plugin directory |
| 79 | + - name: Check out repository code |
| 80 | + uses: actions/checkout@v2 |
| 81 | + with: |
| 82 | + path: plugin |
| 83 | + |
| 84 | + # Install PHP of required version. For possible options see https://github.com/shivammathur/setup-php |
| 85 | + - name: Setup PHP ${{ matrix.php }} |
| 86 | + uses: shivammathur/setup-php@v2 |
| 87 | + with: |
| 88 | + php-version: ${{ matrix.php }} |
| 89 | + coverage: none |
| 90 | + |
| 91 | + # Install this project into a directory called "ci", updating PATH and |
| 92 | + # locale. |
| 93 | + - name: Initialise moodle-plugin-ci |
| 94 | + run: | |
| 95 | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 |
| 96 | + echo $(cd ci/bin; pwd) >> $GITHUB_PATH |
| 97 | + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH |
| 98 | + sudo locale-gen en_AU.UTF-8 |
| 99 | +
|
| 100 | + # Run the default install. |
| 101 | + # Optionally, it is possible to specify a different Moodle repo to use |
| 102 | + # (git://github.com/moodle/moodle.git is used by default) and define |
| 103 | + # ignore directives or any other env vars for install step. |
| 104 | + # |
| 105 | + # env: |
| 106 | + # MOODLE_REPO=git://github.com/username/moodle.git |
| 107 | + # IGNORE_PATHS: 'ignore' |
| 108 | + # IGNORE_NAMES: 'ignore_name.php' |
| 109 | + # MUSTACHE_IGNORE_NAMES: 'broken.mustache' |
| 110 | + - name: Install moodle-plugin-ci |
| 111 | + run: | |
| 112 | + moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 |
| 113 | + env: |
| 114 | + DB: ${{ matrix.database }} |
| 115 | + MOODLE_BRANCH: ${{ matrix.moodle-branch }} |
| 116 | + |
| 117 | + # Steps that are run for the purpose of testing. Any of these steps |
| 118 | + # can be re-ordered or removed to your liking. And of course, you can |
| 119 | + # add any of your own custom steps. |
| 120 | + - name: PHP Lint |
| 121 | + if: ${{ always() }} # prevents CI run stopping if step failed. |
| 122 | + run: moodle-plugin-ci phplint |
| 123 | + |
| 124 | + - name: PHP Copy/Paste Detector |
| 125 | + continue-on-error: true # This step will show errors but will not fail |
| 126 | + if: ${{ always() }} |
| 127 | + run: moodle-plugin-ci phpcpd |
| 128 | + |
| 129 | + - name: PHP Mess Detector |
| 130 | + continue-on-error: true |
| 131 | + if: ${{ always() }} |
| 132 | + run: moodle-plugin-ci phpmd |
| 133 | + |
| 134 | + - name: Moodle Code Checker |
| 135 | + if: ${{ always() }} |
| 136 | + run: moodle-plugin-ci codechecker --max-warnings 0 |
| 137 | + |
| 138 | + - name: Moodle PHPDoc Checker |
| 139 | + if: ${{ always() }} |
| 140 | + run: moodle-plugin-ci phpdoc |
| 141 | + |
| 142 | + - name: Validating |
| 143 | + if: ${{ always() }} |
| 144 | + run: moodle-plugin-ci validate |
| 145 | + |
| 146 | + - name: Check upgrade savepoints |
| 147 | + if: ${{ always() }} |
| 148 | + run: moodle-plugin-ci savepoints |
| 149 | + |
| 150 | + - name: Mustache Lint |
| 151 | + if: ${{ always() }} |
| 152 | + run: moodle-plugin-ci mustache |
| 153 | + |
| 154 | + - name: Grunt |
| 155 | + if: ${{ always() }} |
| 156 | + run: moodle-plugin-ci grunt --max-lint-warnings 0 |
| 157 | + |
| 158 | + - name: PHPUnit tests |
| 159 | + if: ${{ always() }} |
| 160 | + run: moodle-plugin-ci phpunit |
| 161 | + |
| 162 | + - name: Behat features |
| 163 | + if: ${{ always() }} |
| 164 | + run: moodle-plugin-ci behat --profile chrome |
| 165 | +``` |
0 commit comments