Code Quality Check with GitHub Actions

Julien Delange
3 min readMay 25, 2020

--

Code Inspector just released a GitHub action to add a code quality check to your workflow! The GitHub action differs slightly from what our current GitHub App: it does not perform extensive code reviews or publish analysis reviews on our frontend. Instead, the Github action serves as the software quality gatekeeper to ensure that your codebase always meets your quality criteria.

What is a GitHub action?

A GitHub action is an element of your custom workflow that is triggered when a push or pull request is created and perform a simple action (such as checking code, sending a message or deploying the application). A workflow is a very powerful tool that can implement a full CI/CD pipeline: it is an aggregation of multiple, composable, chained GitHub actions, each of them doing something specific.

The most important concept of GitHub actions is their composability. You can assemble actions as building blocks and build a workflow that matches your own needs. The GitHub actions chain is conditional: some actions are activated based on results of other actions(for example: do not deploy if the testsuite failed). This is of primary importance since there is no single one-size fits all workflow.

The following picture depicts what a workflow may look like. When you commit new code, GitHub actions are triggered to perform various actions. If these actions succeed, the code can be then merged or the resulting application deployed.

How GitHub actions are used to define a workflow

Why a GitHub action for Code Inspector?

The Code Inspector GitHub action lets you verify that any new code meets your own code quality criteria. It gives better visibility on the quality of the code being deployed.

The figure below illustrates an example of usage the Code Inspector GitHub action in your workflow:

  • If the new code meets all code quality criteria, the workflow continues, tests and deploys the applications.
  • If the new code does not meet code quality criteria, notifications are sent to the developer team via email or Slack.
The Code Inspector GitHub action checks code at every commit

How does the Code Inspector GitHub action work?

The first step is to install and define your code quality criteria in the workflow configuration file (located in your .github/workflows directory, see example). The action supports the following code quality criteria:

  • Minimum Code Quality Score or Code Grade
  • Maximum number of defects per line of code
  • Maximum ratio of complex functions
  • Maximum ratio of long functions

Once the GitHub action is installed and configured, Code Inspector is notified through its API for each push or pull and triggers a new analysis. The GitHub action quickly gets the analysis results and compares them with the code quality criteria in the GitHub Action criteria. If the criteria are met, the action succeeds. Otherwise, it fails.

Note that if you use the GitHub action on a project currently imported on Code Inspector, you can pass the name of the project in the GitHub action so that the analysis engine loads the project preferences to customize the analysis (e.g. languages or defects filtered). If you do not pass a project, all analyses run by default and no defect is filtered.

How to install the Code Inspector GitHub action?

Follow the installation instructions on the GitHub repository: codeinspectorio/github-action. Visit the repository page or check out the associated GitHub marketplace page.

It takes less than 5 minutes to set it up! If you want to build a complex workflow, a good starting point is the official documentation on GitHub actions.

About Code Inspector and GitHub

Code Inspector is integrated with GitHub through a GitHub App that provides automated code analysis and automated code reviews. It is a new code analysis platform that helps developers and managers deliver better code and reduce their technical debt.

We support GitHub enterprise as well: if you are interested in using our solutions using your GitHub enterprise installation, please contact us.

Questions?

If you have any questions regarding the GitHub action or about Code Inspector in general, please contact us by email or on Slack.

--

--