GitHub Action : conventional-commit-checker

In this article, we will see how to write a GitHub Action and publish it to Github marketplace. GitHub Actions are GitHubs solution for CI/CD automation. This article was not my primary intention since I thought I could use something available on the GitHub market place, but as I was searching for different GitHub apps and actions on GitHub market place, I found some actions/apps that are similar I could not find the one the “exactly” fit my need.

So I want a GitHub action that checks for conventional commit format in Pull Requests.

Conventional commit in short has this below format

My GitHub Actions goals are

  1. Check the Pull Request title for conformance of <type>[optional scope]: <description>
  2. Check the description of the Pull request for conformance of[optional body] and [optional footer]
  3. When PR is accepted, it should squash all the commits in the PR and the commit message should have the PR title, description, body and footer

Following the instructions from https://help.github.com/en/actions/creating-actions/creating-a-javascript-action , I got a hello world action working.

Step 1: It uses the actions/checkout@v2 which as the name implies git clone/checkouts our repo into the machine where this action is running. This action is prerequisite for all actions. You can do some advanced stuff with checkout other repos for complex builds.

Step 2: (Say Hello go <who-to-greet>): uses the following action code. <who-to-greet> is an input variable to this action.

The Github action executes a javascript index.js file which takes the input paramenter who-to-greet , greets and also sets an output time variable

Step 3: (what was the time of the greet): This step takes the output time variable set in the previous step and prints out in the console. `

After learning about how the Hello world Javascript GitHub Action, I was able to create an action for conventional commit check.

It basically ended up as regex check. I get the PR title and PR body (first comment) using the GitHub context APIs and validating against a regex. The regex can be modified by optional input configuration

You can use it in your repo as follows

It is available at GitHub marketplace at https://github.com/marketplace/actions/conventional-commit-checker

Unfortunately, I could not meet the goal 3 i.e

When you press the Squash And Merge Button in the PR, commit message that will be used to merge this PR uses the title of the PR appended by all commits that went into the PR.

It is not possible to auto update/customize the GitHub Squash and Merge description message. To really benefit from this action, you can copy the PR body into the GitHub Squash and Merge description message.

May be in future if there can be some API/Github option, it can be fulfilled

Overall, It is pretty neat experience about how GitHub actions are architected, publishing. Publishing is as straight forward as creating GitHub releases, tags.

Solving Problems. Making Software Better. Intrigued by Elegant Solutions. https://twitter.com/agent_hunt

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store