Now you can skip running unnecessary builds or certain Steps when committing small or Draft PRs by using the Env Var GITHUB_PR_IS_DRAFT. 🚀
We introduced a new environment variable - GITHUB_PR_IS_DRAFT - that will be set to true when a Draft Pull Request triggers a build. You can use this variable to vary the behavior of your builds based on the Pull Request’s draft status. As the Env Var’s name suggests, this feature is only available for apps hosted on GitHub at the moment.
Two use-cases are
- to skip steps and
- to early exit builds
making more efficient use of credits.
Note: you can select ‘Draft PR’ when opening a Pull Request and this Env Var is of course only present in builds triggered by PR webhooks.
Skipping steps
Let’s see how you can run builds, but skip certain steps to save credits and time. In the case of a Draft PR, you might want to skip lengthy UI Tests and just run some static analysis instead.
Sample script that will only run if it's a Draft PR:
And this is a sample script to only run if NOT a Draft PR:
Early exit a Build
To skip an entire PR build if the Pull Request is in draft state, place a Script Step at the beginning of the Workflow. This script will early exit if the Pull Request is a Draft. This will have an overhead of 1 minute of build time consumed.
Sample script to exit build when a Draft PR is detected:
Please note the following:
- This will cause your build to show as failed.
- Put this script as the first step in your Workflow, otherwise you’ll waste time on other Steps.
- If you have subsequent Steps marked as is_always_run, those Steps will still run.
- We do hope to have a simpler way for skipping an entire build in the future.
Happy building! 🚀