DJ.
DJ.

Reputation: 6784

Checking condition when step is running on schedule in GitHub Actions

We have workflow in GitHub Actions which has both types that trigger on event, e.g.pull-request, and on schedule.

Most of the steps are the same except for running test step. What we would like is:

  1. On pull-request without specific label provided: execute smoke test
  2. On pull-request with specific label OR on schedule: execute full test

The check for label can be done with contains(github.event.pull_request.labels.*.name, 'full-tests').

The question is how to check when the it is run on schedule? From my understanding of the documentation, when on schedule there is no payload for github.event for schedule. However checking github.event == null doesn't seems to work.

Is there a specific way to check whether it is running on schedule?

Upvotes: 18

Views: 8793

Answers (1)

GuiFalourd
GuiFalourd

Reputation: 23190

What you want to use in that case is the github.event_name variable, which represents the name of the event that triggered the workflow run in the github context.

In your case, to run a job or a step if the workflow run triggered on a scheduled event, you will need to use:

if: ${{ github.event_name == 'schedule' }}

Reference

Upvotes: 33

Related Questions