From 2c08f137897663ea52698ffbefbd0d48ec9f92f1 Mon Sep 17 00:00:00 2001 From: "Sean P. Kelly" Date: Wed, 28 Aug 2024 05:23:08 +0000 Subject: [PATCH] ci: enable commitlint for PRs --- .commitlint.config.mjs | 42 ++++++++++++++++++++++++++++++++ .github/workflows/commitlint.yml | 28 +++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .commitlint.config.mjs create mode 100644 .github/workflows/commitlint.yml diff --git a/.commitlint.config.mjs b/.commitlint.config.mjs new file mode 100644 index 00000000..ede860a0 --- /dev/null +++ b/.commitlint.config.mjs @@ -0,0 +1,42 @@ +/* [commitlint](https://github.com/conventional-changelog/commitlint) configuration */ +import { + RuleConfigSeverity, +} from '@commitlint/types'; + +export default { + parserPreset: 'conventional-changelog-conventionalcommits', + rules: { + 'header-max-length': [RuleConfigSeverity.Error, 'always', 72], // Header should be 72 characters or shorter + 'header-trim': [RuleConfigSeverity.Error, 'always'], // No leading/trailing whitespace in header + 'subject-empty': [RuleConfigSeverity.Error, 'never'], // No empty subject + 'subject-case': [ // Subject line should be lowercase + RuleConfigSeverity.Error, + 'never', + ['sentence-case', 'start-case', 'pascal-case', 'upper-case']], + 'subject-full-stop': [RuleConfigSeverity.Error, 'never'], // No full-stop at end of subject + 'body-max-line-length': [RuleConfigSeverity.Error, 'always', 72], // Body lines should be 72 characteres or shorter + 'body-leading-blank': [RuleConfigSeverity.Error, 'always'], // Empty line before body + 'type-empty': [RuleConfigSeverity.Error, 'never'], // Commit type must be present + 'type-case': [RuleConfigSeverity.Error, 'always', 'lower-case'], // Commit type should be lowercase + 'type-enum': [ // Commit type allowlist + RuleConfigSeverity.Error, + 'always', + [ + 'build', + 'chore', + 'ci', + 'docs', + 'feat', + 'fix', + 'perf', + 'refactor', + 'revert', + 'style', + 'test', + ], + ], + }, + ignores: [ + (message) => message.includes("Merge pull request #"), // PR merges are allowed + ], +}; diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 00000000..5d62c449 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,28 @@ +name: Lint Commit Messages +on: + pull_request: + types: + - opened + - edited + - reopened + - synchronize + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup Node + uses: actions/setup-node@v4 + - name: Install dependencies + run: npm install commitlint @commitlint/config-conventional + - name: Run commitlint against commits in PR + run: | + npx commitlint \ + -g ${{ github.workspace }}/.commitlint.config.mjs \ + --from ${{ github.event.pull_request.base.sha }} \ + --to ${{ github.event.pull_request.head.sha }} \ + --help-url="https://github.com/${GITHUB_REPOSITORY}/blob/${GITHUB_BASE_REF}/CONTRIBUTING.md" \ + --verbose