Status check with path filter

I have a workflow that I run on PRs that validates the build of front end assets, and I’ve set that up as a status check against merging to master.

I now have a scenario where I would like the execution of this workflow to be optional, and only run if files in the front end code has changed. Setting this up is simple with on.<push|pull_request>.paths, but when this workflow isn’t executed the status check fail.

I assume I could implement the path filter as an if statement for the relevant step, but that seems a lot more complicated so I’d prefer to avoid that if there’s a better way. Any suggestions on how to implement this the best way?

2 Likes

Hi @effata ,

I added a path filter to one of my workflows , but it didn’t show status check as failure in PR page. Even if I added that workflow run status check to branch policy, in pull request page, it just showed waiting for status to be reported. 

Could you please share your PR status check screenshots here? If it’s a public repo, please feel free to share the link here. 

@yanjingzhu What you’re describing is exactly the case I mean. In this case I classify Waiting for status to be reported as a failure, because it’s blocking the PR from being merged. What I’m trying to accomplish is to have this check still be required when it runs, but when it doesn’t run it shouldn’t block the PR from being merged.

Screenshot 2020-04-07 at 13.48.33.png

I would recommend you going to your branch policy page, uncheck the “frontend-fast-build” from the status check section. 

As the workflow will be triggered on pull_request or push event , it will be attached to this pull request checks when it runs. And the status check needs to pass . 

When you push new changes without matched files to the path filter, the workflow will not be triggered and it will not show in the pull request checks list. So it would not block the PR from being merged. 

@yanjingzhu wrote:

I would recommend you going to your branch policy page, uncheck the “frontend-fast-build” from the status check section. 

As the workflow will be triggered on pull_request or push event , it will be attached to this pull request checks when it runs. And the status check needs to pass . 

When you push new changes without matched files to the path filter, the workflow will not be triggered and it will not show in the pull request checks list. So it would not block the PR from being merged. 

That kind of works, but it’s not quite the same, as the “overall” status will be green, and the failed status won’t actually block the PR from being merged :disappointed:

I suspect that the only way to do what the OP (and I), would like to do, is to do it in an if…

+1 We are having this issue as well. We want our pull request workflows with path based filters to be required checks when the workflow is triggered, but not block PRs that do not match the filter due to status not being reported.

Hi all, 

It is a good idea to use path filter with require status check branch protect rule.  I would encourage you share those in the Feedback form for GitHub Actions. Thank you for helping us build a better GitHub Actions. 

I had similar use case and solved it that way.
Recently I published it as an reusable action - paths-filter

Example usage:

    - uses: dorny/paths-filter@v2.0.0
      id: filter
      with:
        filters: |
          frontend:
            - 'frontend/**/*'

    # run only if 'frontend' files were changed
    - if: steps.filter.outputs.frontend == 'true'
      run: ...

It would be nice to have this as an built-in feature.
Maybe one day… for now, I would say this workaround is good enough.

I published an Action that solves all those required-check-problems: https://github.com/marketplace/actions/skip-duplicate-actions

This is similar to GitHub’s path filter, but the underlying algorithm is smarter.
You can give it a try if this is still an issue.