diff --git a/.commitlintrc.json b/.commitlintrc.json new file mode 100644 index 00000000..cc01e52a --- /dev/null +++ b/.commitlintrc.json @@ -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" + ] + ] + } +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b738e4e..9ac645cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: pull_request: env: + DEFAULT_PYTHON: 3.11 SECRET_KEY: topsecret123 FIELD_ENCRYPTION_KEYS: f164ec6bd6fbc4aef5647abc15199da0f9badcc1d2127bde2087ae0d794a9a0b @@ -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 @@ -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 . diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index a70ba4ef..b9f16437 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ba8b1a53..6f12e8f1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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"] diff --git a/README.md b/README.md index 943963b9..9cb5d4d2 100644 --- a/README.md +++ b/README.md @@ -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: