diff --git a/.github/workflows/lint-commit.yml b/.github/workflows/lint-commit.yml new file mode 100644 index 0000000000..6a61ae771a --- /dev/null +++ b/.github/workflows/lint-commit.yml @@ -0,0 +1,27 @@ +name: Lint Commits + +on: + pull_request: + +permissions: + contents: read # to fetch code (actions/checkout) + +jobs: + lint-pr-first-commit: + name: Commit Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + - uses: actions/setup-node@v6 + with: + node-version: 22.x + - run: npm install + - name: Lint first PR commit message + run: | + FIRST=$(git rev-list --reverse ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | head -1) + echo "Base: ${{ github.event.pull_request.base.sha }}" + echo "Head: ${{ github.event.pull_request.head.sha }}" + echo "First PR commit: $FIRST" + git log -1 --format=%B "$FIRST" | npx commitlint --verbose diff --git a/commitlint.config.mjs b/commitlint.config.mjs new file mode 100644 index 0000000000..2291173ef3 --- /dev/null +++ b/commitlint.config.mjs @@ -0,0 +1,3 @@ +export default { + extends: ['@commitlint/config-conventional'] +}; diff --git a/package.json b/package.json index 7f579406da..bce9250537 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,8 @@ "node": "^20.17.0 || >=22.9.0" }, "devDependencies": { + "@commitlint/cli": "^21.0.2", + "@commitlint/config-conventional": "^21.0.2", "bindings": "^1.5.0", "cross-env": "^10.1.0", "eslint": "^9.39.1",