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

Ability to filter out shared yaml anchors from changes output? #131

Open
machty opened this issue Apr 12, 2022 · 4 comments · May be fixed by #239
Open

Ability to filter out shared yaml anchors from changes output? #131

machty opened this issue Apr 12, 2022 · 4 comments · May be fixed by #239

Comments

@machty
Copy link

machty commented Apr 12, 2022

YAML anchors are great for shared config, but if you're trying to use the changes output to drive the matrix of another job, then any anchors you use (which are required by YAML to be attached to a YAML object declaration) are themselves going to appear in the list of changes, e.g.

          shared: &shared
            - common/**
            - config/**
          src:
            - *shared
            - src/**
          lib:
            - *shared
            - lib/**

Assuming I only want matrix jobs for src and lib, this will produced the undesired result of also adding shared to the changes array, which will generate a job for shared even though shared is only meant to be used as a yaml mixin. Is there any way to filter this out?

@lucasyarid
Copy link

Do you happen to have any updates/workaround on this?
The only thing I could think of is conditionally not running steps for shared, which makes it worse, so I'm just going with not using &shared.

@machty
Copy link
Author

machty commented Jan 31, 2023

@lucasyarid I ended up passing the output to a JS script to filter out undesired output.

@JavierMonton
Copy link

JavierMonton commented May 16, 2024

Having the same issue here. This is a workaround using bash and jq.

  changes:
    runs-on: ubuntu-latest
    outputs:
      services: ${{ steps.filter_shared.outputs.without-shared }}
    steps:
      - uses: actions/checkout@v4
      - uses: dorny/paths-filter@v3
        id: filter
        with:
          filters: |
            shared: &shared
              - 'something/**'
              - 'foo/bar/baz/**'
            service1:
              - *shared
              - 'foo/bar/**'
            service2:
              - *shared
              - 'baz/**'
      # filter out "shared" from services
      - name: Filter shared
        id: filter_shared
        run: |
          echo "without-shared=$(echo '${{ steps.filter.outputs.changes }}' | jq -c 'map(select(. != "shared"))')" >> $GITHUB_OUTPUT

@lucasyarid lucasyarid linked a pull request May 17, 2024 that will close this issue
@lucasyarid
Copy link

Finally found some time to open a PR to fix the issue.
Waiting on directions/approval.

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

Successfully merging a pull request may close this issue.

3 participants