DEV Community

loading...
Cover image for #DevHack: Skipping your GitHub Actions workflows on specific commits messages

#DevHack: Skipping your GitHub Actions workflows on specific commits messages

Elio Struyf
Elio Struyf is an independent Engineering Lead working for Valo Intranet, Blogger, and Speaker. Loves stickers - if you want stickers as well, get them at https://pyod.shop.
・2 min read

In the doctor project, I try to do as much as possible in one GitHub Actions workflow. Having all logic in one workflow makes it more convenient but comes with a couple of complexities. Like, do you want to run each action for every type of commit/PR/...?

The whole GitHub Actions workflow

Why I want to skip actions/jobs in my workflow

I host the documentation on Vercel. Vercel manages its build processes. You can also choose to use the Vercel Action for deploying your sources, but having it on the Vercel platform itself is straightforward.

When I was working on the documentation, I thought it would be useless to go through a complete workflow run when only the documentation was touched. I thought this does not have to happen, so why not skip these actions/jobs on specific commits. That is why I specified to skip all jobs when my commit contains #docs in the commit message.

Info: You can use any text value that makes sense to you.

Skipping when commits contain a text value

If you want to skip your job or actions when the commit contains a specific text value in its commit message, all you have to do is add an if condition. In this condition, you can use the contains expression.

In the case of my #docs commit messages, the expression looks as follows:

jobs:
  build:
    name: Build ${{ matrix.os }} - Bash
    runs-on: ${{ matrix.os }}
    if: ${{ !contains(github.event.head_commit.message, '#docs') }}
Enter fullscreen mode Exit fullscreen mode

Skipping all GitHub Actions when commit message contains `#docs`

Info: You can read more about the GitHub Actions expression syntax at context and expression syntax for GitHub Actions.

Article first published on eliostruyf.com

Discussion (0)