Another approach, using filters
in the workflows
config:
jobs:
- forks_only:
filters:
branches:
# only from forks
only: /^pull\/.*$/
- canonical_repo_only:
filters:
branches:
# only from canonical repository
# https://stackoverflow.com/a/5334825/358804
only: /^(?!pull\/).*$/
The advantages here (versus @dtzar’s shell conditionals):
- It’s using native CircleCI config, rather than having to break out to shell conditionals
- The
jobs
are segmented, which is good if you want very differentsteps
between builds from forks vs. the canonical repo
The disadvantages:
- It’s equally non-intuitive
- The
jobs
are segmented, so you kinda have to maintain them in two places (assuming you want the steps to be similar) - This doesn’t work for required status checks in GitHub, which expect a consistent name for all pull requests
- Regular expression lookarounds aren’t supported by all regex engines, so while it works on CircleCI now, it may not in the future if they switch to a different language/engine for parsing the config
Example usage. A future approach that splits the difference would be using optional build steps, but that isn’t possible yet.