diff --git a/.commitlintrc.yml b/.commitlintrc.yml new file mode 100644 index 0000000..9840b68 --- /dev/null +++ b/.commitlintrc.yml @@ -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'] diff --git a/.github/workflows/enforce_conventional_commits.yml b/.github/workflows/enforce_conventional_commits.yml new file mode 100644 index 0000000..a3e1a5d --- /dev/null +++ b/.github/workflows/enforce_conventional_commits.yml @@ -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 } diff --git a/.gitignore b/.gitignore index df8bd6b..cf4e9eb 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ /rspec-report.xml /rubocop-report.json /sig + +node_modules +package-lock.json diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 0000000..70bd3dd --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +npx --no-install commitlint --edit "$1" diff --git a/README.md b/README.md index 8584b26..30ceec4 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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 diff --git a/bin/setup b/bin/setup index dce67d8..2b9f99b 100755 --- a/bin/setup +++ b/bin/setup @@ -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 diff --git a/package.json b/package.json new file mode 100644 index 0000000..0f10c3e --- /dev/null +++ b/package.json @@ -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" + } +}