From b3854eaf4143374a90f1fc67cc4ec3ea644e2fcd Mon Sep 17 00:00:00 2001 From: Adam Bovill Date: Fri, 18 Feb 2022 14:52:02 +1300 Subject: [PATCH] ci(pre-commit): enforce conventional-commits message structure This adds pre-commit and ci checks to ensure that commit messages follow [`conventional-commits`](https://www.conventionalcommits.org/en/v1.0.0/). From their site: Conventional Commits is: `A specification for adding human and machine readable meaning to commit messages` Commit messages must follow the following format: ``` [optional scope]: [optional body] [optional footer(s)] ``` In general, this means that you will provide a topic: * feat * fix * ci * refactor Followed by a description. Following this standard allows for automatic semantic versioning and release note generation. * `.commitlintrc.yaml` - defines the commit message format for linting * `.cz.json` - configuration for [`commitizen-cli`](http://commitizen.github.io/cz-cli/) --- .commitlintrc.yaml | 2 ++ .cz.json | 4 ++++ .github/workflows/ci.yaml | 3 +++ .pre-commit-config.yaml | 6 ++++++ README.md | 14 ++++++++++++++ 5 files changed, 29 insertions(+) create mode 100644 .commitlintrc.yaml create mode 100644 .cz.json diff --git a/.commitlintrc.yaml b/.commitlintrc.yaml new file mode 100644 index 00000000..9cb74a70 --- /dev/null +++ b/.commitlintrc.yaml @@ -0,0 +1,2 @@ +extends: + - "@commitlint/config-conventional" diff --git a/.cz.json b/.cz.json new file mode 100644 index 00000000..03a5bc9c --- /dev/null +++ b/.cz.json @@ -0,0 +1,4 @@ +{ + "maxHeaderWidth": 72, + "path": "cz-conventional-changelog" +} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b494af85..7a008dd1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,9 +12,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v2 with: go-version: 1.15 - uses: actions/setup-python@v2 - uses: pre-commit/action@v2.0.0 + - uses: wagoid/commitlint-github-action@v2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a8bb970f..bf54a6ce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,3 +20,9 @@ repos: - id: go-fmt - id: go-mod-tidy - id: go-build + - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + rev: v5.0.0 + hooks: + - id: commitlint + stages: [commit-msg] + additional_dependencies: ["@commitlint/config-conventional"] diff --git a/README.md b/README.md index 158f9ea4..ab7ddc02 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,20 @@ the hooks by running the following command in the root of the repository: pre-commit install ``` +This repository following `Conventional Commits` for message formatting. +See: https://www.conventionalcommits.org/en/v1.0.0/ + +``` +[optional scope]: + +[optional body] + +[optional footer(s)] +``` + +You can use commitizen to help generate commit messages. +See: http://commitizen.github.io/cz-cli/ + ### Running Project Built Locally #### Terraform v0.12