CircleCI-Public / path-filtering-orb

MIT License
24 stars 57 forks source link

YAML Anchors Causing Build Failures #100

Open elijahe opened 9 months ago

elijahe commented 9 months ago

Orb version:

1.0.0

What happened:

When using the path-filtering orb to merge multiple configs, some of which contain yaml anchors such as the one below,

default_vars: &default_vars
  environment:
    DEBUG: true
    NODE_ENV: production

the anchors are sometimes placed at the bottom of the merged config which causes the build to fail with an error message similar to:

Unable to parse YAML
found undefined alias default
 in 'string', line 471, column 9:
        <<: *default_vars
            ^

Note: If only a single config contains anchors then this issue appears to happen sporadically depending on the order that the filtered configs are processed in. In other words, if we have 2 configs, config_1_with_anchors.yml and config_2_without_anchors.yml, if the merging code decides to process config_1_with_anchors.yml before config_2_without_anchors.yml it works just fine. If on the other hand it decides to process config_2_without_anchors.yml first and config_1_with_anchors.yml second then it fails. The order of processing appears to be non-deterministic.

Expected behavior:

Ideally YAML anchors should always be placed at the top of the merged config so that they do not cause parsing errors.

Additional context:

Here's a sample .circleci/config.yml file which reproduces the issue above:

---
version: 2.1

setup: true

orbs:
  path-filtering: circleci/path-filtering@1.0.0

workflows:
  generate-config:
    jobs:
      - path-filtering/filter:
          base-revision: << pipeline.git.branch >>
          mapping: |
            editor/.* build-editor true editor/.circleci/config.yml
            fe/.* build-fe true fe/.circleci/config.yml
patrykkarny commented 4 months ago

Hey @elijahe, thank you for reporting the issue! I'm experiencing the same problem. Have you found any solutions to avoid this error, other than consolidating the configuration into a single one?

elijahe commented 4 months ago

Hi @patrykkarny , no I haven't found a solution for this issue yet. We're just avoiding YAML Anchors for now. It would be great to be able to use them again.

pc-bob commented 2 months ago

A workaround has been suggest here that worked for me: https://github.com/CircleCI-Public/path-filtering-orb/issues/88