This GitHub Action can be used to lint commit messages to ensure they adhere to the conventional commit specification.
This action has two main use cases
- Validate the pull request title
- Validate commits added in a pull request
The action has an optional relaxed mode. When used, commit messages will only be validated if the pull request title is invalid or if the pull request only consists of a single commit. For most use cases, the relaxed mode is now recommended. The action also has an optional require-type-and-scope parameter. When used, the PR title commit message will be validated with a stricter custom plugin according to conventional commits (e.g., feat(ABC-1234): Commit name), enforcing both the type and scope requirements for better consistency.
To complement this action, it is recommended to enforce commit conventions using pre-commit hooks.
See action.yml.
This example will always validate the pull request title. In case require-type-and-scope will be true additional checks will be performed (checking git prefix , syntax validation). If the title is valid, it will only validate commits if the pull request consists of a single commit. The rationale behind this behavior is that PRs with single commits will be used as the default squash message by GitHub.
A workflow configured like this is the most forgiving, while enforcing good commits as long as squash and merge is used.
on:
pull_request:
types:
- edited
- opened
- reopened
- synchronize
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Lint pull request title
uses: extenda/actions/commitlint@v0
with:
message: ${{ github.event.pull_request.title }}
- name: Lint commit messages
if: always()
uses: extenda/actions/commitlint@v0
with:
relaxed: ${{ contains(job.status, 'success') }}on:
pull_request:
types:
- edited
- opened
- reopened
- synchronize
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Lint pull request title
uses: extenda/actions/commitlint@v0
with:
message: ${{ github.event.pull_request.title }}
- name: Lint commit messages
uses: extenda/actions/commitlint@v0on:
pull_request:
types:
- edited
- opened
- reopened
- synchronize
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Lint pull request title
uses: extenda/actions/commitlint@v0
with:
message: ${{ github.event.pull_request.title }}
require-type-and-scope: 'true'
- name: Lint commit messages
uses: extenda/actions/commitlint@v0