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 11, 2024
1 parent 70c72f9 commit 9234cb0
Show file tree
Hide file tree
Showing 8 changed files with 91 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 @@ -14,3 +14,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/discovery_v1/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/main-branch/discovery_v1/actions/workflows/continuous_integration.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/aeebc016487c5cad881e/maintainability)](https://codeclimate.com/github/main-branch/discovery_v1/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/aeebc016487c5cad881e/test_coverage)](https://codeclimate.com/github/main-branch/discovery_v1/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/discovery__v1-yellow.svg?logo=slack)](https://main-branch.slack.com/archives/C07MT5MG7V1)

Unofficial helpers and extensions for the Google Discovery V1 API
Expand Down Expand Up @@ -33,6 +35,8 @@ Gems in the Google API helper, extensions, and examples series:
* [RestDescription Extensions](#restdescription-extensions)
* [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 @@ -201,6 +205,31 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/discovery_v1. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/discovery_v1/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 License](https://opensource.org/licenses/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
2 changes: 1 addition & 1 deletion discovery_v1.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

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 'main_branch_shared_rubocop_config', '~> 0.1'
spec.add_development_dependency 'rake', '~> 13.2'
spec.add_development_dependency 'rspec', '~> 3.13'
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 9234cb0

Please sign in to comment.