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

#DevHack: GitHub Actions do not run step on schedule

post

When creating a whole new Github Actions workflow for Doctor, I wanted to do as much as possible from one workflow and be able to limit specific actions depending on how it triggered.

I wanted my GitHub Actions to run on each push to the dev and main branch and run the tests on a schedule. Instead of creating two workflows, I wanted to use only one workflow and specify not to run my release step to npm when triggered on a schedule.

The condition for this is relatively easy. All you need to know is the event type and the property name to use.

You can find all property names on the context and expression syntax for GitHub Actions. The one we need for the workflow is github.event_name.

You can find the event name values on the [events that trigger the workflows](Events that trigger workflows - GitHub Docs) page. In this case, the value is schedule.

The condition its implementation looks as follows:

1
2
3
4
5
6
7
8
9
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Do not run on a schedule
        run: echo Just a message.
        if: ${{ github.event_name != 'schedule' }}

This results in:

Skip step on a schedule
Skip step on a schedule

Comments

Back to top