Skip to content

Commit

Permalink
build: enforce conventional commit message formatting
Browse files Browse the repository at this point in the history
1. Add a git commit-msg hook to validate commit messages as they are made
2. Add a GitHub workflow to validate that all commits in a PR conform to conventional commits
  • Loading branch information
jcouball committed Oct 10, 2024
1 parent e5f91d1 commit 05918a3
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .commitlintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
extends: '@commitlint/config-conventional'

rules:
# See: https://commitlint.js.org/reference/rules.html
#
# Rules are made up by a name and a configuration array. The configuration array contains:
#
# * Severity [0..2]: 0 disable rule, 1 warning if violated, or 2 error if violated
# * Applicability [always|never]: never inverts the rule
# * Value: value to use for this rule
#
# Run `npx commitlint --print-config` to see the current setting for all rules.
#
body-leading-blank: [2, 'always']
footer-leading-blank: [2, 'always']
21 changes: 21 additions & 0 deletions .github/workflows/enforce_conventional_commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Conventional Commits

on:
pull_request:
branches:
- main

jobs:
commit-lint:
name: Verify Conventional Commits

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with: { fetch-depth: 0 }

- name: Check Commit Messages
uses: wagoid/commitlint-github-action@v6
with: { configFile: .commitlintrc.yml }
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
/rubocop-report.json

/.yarddoc

node_modules
package-lock.json
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no-install commitlint --edit "$1"
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[![Build Status](https://github.com/main-branch/command_line_boss/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/main-branch/command_line_boss/actions/workflows/continuous_integration.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/513b4d8d95a5e3a77ec6/maintainability)](https://codeclimate.com/github/main-branch/command_line_boss/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/513b4d8d95a5e3a77ec6/test_coverage)](https://codeclimate.com/github/main-branch/command_line_boss/test_coverage)
[![Conventional
Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
[![Slack](https://img.shields.io/badge/slack-main--branch/command__line__boss-yellow.svg?logo=slack)](https://main-branch.slack.com/archives/C07MQC0LNKF)

`command_line_boss` makes it easy to build, test, and maintain complex command line
Expand Down Expand Up @@ -33,6 +35,8 @@ Other good alternatives also exist.
* [Run the command line](#run-the-command-line)
* [Development](#development)
* [Contributing](#contributing)
* [Commit message guidelines](#commit-message-guidelines)
* [Pull request guidelines](#pull-request-guidelines)
* [License](#license)
* [Code of Conduct](#code-of-conduct)

Expand Down Expand Up @@ -354,6 +358,31 @@ safe, welcoming space for collaboration, and contributors are expected to adhere
the [code of
conduct](https://github.com/main_branch/command_line_boss/blob/main/CODE_OF_CONDUCT.md).

### Commit message guidelines

All commit messages must follow the [Conventional Commits
standard](https://www.conventionalcommits.org/en/v1.0.0/). This helps us maintain a
clear and structured commit history, automate versioning, and generate changelogs
effectively.

To ensure compliance, this project includes:

* A git commit-msg hook that validates your commit messages before they are accepted.

To activate the hook, you must have node installed and run `npm install`.

* A GitHub Actions workflow that will enforce the Conventional Commit standard as
part of the continuous integration pipeline.

Any commit message that does not conform to the Conventional Commits standard will
cause the workflow to fail and not allow the PR to be merged.

### Pull request guidelines

All pull requests must be merged using rebase merges. This ensures that commit
messages from the feature branch are preserved in the release branch, keeping the
history clean and meaningful.

## License

The gem is available as open source under the terms of the [MIT
Expand Down
13 changes: 11 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/usr/bin/env bash

# Same setup script for Ruby projects that also installs the conventional commit git hook

set -euo pipefail
IFS=$'\n\t'
set -vx

# set -vx

bundle install

# Do any other automated setup that you need to do here
if [ -x "$(command -v npm)" ]; then
npm install
else
echo "npm is not installed"
echo "Install npm then re-run this script to enable the conventional commit git hook."
fi
2 changes: 1 addition & 1 deletion command_line_boss.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Gem::Specification.new do |spec|

spec.add_dependency 'logger', '~> 1.6'
spec.add_development_dependency 'bundler-audit', '~> 0.9'
spec.add_development_dependency 'create_github_release', '~> 1.5'
spec.add_development_dependency 'create_github_release', '~> 2.1'
spec.add_development_dependency 'csv', '~> 3.3'
spec.add_development_dependency 'fuubar', '~> 2.5'
spec.add_development_dependency 'main_branch_shared_rubocop_config', '~> 0.1'
Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"devDependencies": {
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"husky": "^9.1.0"
},
"scripts": {
"postinstall": "husky",
"prepare": "husky"
}
}

0 comments on commit 05918a3

Please sign in to comment.