-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Use Case
Allow the GitHub Action to input the PR title or a custom text field for Conventional Commit style validation.
Proposed Solution
With a Boolean PR title validation:
- name: Action | Validate Commit Messages
uses: opensource-nepal/commitlint@v1
with:
# Set to true to validate the PR title. Default to true.
# This setting should be ignored when it is not a PR or when github.event.pull_request.title is empty
pull-request-title: trueOr, with a custom text validation (this might be particularly useful in actions):
- name: Action | Validate Commit Messages
uses: opensource-nepal/commitlint@v1
with:
# Only validate this commit if the value is not empty
commit: ""Alternative Considered
I installed commitlint on my runner (see https://github.com/SiegeSailor/Smarty-Notebook/actions/runs/19213985568/job/54920491842 for details):
jobs:
linting:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: Action | Checkout Repository on Pull Request
uses: actions/checkout@v5
if: github.event_name == 'pull_request'
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Action | Set Up Python
uses: actions/setup-python@v6
if: github.event_name == 'pull_request'
with:
python-version: "3.11.13"
- name: Setup | Install Commitlint
if: github.event_name == 'pull_request'
run: |
pip install commitlint
- name: Evaluate | Validate PR Title
if: github.event_name == 'pull_request'
run: |
commitlint "${{ github.event.pull_request.title }}"
When it is not a PR:
By the way, the following doesn't work. The GitHub Action commitlint seems not to read the local commits on the runner (see https://github.com/SiegeSailor/Smarty-Notebook/actions/runs/19212728519/job/54917412427):
steps:
- name: Action | Checkout Repository on Pull Request
uses: actions/checkout@v5
if: github.event_name == 'pull_request'
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup | Commit PR Title
if: github.event_name == 'pull_request'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit --allow-empty -m "${{ github.event.pull_request.title }}"
- name: Action | Validate Commit Messages
uses: opensource-nepal/commitlint@v1
- name: Cleanup | Revert PR Title Commit
if: github.event_name == 'pull_request'
run: |
git reset --hard HEAD~1
Additional context
Another GitHub Action CashStory/commitizen-action-pr seems to be a particular fit, but it comes with some issues (see CashStory/commitizen-action-pr#2) and is not in an active status.