From 9fd65569ee17ac7568445c6315bef02023946adb Mon Sep 17 00:00:00 2001 From: Matthew Davidson Date: Fri, 3 May 2024 21:35:09 +0700 Subject: [PATCH] ci: Add Conventional Commits linter for CI --- .github/workflows/commit-linter.yaml | 38 ++++++++++++++++++++++++++++ commitlint.config.mjs | 6 +++++ 2 files changed, 44 insertions(+) create mode 100644 .github/workflows/commit-linter.yaml create mode 100644 commitlint.config.mjs diff --git a/.github/workflows/commit-linter.yaml b/.github/workflows/commit-linter.yaml new file mode 100644 index 0000000..9383f4d --- /dev/null +++ b/.github/workflows/commit-linter.yaml @@ -0,0 +1,38 @@ +name: commit-linter + +on: + pull_request: + push: + branches: [main] + +jobs: + commit-lint: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: cachix/install-nix-action@v25 + with: + nix_path: nixpkgs=channel:nixos-unstable + + - uses: DeterminateSystems/magic-nix-cache-action@main + + - name: npm install + run: nix develop --command npm install --include=dev + + - name: Print versions + run: | + git --version + node --version + npm --version + npx commitlint --version + + - name: Validate current commit (last commit) with commitlint + if: github.event_name == 'push' + run: nix develop --command npx commitlint --last --verbose + + - name: Validate PR commits with commitlint + if: github.event_name == 'pull_request' + run: nix develop --command npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose diff --git a/commitlint.config.mjs b/commitlint.config.mjs new file mode 100644 index 0000000..0f272b7 --- /dev/null +++ b/commitlint.config.mjs @@ -0,0 +1,6 @@ +export default { + extends: ['@commitlint/config-conventional'], + rules: { + 'subject-case': [2, 'always', 'sentence-case'] // override default + } +};