Skip to content

Commit 1c5f446

Browse files
committed
build: enforce conventional commit message formatting
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
1 parent 1b7e633 commit 1c5f446

File tree

8 files changed

+93
-4
lines changed

8 files changed

+93
-4
lines changed

.commitlintrc.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
extends: '@commitlint/config-conventional'
3+
4+
rules:
5+
# See: https://commitlint.js.org/reference/rules.html
6+
#
7+
# Rules are made up by a name and a configuration array. The configuration array contains:
8+
#
9+
# * Severity [0..2]: 0 disable rule, 1 warning if violated, or 2 error if violated
10+
# * Applicability [always|never]: never inverts the rule
11+
# * Value: value to use for this rule
12+
#
13+
# Run `npx commitlint --print-config` to see the current setting for all rules.
14+
#
15+
body-leading-blank: [2, 'always']
16+
footer-leading-blank: [2, 'always']
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Conventional Commits
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
commit-lint:
10+
name: Verify Conventional Commits
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with: { fetch-depth: 0 }
18+
19+
- name: Check Commit Messages
20+
uses: wagoid/commitlint-github-action@v6
21+
with: { configFile: .commitlintrc.yml }

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
/rspec-report.xml
1414
/rubocop-report.json
1515
sig/**/*
16+
17+
node_modules
18+
package-lock.json

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no-install commitlint --edit "$1"

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
[![Build Status](https://github.com/main-branch/create_github_release/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/main-branch/create_github_release/actions/workflows/continuous_integration.yml)
77
[![Maintainability](https://api.codeclimate.com/v1/badges/b8c0af10b15a0ffeb1a1/maintainability)](https://codeclimate.com/github/main-branch/create_github_release/maintainability)
88
[![Test Coverage](https://api.codeclimate.com/v1/badges/b8c0af10b15a0ffeb1a1/test_coverage)](https://codeclimate.com/github/main-branch/create_github_release/test_coverage)
9+
[![Conventional
10+
Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
911
[![Slack](https://img.shields.io/badge/slack-main--branch/create__github__release-yellow.svg?logo=slack)](https://main-branch.slack.com/archives/C07NG282N80)
1012

1113
When run in your gem's git worktree, the `create-github-release` script does the
@@ -40,6 +42,8 @@ Tested on Ruby 3.0+
4042
* [How is the changelog updated?](#how-is-the-changelog-updated)
4143
* [Development](#development)
4244
* [Contributing](#contributing)
45+
* [Commit message guidelines](#commit-message-guidelines)
46+
* [Pull request guidelines](#pull-request-guidelines)
4347
* [License](#license)
4448

4549
## Installation
@@ -401,6 +405,31 @@ To install this gem onto your current Ruby environment, run `bundle exec rake in
401405
Bug reports and pull requests are welcome on
402406
[this project's GitHub page](https://github.com/main-branch/create_github_release)
403407

408+
### Commit message guidelines
409+
410+
All commit messages must follow the [Conventional Commits
411+
standard](https://www.conventionalcommits.org/en/v1.0.0/). This helps us maintain a
412+
clear and structured commit history, automate versioning, and generate changelogs
413+
effectively.
414+
415+
To ensure compliance, this project includes:
416+
417+
* A git commit-msg hook that validates your commit messages before they are accepted.
418+
419+
To activate the hook, you must have node installed and run `npm install`.
420+
421+
* A GitHub Actions workflow that will enforce the Conventional Commit standard as
422+
part of the continuous integration pipeline.
423+
424+
Any commit message that does not conform to the Conventional Commits standard will
425+
cause the workflow to fail and not allow the PR to be merged.
426+
427+
### Pull request guidelines
428+
429+
All pull requests must be merged using rebase merges. This ensures that commit
430+
messages from the feature branch are preserved in the release branch, keeping the
431+
history clean and meaningful.
432+
404433
## License
405434

406435
The gem is available as open source under the terms of the

bin/setup

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#!/usr/bin/env bash
2+
23
set -euo pipefail
34
IFS=$'\n\t'
4-
set -vx
5+
6+
# set -vx
57

68
bundle install
79

8-
# Do any other automated setup that you need to do here
10+
if [ -x "$(command -v npm)" ]; then
11+
npm install
12+
else
13+
echo "npm is not installed"
14+
echo "Install npm then re-run this script to enable the conventional commit git hook."
15+
fi

create_github_release.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ Gem::Specification.new do |spec|
4040
'Ruby: MRI 3.1 or later, TruffleRuby 24 or later, or JRuby 9.4 or later'
4141
]
4242

43-
spec.add_dependency 'command_line_boss', '~> 0.1'
44-
spec.add_dependency 'version_boss', '~> 0.1'
43+
spec.add_dependency 'command_line_boss', '~> 0.2'
44+
spec.add_dependency 'version_boss', '~> 0.2'
4545

4646
spec.add_development_dependency 'bundler-audit', '~> 0.9'
47+
spec.add_development_dependency 'create_github_release', '~> 2.1'
4748
# spec.add_development_dependency 'debug', '~> 1.9'
4849
spec.add_development_dependency 'logger', '~> 1.6'
4950
spec.add_development_dependency 'main_branch_shared_rubocop_config', '~> 0.1'

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"devDependencies": {
3+
"@commitlint/cli": "^19.5.0",
4+
"@commitlint/config-conventional": "^19.5.0",
5+
"husky": "^9.1.0"
6+
},
7+
"scripts": {
8+
"postinstall": "husky",
9+
"prepare": "husky"
10+
}
11+
}

0 commit comments

Comments
 (0)