Recently I learned of the circleci/path-filtering orb that uses the continuation API in a Setup Workflow. This is a really powerful set of tools, except for some reason the
base-revision
is not something that can be dynamically controlled. While you can set the base-revision for the path filtering orb to any valid value, including other parameters, it is not possible to dynamically create a value for the base-revision. For example, if the base-revision is set to a value of
master
it works fine. But if we create a pre-step that gets the base revision from Github, the value cannot be used as the base revision. Relying on the
pipeline.git.base-revision
as a dynamic revision is not reliable, and doesn't work the way one might hope it would. In practice this means that developers using CircleCI in my project need to manually update the base-revision whenever they are working on a different base from
main
/
master
. Can the orb be updated to accept an environment variable exported into $BASH_ENV from a pre-step, or can we have some other mechanism for dynamically controlling this parameter?
Ideally I would be able to do something like this
version: 2.1
setup: true
orbs:
path-filtering: circleci/path-filtering@0.0.2
workflows:
generate-config:
jobs:
- path-filtering/filter:
pre-steps:
- run:
name: Fetch Base Branch from Github
command: |
BASE_BRANCH=$(curl -X GET \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.groot-preview+json" \
-L "https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/commits/$CIRCLE_SHA1/pulls" \
| jq '.[].base.ref')
echo "export BASE_BRANCH=$BASE_BRANCH" >> $BASH_ENV
base-revision: $BASE_BRANCH
mapping: |
path/to/dir/.* build-my-job true
Path Filtering orb