From c3b93ac243ebaaaf9bac1893d1f348c9b1628792 Mon Sep 17 00:00:00 2001 From: Steffen Scheib Date: Sun, 7 Apr 2024 00:56:07 +0200 Subject: [PATCH 1/6] chore(pre-commit): Adding commitlint and jshint, adjusting hook stages Adding commitlint and jshint pre-commit hooks. Adjusting hook stages to only run on their respective stage. --- .pre-commit-config.yaml | 64 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d9523fd5..42dc3178 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -30,25 +33,51 @@ 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' @@ -56,6 +85,8 @@ repos: rev: 'v1.35.1' hooks: - id: 'yamllint' + stages: + - 'pre-commit' pass_filenames: true verbose: true @@ -64,6 +95,8 @@ repos: rev: '63e4654f0be643ca0f1676227db24bb7f88dee29' hooks: - id: 'pyspelling' + stages: + - 'pre-commit' pass_filenames: false verbose: true @@ -71,6 +104,8 @@ repos: rev: 'v3.12.1' hooks: - id: 'markdown-link-check' + stages: + - 'pre-commit' pass_filenames: true verbose: true @@ -78,6 +113,27 @@ repos: 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' ... From a745a080dc6617a94c0bd899cef0bf5530d46297 Mon Sep 17 00:00:00 2001 From: Steffen Scheib Date: Sun, 7 Apr 2024 00:58:08 +0200 Subject: [PATCH 2/6] chore(pre-commit): Adding configuration for commitlint Adding configuration for commitlint. --- .commitlintrc.js | 142 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 .commitlintrc.js diff --git a/.commitlintrc.js b/.commitlintrc.js new file mode 100644 index 00000000..4ec39297 --- /dev/null +++ b/.commitlintrc.js @@ -0,0 +1,142 @@ +module.exports = { + plugins: ['selective-scope'], + 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".)', + }, + }, + }, +}; From 831b5406e78ef09b3b23900769e902d8a16b166e Mon Sep 17 00:00:00 2001 From: Steffen Scheib Date: Sun, 7 Apr 2024 01:02:00 +0200 Subject: [PATCH 3/6] ci: Adding commitlint Adding commitlint configuration for GitHub actions --- .github/workflows/commitlint.yml | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/commitlint.yml diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 00000000..0adbf8f6 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -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: | + apt update + apt install -y sudo + sudo apt install -y git curl + curl -sL https://deb.nodesource.com/setup_14.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 +... From 27605874d2213e5dc05617b9340ae5506d5d665f Mon Sep 17 00:00:00 2001 From: Steffen Scheib Date: Sun, 7 Apr 2024 01:03:59 +0200 Subject: [PATCH 4/6] ci: Fixing missing permission elevation Fixing missing permission elevation for apt commands --- .github/workflows/commitlint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 0adbf8f6..c7ddb1a4 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -14,8 +14,8 @@ jobs: - name: 'Install required dependencies' run: | - apt update - apt install -y sudo + sudo apt update + sudo apt install -y sudo sudo apt install -y git curl curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo DEBIAN_FRONTEND=noninteractive apt install -y nodejs From a3558d24515837f05e79c3f7bf622f25b14e648a Mon Sep 17 00:00:00 2001 From: Steffen Scheib Date: Sun, 7 Apr 2024 01:05:59 +0200 Subject: [PATCH 5/6] ci: Moving to nodejs 20 Moving to nodejs 20.x, replacing the deprecated 14.x --- .github/workflows/commitlint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index c7ddb1a4..6fca98a2 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -17,7 +17,7 @@ jobs: sudo apt update sudo apt install -y sudo sudo apt install -y git curl - curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - + curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo DEBIAN_FRONTEND=noninteractive apt install -y nodejs - name: 'Install commitlint' From d72016d9f8e296e3152361e6433117a3e6233d47 Mon Sep 17 00:00:00 2001 From: Steffen Scheib Date: Sun, 7 Apr 2024 01:07:07 +0200 Subject: [PATCH 6/6] chore(commitlint): Removing selective-scope plugin Removing selective-scope plugin for commitlint --- .commitlintrc.js | 1 - 1 file changed, 1 deletion(-) diff --git a/.commitlintrc.js b/.commitlintrc.js index 4ec39297..34fdb557 100644 --- a/.commitlintrc.js +++ b/.commitlintrc.js @@ -1,5 +1,4 @@ module.exports = { - plugins: ['selective-scope'], parserPreset: 'conventional-changelog-conventionalcommits', rules: { 'body-leading-blank': [1, 'always'],