Skip to content

Commit

Permalink
chore: add commitlint
Browse files Browse the repository at this point in the history
Also run coding style tools separately for concurrency and
to get all issues if one job fails.

Refs: HP-2314
  • Loading branch information
charn committed Apr 30, 2024
1 parent cfd93c9 commit bde9785
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 29 deletions.
39 changes: 39 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"extends": [
"@commitlint/config-conventional"
],
"rules": {
"header-max-length": [
2,
"always",
72
],
"body-max-line-length": [
2,
"always",
72
],
"body-leading-blank": [
2,
"always"
],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"deps",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test"
]
]
}
}
73 changes: 45 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:

env:
DEFAULT_PYTHON: 3.11
SECRET_KEY: topsecret123
FIELD_ENCRYPTION_KEYS: f164ec6bd6fbc4aef5647abc15199da0f9badcc1d2127bde2087ae0d794a9a0b

Expand Down Expand Up @@ -33,10 +34,10 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python 3.11
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: ${{ env.DEFAULT_PYTHON }}

- name: Cache pip packages
uses: actions/cache@v4
Expand Down Expand Up @@ -66,38 +67,54 @@ jobs:
- name: Database sanitizer config
run: ./manage.py check_sanitizerconfig

coding-style:
name: Coding style
commitlint:
name: Commitlint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check commitlint
uses: wagoid/commitlint-github-action@0d749a1a91d4770e983a7b8f83d4a3f0e7e0874e # v5.4.4

black:
name: Coding style - black
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Run black
uses: psf/black@stable
with:
options: "--check"

- name: Set up Python 3.11
flake8:
name: Coding style - flake8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install dependencies
run: pip install flake8 pep8-naming -c requirements-dev.txt
- name: Run flake8
uses: liskin/gh-problem-matcher-wrap@v3
with:
linters: flake8
run: flake8

- name: Cache pip packages
uses: actions/cache@v4
env:
cache-name: cache-pip-modules
isort:
name: Coding style - isort
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
path: ~/.pip-cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('**/requirements-dev.txt') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install dependencies
run: pip install -r requirements.txt -r requirements-dev.txt

- name: Linting
run: flake8

- name: Import sorting
run: isort . --check --diff

- name: Formatting
run: black --check .
run: pip install isort -c requirements-dev.txt
- name: Run isort
uses: liskin/gh-problem-matcher-wrap@v3
with:
linters: isort
run: isort -c .
2 changes: 1 addition & 1 deletion .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
default_language_version:
python: python3
default_install_hook_types: [pre-commit, commit-msg]
default_stages: [pre-commit, manual]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand All @@ -25,3 +27,9 @@ repos:
hooks:
- id: isort
exclude: "migrations|snapshots"
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.10.0
hooks:
- id: commitlint
stages: [commit-msg, manual]
additional_dependencies: ["@commitlint/config-conventional"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ run all the formatting tools as git hooks automatically before a
commit.


## Commit message format

New commit messages must adhere to the [Conventional Commits](https://www.conventionalcommits.org/)
specification, and line length is limited to 72 characters.

When [`pre-commit`](https://pre-commit.com/) is in use, [`commitlint`](https://github.com/conventional-changelog/commitlint)
checks new commit messages for the correct format.


## Running tests

The tests require a Postgres database to which to connect to. Here's one way to run the tests:
Expand Down

0 comments on commit bde9785

Please sign in to comment.