Skip to content

Commit

Permalink
build(ci): lint commits in pull requests
Browse files Browse the repository at this point in the history
Prevent the merging of unconventional commits into the master branch.

Lint commits made directly onto the master branch.

Issues: #18
  • Loading branch information
geoffreyvanwyk committed Jan 5, 2024
1 parent 1506d60 commit 5b3ba90
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Build

on:
pull_request: {}

push:
branches:
- master

jobs:
commitlint:
name: Commit Lint
runs-on: ubuntu-latest

steps:
- name: Check out the codebase
uses: actions/checkout@v2

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 21

- name: Install Node modules
run: npm install

- name: Check program versions
run: |
node --version
npm --version
npm run commitlint -- --version
- name: Validate last commit
if: github.event_name == 'push'
run: npm run commitlint -- --from HEAD~1 --to HEAD --verbose

- name: Validate commits in pull request
if: github.event_name == 'pull_request'
run: >-
npm run commitlint --
--from=${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }}
--to=${{ github.event.pull_request.head.sha }}
--verbose
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run commitlint ${1}
npm run lint-commit-msg ${1}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"scripts": {
"prepare": "husky install",
"commitlint": "commitlint --edit"
"lint-commit-msg": "commitlint --edit",
"commitlint": "commitlint"
}
}

0 comments on commit 5b3ba90

Please sign in to comment.