Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for parameterizing path-filtering logic that forces compare to parent commit when base == head #96

Open
WisdomMillsOwoo opened this issue Nov 10, 2023 · 0 comments

Comments

@WisdomMillsOwoo
Copy link

Describe Request:

We are using the set-parameters command in the path-filtering orb to try to minimize how often have to run certain jobs in our workflow. The idea is that if the code has not changed fundamentally, we can rely on artifacts created, and scans that have been performed in a previous branch.

The issue we are running to is on branch creation. Here is the scenario:

Our path-filtering is set up as follows:

- path-filtering/set-parameters:
    config-path: .circleci/continue_config.yml
    output-path: ./pipeline-parameters.json
    mapping: |
      api/.* api-changed true
      service/.* service-changed true
      pom.xml version-changed true
    base-revision: develop

So the idea is if api-changed, service-changed, or version-changed are not set to true, then we don't need to re-run our full build and scan workflow. We can just pick up the latest artifacts and use them.

However, lets say I run my DEVELOP branch pipeline, and I have done all the necessary scans and builds there. I then create my RELEASE branch from DEVELOP. Because nothing has changed, I would expect that the path-filtering logic would reflect that, and queue the pipeline to use the existing artifacts.

Unfortunately, because of this piece of code found in the set-parameters command in the path-filtering orb:
(Lines 198 - 210)

if head == base:
try:
# If building on the same branch as BASE_REVISION, we will get the
# current commit as merge base. In that case try to go back to the
# first parent, i.e. the last state of this branch before the
# merge, and use that as the base.
base = parent_commit()
except:
# This can fail if this is the first commit of the repo, so that
# HEAD~1 actually doesn't resolve. In this case we can compare
# against this magic SHA below, which is the empty tree. The diff
# to that is just the first commit as patch.
base = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'

that will never happen. Because on the creation of a new branch, "head == base" will always be true, thereby triggering this piece of code to force comparison with the parent commit instead.

The ask here if CircleCI can please parameterize this logic and allow the consumer to pass turn this off when desired. The default logic can stay the same, as to not introduce any breaking changes. This will provide functionality to tweak this logic as needed per workflow.

Examples:

- path-filtering/set-parameters:
    config-path: .circleci/continue_config.yml
    output-path: ./pipeline-parameters.json
    allowSameRevisionCompare: true
    mapping: |
      api/.* api-changed true
      service/.* service-changed true
      pom.xml version-changed true
    base-revision: develop

There's probably a better name for it, but thats kind of the idea

Supporting Documentation Links:

The orb command: https://circleci.com/developer/orbs/orb/circleci/path-filtering#commands-set-parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant