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 a62fcf8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
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
with:
fetch-depth: ${{ github.event.pull_request.commits }}

- 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 a62fcf8

Please sign in to comment.