GitHub Actions Day 13: Conditionals

December 13, 2019

This is day 13 of my GitHub Actions Advent Calendar. If you want to see the whole list of tips as they're published, see the index.

Yesterday we saw that there's a lot of data available to you when you run a workflow. You can use this data within your run steps and use it with your build scripts, deploy steps or repository automation. But you can also use this within the workflow itself.

One useful way to take advantage of this data is to use it to run workflow steps conditionally.

For example, you might want to check the name of the repository your workflow is running in before you execute a step. This is helpful if you're working on an open source project -- since people who fork your repository have tokens with different permissions, you can skip the publish step for forks.

This allows forked repositories to still perform continuous integration builds, and ensures that the workflow succeeds when builds run and tests pass, and don't fail because of permissions problems on a publish step.

You can set up a conditional that ensures you're on the correct repository, and running in a CI build (from a push event).

Now when this workflow runs in a fork, the Publish Documentation step will be skipped.

Skipped Step

Using conditionals lets you build advanced workflows that you can share between branches or forks, but have some steps that are tailored to particular triggers or environments.