Skip to content

Commit

Permalink
👷(project) add GitHub Actions CI workflow
Browse files Browse the repository at this point in the history
We set up a CI pipeline using GitHub Actions, adapted from
Moodle Plugin CI, to ensure adherence to best development practices.
  • Loading branch information
SergioSim committed Jul 9, 2024
1 parent be8af07 commit a5a04f3
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 0 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: IAGORA CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
php: ['8.3']
moodle-branch: ['MOODLE_404_STABLE']
database: [pgsql]

steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
path: plugins
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install gitlint
run: python -m pip install --user gitlint requests

- name: Lint commit messages
working-directory: plugin
run: ~/.local/bin/gitlint --commits origin/main..HEAD

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: max_input_vars=5000
coverage: xdebug

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- name: Install moodle-plugin-ci
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
# Uncomment this to run Behat tests using the Moodle App.
# MOODLE_APP: 'true'

- name: PHP Lint
if: ${{ !cancelled() }}
run: moodle-plugin-ci phplint

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail.
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpcs --max-warnings 0

- name: Moodle PHPDoc Checker
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpdoc --max-warnings 0

- name: Validating
if: ${{ !cancelled() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ !cancelled() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ !cancelled() }}
run: moodle-plugin-ci mustache

- name: Grunt
if: ${{ !cancelled() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpunit --fail-on-warning

- name: Behat features
id: behat
if: ${{ !cancelled() }}
run: moodle-plugin-ci behat --profile chrome

- name: Upload Behat Faildump
if: ${{ failure() && steps.behat.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: Behat Faildump (${{ join(matrix.*, ', ') }})
path: ${{ github.workspace }}/moodledata/behat_dump
retention-days: 1
if-no-files-found: ignore

- name: Mark cancelled jobs as failed.
if: ${{ cancelled() }}
run: exit 1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Byte-compiled / optimized / DLL files
__pycache__/
140 changes: 140 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Edit this file as you like.
#
# All these sections are optional. Each section with the exception of [general]
# represents one rule and each key in it is an option for that specific rule.
#
# Rules and sections can be referenced by their full name or by id. For example
# section "[body-max-line-length]" could also be written as "[B1]".
# Full section names are used in here for clarity.
#
[general]
# Ignore certain rules, this example uses both full name and id
# ignore=title-trailing-punctuation, T3

# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
# verbosity = 2

# By default gitlint will ignore merge, revert, fixup, fixup=amend, and squash commits.
ignore-merge-commits=false
ignore-revert-commits=false
ignore-fixup-commits=false
ignore-fixup-amend-commits=false
ignore-squash-commits=false

# Ignore any data sent to gitlint via stdin
# ignore-stdin=true

# Fetch additional meta-data from the local repository when manually passing a
# commit message to gitlint via stdin or --commit-msg. Disabled by default.
# staged=true

# Hard fail when the target commit range is empty. Note that gitlint will
# already fail by default on invalid commit ranges. This option is specifically
# to tell gitlint to fail on *valid but empty* commit ranges.
# Disabled by default.
# fail-without-commits=true

# Whether to use Python `search` instead of `match` semantics in rules that use
# regexes. Context: https://github.com/jorisroovers/gitlint/issues/254
# Disabled by default, but will be enabled by default in the future.
regex-style-search=true

# Enable debug mode (prints more output). Disabled by default.
# debug=true

# Enable community contributed rules
# See http://jorisroovers.github.io/gitlint/contrib_rules for details
contrib=contrib-disallow-cleanup-commits

# Set the extra-path where gitlint will search for user defined rules
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
extra-path=gitlint

# This is an example of how to configure the "title-max-length" rule and
# set the line-length it enforces to 50
# [title-max-length]
# line-length=50

# Conversely, you can also enforce minimal length of a title with the
# "title-min-length" rule:
# [title-min-length]
# min-length=50

[title-must-not-contain-word]
# Comma-separated list of words that should not occur in the title. Matching is case
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
# will not cause a violation, but "WIP: my title" will.
words=wip

# [title-match-regex]
# python-style regex that the commit-msg title must match
# Note that the regex can contradict with other rules if not used correctly
# (e.g. title-must-not-contain-word).
# regex=^US[0-9]*

# [body-max-line-length]
# line-length=72

# [body-min-length]
# min-length=5

[body-is-missing]
# Whether to ignore this rule on merge commits (which typically only have a title)
# default = True
# ignore-merge-commits=false

# [body-changed-file-mention]
# List of files that need to be explicitly mentioned in the body when they are changed
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly reference
# it in the commit message.
# files=gitlint-core/gitlint/rules.py,README.md

# [body-match-regex]
# python-style regex that the commit-msg body must match.
# E.g. body must end in My-Commit-Tag: foo
# regex=My-Commit-Tag: foo$

# [author-valid-email]
# python-style regex that the commit author email address must match.
# For example, use the following regex if you only want to allow email addresses from foo.com
# regex=[^@][email protected]

# [ignore-by-title]
# Ignore certain rules for commits of which the title matches a regex
# E.g. Match commit titles that start with "Release"
# regex=^Release(.*)

# Ignore certain rules, you can reference them by their id or by their full name
# Use 'all' to ignore all rules
# ignore=T1,body-min-length

# [ignore-by-body]
# Ignore certain rules for commits of which the body has a line that matches a regex
# E.g. Match bodies that have a line that that contain "release"
# regex=(.*)release(.*)
#
# Ignore certain rules, you can reference them by their id or by their full name
# Use 'all' to ignore all rules
# ignore=T1,body-min-length

# [ignore-body-lines]
# Ignore certain lines in a commit body that match a regex.
# E.g. Ignore all lines that start with 'Co-Authored-By'
# regex=^Co-Authored-By

# [ignore-by-author-name]
# Ignore certain rules for commits of which the author name matches a regex
# E.g. Match commits made by dependabot
# regex=(.*)dependabot(.*)
#
# Ignore certain rules, you can reference them by their id or by their full name
# Use 'all' to ignore all rules
# ignore=T1,body-min-length

# This is a contrib rule - a community contributed rule. These are disabled by default.
# You need to explicitly enable them one-by-one by adding them to the "contrib" option
# under [general] section above.
# [contrib-title-conventional-commits]
# Specify allowed commit types. For details see: https://www.conventionalcommits.org/
# types = bugfix,user-story,epic
43 changes: 43 additions & 0 deletions gitlint/gitlint_emoji.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Retrieved from https://github.com/openfun/ralph
"""
Gitlint extra rule to validate that the message title is of the form
"<gitmoji>(<scope>) <subject>"
"""

from __future__ import unicode_literals

import re

import requests

from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation


class GitmojiTitle(LineRule):
"""Gitmoji title rule.
This rule will enforce that each commit title is of the form
"<gitmoji>(<scope>) <subject>" where gitmoji is an emoji from the list
defined in https://gitmoji.carloscuesta.me and subject should be all
lowercase.
"""

id = "UC1"
name = "title-should-have-gitmoji-and-scope"
target = CommitMessageTitle

def validate(self, title, _commit):
"""Validate Gitmoji title rule.
Download the list possible gitmojis from the project's GitHub
repository and check that title contains one of them.
"""
gitmojis = requests.get(
"https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",
timeout=5,
).json()["gitmojis"]
emojis = [item["emoji"] for item in gitmojis]
pattern = r"^({:s})\(.*\)\s[a-z].*$".format("|".join(emojis))
if not re.search(pattern, title):
violation_msg = 'Title does not match regex "<gitmoji>(<scope>) <subject>"'
return [RuleViolation(self.id, violation_msg, title)]

0 comments on commit a5a04f3

Please sign in to comment.