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 9, 2024
1 parent 3c08516 commit 3853ff7
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 2 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 @@ -15,3 +15,6 @@
/rspec-report.xml
/rubocop-report.json
/sig

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/version_boss/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/main-branch/version_boss/actions/workflows/continuous-integration.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/44a42ed085fe162e5dff/maintainability)](https://codeclimate.com/github/main-branch/version_boss/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/44a42ed085fe162e5dff/test_coverage)](https://codeclimate.com/github/main-branch/version_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/version__boss-yellow.svg?logo=slack)](https://main-branch.slack.com/archives/C07MCMDBJLX)

Parse, compare, and increment Gem and [SemVer](https://semver.org) versions.
Expand Down Expand Up @@ -52,6 +54,8 @@ gem-version-boss help [COMMAND]
* [VersionBoss::Semver classes](#versionbosssemver-classes)
* [Development](#development)
* [Contributing](#contributing)
* [Commit message guidelines](#commit-message-guidelines)
* [Pull request guidelines](#pull-request-guidelines)
* [License](#license)
## Installation
Expand Down Expand Up @@ -209,6 +213,31 @@ commits and the created tag, and push the `.gem` file to
Bug reports and pull requests are welcome on GitHub at
https://github.com/main-branch/version_boss.
### 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
11 changes: 9 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/usr/bin/env bash

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
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 3853ff7

Please sign in to comment.