Hundreds of founders, makers and marketers are part of The Digital Product Playbook.

This month we're giving away $700 of DigitalOcean credit, 1 year of SnapShooter along with a whole bunch of DigitalOcean goodies!

Join for free today at thedigitalproductplaybook.com/giveaway

Running GitHub Actions for Certain Commit Messages

A quick look at how you can configure your GitHub Actions workflows to only run when a certain phrase is present in the commit message.

Published 3 weeks ago | Updated 3 weeks ago
Tooling GitHub Actions

I'm going to be honest with you all for a second. I write a lot of wip commits. These commits are normally small changes that I want to push up to GitHub so that:

  1. I don't lose things if anything goes wrong and my backup hasn't picked it up.
  2. If I can't describe the change I have just made.
  3. If I'm demonstrating something to somebody on a pull-request.

The problem is, my actions are setup to run on push, so every single wip commit gets run through the CI process, whether it be running tests, linting or formatting.

After doing some research, I found a way of preventing these from running on every single commit.

jobs:
  format:
    runs-on: ubuntu-latest
    if: "! contains(github.event.head_commit.message, 'wip')"

Now, whenever I push a wip commit or any commit that contains the word wip, it will be marked as skipped inside of GitHub actions.

You could also flip the logic and perhaps do something like:

jobs:
  format:
    runs-on: ubuntu-latest
    if: "contains(github.event.head_commit.message, '[build]')"

Any commit that contains [build] will now trigger these jobs, everything else will be skipped.

You can thank me later! 😉