From 257bdd0658a17775f314506b69b3d40ee6e68cc3 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 | 11 +++++-- commitlint.config.js | 49 +++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 2 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..e0d905fff9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,7 +12,6 @@ First off, thank you for taking the time to contribute to Minder! :+1: :tada: Mi - [Pull Request Process](#pull-request-process) - [Contributing to docs](#contributing-to-docs) - [Commit Message Guidelines](#commit-message-guidelines) - ## Code of Conduct This project adheres to the [Contributor Covenant](https://github.com/stacklok/minder/blob/main/CODE_OF_CONDUCT.md) code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to code-of-conduct@stacklok.dev. @@ -48,4 +47,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..4c2ccc310f --- /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: [ + // Ignores Dependabot and WIP commits + (message) => message.includes('build(') || message.includes('WIP') + ] +};