This GitHub Actions script (or action) aims at checking that a pull request is well-formed before being merged to the main branch of a repository. This also aims to verify the message of the commits inside the pull-request (called inner-commits) is well formed for the semantic- release tool.
It particularly targets repositories using the squash and merge commit strategy to keep their commit history clean and readable.
It also targets repositories using the semantic-release
tool for automatically generating releases based on conventional commits standard. Here, only non-conventional (squash and merge) commits are expected in the main branch, each with a reference to the pull request it was squashed from, allowing to refer to the inner-commits, though the latter were squashed during the merging of the pull request to the main branch. The format of such squash and merge commits is as follows:
Modify the data model (#13)
where the block (#13)
, and particularly the number 13
, is the index of the pull request containing the commits that were squashed and merged.
The format of inner-commit's message is as follows:
type(scope): something changed
Where type
is mandatory and picked from a list defined in the contributor's guide, scope
is not mandatory and refers to the
scope the commit changed.
The following input parameters
Parameter | Description | Mandatory | Default |
---|---|---|---|
github-token |
GitHub token for accessing GitHub repositories. | Yes | None |
pull-request-number |
GitHub pull request number to verify. | Yes | None |
None
The sample GitHub Actions workflow below shows how this action can be used as a step of a GitHub Actions worklflow:
name: Verify pull request format
on:
pull_request_target:
types: [opened, synchronize]
jobs:
check:
name: Check pull request
runs-on: ubuntu-latest
steps:
- name: Analyze pull request title
uses: SofairOfficial/github-actions/check-pull-request-action@main
with:
pull-request-number: "${{ github.event.pull_request.number }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
This GitHub Actions script is implemented using Typescript. The following command should be used to build it when modifying its code:
$ npm build
Unit tests can be executed as follows:
$ npm test
A way for testing the action locally is by executing the providedtest-check-pull-request-action workflow using Act tool. For doing so, the following command should be executed at the root of this repository:
act -s GITHUB_TOKEN=[Your_Personal_Github_Token] pull_request_target