Alert This post is over a year old, some of this information may be out of date.

#DevHack: Skip GitHub Actions on specific commits messages

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
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.


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:

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

Good thing to note is that the contains function is not case sensitive for the value to check.

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

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

Happy automating


Back to top