Search code examples
github-actionscicd

github actions path filtering returning true when no changes made


So I'm using this marketplace action dorny/paths-filter to check if there are files changed to run a specific workflow. for the moment I'm just testing the outputs to see if they are correct so I have this file structure.

- .github/workflows/
- scraper_backend/
- terraform_ecr/
- terraform_lambda
- app.py
- tagging.sh

Now I want 3 workflows for when there is a change to either the backend, terraform_ecr or terraform_lambda. So I just echo the output of to see if they found a change but when there is no change to either of these 3 folders it still returns true for the backend and the lambda folder. This is my workflow

name: Composite Test
on: [pull_request, push]
jobs:
  changes:
    runs-on: ubuntu-latest
    outputs:
      backend: ${{ steps.changes.outputs.backend }}
      ecr: ${{ steps.changes.outputs.infra }}
      lambda: ${{ steps.changes.outputs.lambda }}
    steps:
    - uses: actions/checkout@v3
    - uses: dorny/paths-filter@v2
      id: changes
      with:
        filters: |
          backend:
            - 'scraper_backend/**'
            - 'app.py'
            - 'tagging.sh'
          ecr:
            - 'terraform_ecr/**'
          lambda:
            - 'terraform_lambda/**'
  test:
    needs: changes
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: echo ${{ needs.changes.outputs.backend }}
      - run: echo ${{ needs.changes.outputs.ecr }}
      - run: echo ${{ needs.changes.outputs.lambda }}

This is the output

enter image description here

Any help is greatly appreciated!

EDIT

I think it compares to the main branch where it detects the changes. Is there a way to tell it to look at the latest commit?


Solution

  • I found it.

    steps:
        - uses: actions/checkout@v3
        - uses: dorny/paths-filter@v2
          id: changes
          with:
            base: ${{ github.ref }} <----- ADDED
            filters: |
              backend:
                - 'scraper_backend/**'
                - 'app.py'
                - 'tagging.sh'
              ecr:
                - 'terraform_ecr/**'
              lambda:
                - 'terraform_lambda/**'
    

    Just needed to add this base line