From 9fceca3fcdd4366324550a5b909ea9ba7f3901b9 Mon Sep 17 00:00:00 2001 From: Andres Galante <1832037+andresgalante@users.noreply.github.com> Date: Thu, 30 Nov 2023 10:09:42 -0300 Subject: [PATCH] Add commitlint to the CI --- .github/workflows/commit-lint.yml | 13 ++++++++ .github/workflows/pr.yml | 2 ++ CONTRIBUTING.md | 30 ++++++++++++------- commitlint.config.js | 49 +++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/commit-lint.yml create mode 100644 commitlint.config.js diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml new file mode 100644 index 0000000000..020bb0780e --- /dev/null +++ b/.github/workflows/commit-lint.yml @@ -0,0 +1,13 @@ +name: Lint Commit Messages + +on: + workflow_call: + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: wagoid/commitlint-github-action@v5 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 00b72071fb..75ed6d55dd 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -36,3 +36,5 @@ jobs: uses: ./.github/workflows/security.yml compose-migrate: uses: ./.github/workflows/compose-migrate.yml + commit-lint: + uses: ./.github/workflows/commit-lint.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 370e596e63..11db574f37 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,15 +3,17 @@ First off, thank you for taking the time to contribute to Minder! :+1: :tada: Minder is released under the Apache 2.0 license. If you would like to contribute something or want to hack on the code, this document should help you get started. You can find some hints for starting development in Minder's [README](https://github.com/stacklok/minder/blob/main/README.md). ## Table of contents -- [Code of Conduct](#code-of-conduct) -- [Reporting Security Vulnerabilities](#reporting-security-vulnerabilities) -- [How to Contribute](#how-to-contribute) - - [Sign the Contributor License Agreement](#sign-the-contributor-license-agreement) - - [Using GitHub Issues](#using-github-issues) - - [Not sure how to start contributing...](#not-sure-how-to-start-contributing) - - [Pull Request Process](#pull-request-process) - - [Contributing to docs](#contributing-to-docs) - - [Commit Message Guidelines](#commit-message-guidelines) +- [Contributing to Minder](#contributing-to-minder) + - [Table of contents](#table-of-contents) + - [Code of Conduct](#code-of-conduct) + - [Reporting Security Vulnerabilities](#reporting-security-vulnerabilities) + - [How to Contribute](#how-to-contribute) + - [Using GitHub Issues](#using-github-issues) + - [Sign the Contributor License Agreement](#sign-the-contributor-license-agreement) + - [Not sure how to start contributing...](#not-sure-how-to-start-contributing) + - [Pull Request Process](#pull-request-process) + - [Contributing to docs](#contributing-to-docs) + - [Commit Message Guidelines](#commit-message-guidelines) ## Code of Conduct @@ -48,4 +50,12 @@ PRs to resolve existing issues are greatly appreciated and issues labeled as ["g Follow [this guide](https://github.com/stacklok/minder/blob/main/docs/README.md) for instructions on building, running, and previewing Miner's documentation. ### Commit Message Guidelines -We follow the commit formatting recommendations found on [Chris Beams' How to Write a Git Commit Message article](https://chris.beams.io/posts/git-commit/). \ No newline at end of file +We follow the commit formatting recommendations found on [Chris Beams' How to Write a Git Commit Message article](https://chris.beams.io/posts/git-commit/): + +1. Separate subject from body with a blank line +1. Limit the subject line to 50 characters +1. Capitalize the subject line +1. Do not end the subject line with a period +1. Use the imperative mood in the subject line +1. Wrap the body at 72 characters +1. Use the body to explain what and why vs. how \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000000..d87cf8a6fa --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,49 @@ +// +// Copyright 2023 Stacklok, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +module.exports = { + + // This config should help enforce Chris Bean's commit message recommendations + + + rules: { + + // Separate subject from body with a blank line + 'body-leading-blank': [2, 'always'], + + // - Limit the subject line to 50 characters + 'header-max-length': [2, 'always', 50], + + // Capitalize the subject line + 'header-case': [2, 'always', 'sentence-case'], + 'subject-case': [2, 'always', 'sentence-case'], + + // Do not end the subject line with a period + 'header-full-stop': [2, 'never'], + 'subject-full-stop': [0, 'never'], + + // Wrap the body at 72 characters + 'body-max-line-length': [2, 'always', 75], + + 'type-empty': [2, 'always'], // Disallow types + + // TODO: write plugins to check for: + // Use the imperative mood in the subject line + // Use the body to explain what and why vs. how + }, + ignores: [ + (message) => message.includes('build(') || message.includes('WIP') + ] +};