Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing commitlint #26

Merged
merged 6 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
module.exports = {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'body-leading-blank': [1, 'always'],
'body-max-line-length': [2, 'always', 100],
'footer-leading-blank': [1, 'always'],
'footer-max-line-length': [2, 'always', 100],
'header-max-length': [2, 'always', 100],
'subject-case': [
2,
'never',
['start-case', 'pascal-case', 'upper-case'],
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
'tests',
],
],
},
prompt: {
questions: {
type: {
description: "Select the type of change that you're committing",
enum: {
feat: {
description: 'A new feature',
title: 'Features',
emoji: '✨',
},
fix: {
description: 'A bug fix',
title: 'Bug Fixes',
emoji: '🐛',
},
docs: {
description: 'Documentation only changes',
title: 'Documentation',
emoji: '📚',
},
style: {
description:
'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
title: 'Styles',
emoji: '💎',
},
refactor: {
description:
'A code change that neither fixes a bug nor adds a feature',
title: 'Code Refactoring',
emoji: '📦',
},
perf: {
description: 'A code change that improves performance',
title: 'Performance Improvements',
emoji: '🚀',
},
test: {
description: 'Adding missing tests or correcting existing tests',
title: 'Tests',
emoji: '🚨',
},
tests: {
description: 'Adding missing tests or correcting existing tests',
title: 'Tests',
emoji: '🚨',
},
build: {
description:
'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
title: 'Builds',
emoji: '🛠',
},
ci: {
description:
'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
title: 'Continuous Integrations',
emoji: '⚙️',
},
chore: {
description: "Other changes that don't modify src or test files",
title: 'Chores',
emoji: '♻️',
},
revert: {
description: 'Reverts a previous commit',
title: 'Reverts',
emoji: '🗑',
},
},
},
scope: {
description:
'What is the scope of this change (e.g. component or file name)',
},
subject: {
description:
'Write a short, imperative tense description of the change',
},
body: {
description: 'Provide a longer description of the change',
},
isBreaking: {
description: 'Are there any breaking changes?',
},
breakingBody: {
description:
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself',
},
breaking: {
description: 'Describe the breaking changes',
},
isIssueAffected: {
description: 'Does this change affect any open issues?',
},
issuesBody: {
description:
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself',
},
issues: {
description: 'Add issue references (e.g. "fix #123", "re #123".)',
},
},
},
};
37 changes: 37 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: 'commitlint'
on: # yamllint disable-line rule:truthy
- 'push'
- 'pull_request'

jobs:
commitlint:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0

- name: 'Install required dependencies'
run: |
sudo apt update
sudo apt install -y sudo
sudo apt install -y git curl
curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo DEBIAN_FRONTEND=noninteractive apt install -y nodejs

- name: 'Install commitlint'
run: |
npm install conventional-changelog-conventionalcommits
npm install commitlint@latest

- name: 'Validate current commit (last commit) with commitlint'
if: "github.event_name == 'push'"
run: 'npx commitlint --last --verbose'

- name: 'Validate pull request commits with commitlint'
if: "github.event_name == 'pull_request'"
run: >-
npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }}
--to ${{ github.event.pull_request.head.sha }} --verbose
...
64 changes: 60 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
ci:
autofix_prs: false
skip:
- 'yamllint'
- 'ansible-lint'
- 'commitlint'
- 'jshint'
- 'markdown-link-check'
- 'markdownlint'
- 'ansible-lint'
- 'pyspelling'
- 'yamllint'

repos:
- repo: 'https://github.com/ansible/ansible-lint'
rev: 'v24.2.1'
hooks:
- name: 'ansible-lint'
- id: 'ansible-lint'
stages:
- 'pre-commit'
additional_dependencies:
# https://github.com/pre-commit/pre-commit/issues/1526
- 'ansible-core>=2.15'
always_run: true
description: 'This hook runs ansible-lint.'
entry: 'python3 -m ansiblelint -v --force-color'
id: 'ansible-lint'
language: 'python'
# do not pass files to ansible-lint, see:
# https://github.com/ansible/ansible-lint/issues/611
Expand All @@ -30,32 +33,60 @@ repos:
rev: 'v4.5.0'
hooks:
- id: 'check-executables-have-shebangs'
stages:
- 'pre-commit'
- id: 'check-merge-conflict'
stages:
- 'pre-commit'
args:
- '--assume-in-merge'
- id: 'check-json'
stages:
- 'pre-commit'
- id: 'check-shebang-scripts-are-executable'
stages:
- 'pre-commit'
- id: 'check-symlinks'
stages:
- 'pre-commit'
- id: 'check-toml'
stages:
- 'pre-commit'
- id: 'check-xml'
stages:
- 'pre-commit'
- id: 'debug-statements'
stages:
- 'pre-commit'
- id: 'destroyed-symlinks'
stages:
- 'pre-commit'
- id: 'detect-private-key'
stages:
- 'pre-commit'
- id: 'mixed-line-ending'
stages:
- 'pre-commit'
args:
- '--fix=no'
- id: 'pretty-format-json'
stages:
- 'pre-commit'
args:
- '--no-sort-keys'
- '--indent=2'
- id: 'trailing-whitespace'
stages:
- 'pre-commit'
args:
- '--markdown-linebreak-ext=md'

- repo: 'https://github.com/adrienverge/yamllint.git'
rev: 'v1.35.1'
hooks:
- id: 'yamllint'
stages:
- 'pre-commit'
pass_filenames: true
verbose: true

Expand All @@ -64,20 +95,45 @@ repos:
rev: '63e4654f0be643ca0f1676227db24bb7f88dee29'
hooks:
- id: 'pyspelling'
stages:
- 'pre-commit'
pass_filenames: false
verbose: true

- repo: 'https://github.com/tcort/markdown-link-check.git'
rev: 'v3.12.1'
hooks:
- id: 'markdown-link-check'
stages:
- 'pre-commit'
pass_filenames: true
verbose: true

- repo: 'https://github.com/igorshubovych/markdownlint-cli'
rev: 'v0.39.0'
hooks:
- id: 'markdownlint'
stages:
- 'pre-commit'
verbose: true
pass_filenames: true

- repo: 'https://github.com/alessandrojcm/commitlint-pre-commit-hook'
rev: 'v9.14.0'
hooks:
- id: 'commitlint'
stages:
- 'commit-msg'
additional_dependencies:
- 'conventional-changelog-conventionalcommits'
- 'commitlint-plugin-selective-scope'

- repo: 'https://github.com/pre-commit/mirrors-jshint'
rev: 'v2.13.6'
hooks:
- id: 'jshint'
stages:
- 'pre-commit'
types:
- 'javascript'
...