Using Gitlint with GitHub Actions

Linting commit messages can be useful to enforce a standard of git commit messages - but how can we run these as checks on a GitHub pull request?

, by Joe Glombek

⚠️ This article was written in and last updated in so may contain some out of date information.

It's possible to run checks in GitHub actions as automated checks in GitHub pull requests. These are simply GitHub actions with the on: pull_request trigger.

I'm using gitlint by Joris Roovers for this purpose as the rules are highly configurable (and come with sensible defaults). This script will automatically look for rules in your .gitlint file in the root of your repository.

name: Gitlint

    runs-on: ubuntu-latest

      - uses: actions/checkout@v2
          # Check out at the last commit (pre-automated merge, we don't care about the temporary commit for linting)
          ref: ${{ github.event.pull_request.head.sha }}
          # Get all history
          fetch-depth: 0

      - name: Install gitlint
        shell: bash
        run: |
          python -m pip install gitlint

      - name: Run gitlint
        shell: bash
        run: |
          # Lint everything from the base to the latest
          gitlint --commits "${{ github.event.pull_request.base.sha }}..HEAD"