GitHub Action to validate that PR titles in saueabharch/rollout
match rollout version of the Conventional Commits spec.
- Make a
.github/workflows
dir in your repo. - Create
.github/workflows/validate-pr-title.yml
containing:
name: Validate PR title
on:
pull_request:
types:
- opened
- edited
- synchronize
jobs:
validate_pr_title:
name: Validate PR title
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Validate PR title
uses: saurabharch/action-rollout-semantic-pull-request@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Warning: Only the
pull_request
event may be used as a workflow trigger.
- Store
GITHUB_TOKEN
as a repo secret. Required for fetching the latest PR title on update.
On validation failure, this action will populate the validation_issues
output. You can use this output in subsequent steps, e.g. to send the validation issue as a comment on the pull request.
📰
Output usage example
name: Validate PR title
on:
pull_request:
types:
- opened
- edited
- synchronize
jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: saurabharch/action-rollout-semantic-pull-request@v1
id: validate_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: marocchino/sticky-pull-request-comment@v2
if: always() # ensure workflow continues executing despite validation errors
with:
header: pr_title_failed_validation
message: |
Thank you for your contribution!
PR titles in this repo follow our version of the Conventional Commits spec.
This allows us to automatically generate the changelog for the next release.
Therefore, we ask you to adjust your PR title to solve the issue(s) below:
```
${{ steps.validate_pr_title.outputs.validation_issues }}
```
- if: ${{ steps.validate_pr_title.outputs.validation_issues == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr_title_failed_validation
delete: true # delete prior comment when issue is resolved
git tag -m "Release v1.x.x" v1.x.x
git push --follow-tags
© 2022 Saurabh Kashyap
Distributed under the MIT License.