Status checks "required if run" #26092
-
TL;DRIs it somehow possible to change the branch protection from status checks that are required to “required if run”? I heavily make use of the
for my different workflows for GitHub Actions. Thus, depending on what files were changed in the PR a different set of checks is run. I would mark most (if not all) of them as required before a PR is merged. Problem is, if I do that the PR also waits for checks that will not be run. Is it somehow possible to change this behavior so that a check is marked as required only if it is run? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
Hi @pmeier, I’m afraid it’s not supported. If the checkrun is required, it has to be completed and return a status value. The only exception is if you’re an administrator, you can still merge the pull request. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hm, that is unfortunate. Problem with you approach is that the PR is marked as “not completed yet (yellow dot)” or failed forever, although that is not the case. I guess I’ll remove the branch protection rules in that case. Thanks for your input. |
Beta Was this translation helpful? Give feedback.
-
Yes this is a real shame. I’d like a “all tests run must pass” option, rather than a “these tests must run and pass (even though some of them may not be automatically started nor be relevant)” option. |
Beta Was this translation helpful? Give feedback.
-
any new update on this? |
Beta Was this translation helpful? Give feedback.
-
@pmeier @ayushxx7 You could try this workaround:
This way some check will run, and the rest will be |
Beta Was this translation helpful? Give feedback.
-
Just found out this wasn't supported. This is incompatible with monorepos. |
Beta Was this translation helpful? Give feedback.
-
I have a solution that involves a separate job with pass:
needs: tests
runs-on: ubuntu-latest
if: always()
steps:
- name: "tests must not fail (status: ${{ needs.tests.result }})"
run: exit ${{ needs.tests.result == 'fail' && '1' || '0' }} You can set this as your You customize it and add further logic and steps if you need it to depend on multiple jobs and also want to fail on "cancelled" jobs. This is the one I'm currently using, with a couple dependencies and different requirements: pass:
# Use `always()` in every step so that every step runs and gives the full status of the requirements
needs: [affected-check, tests]
runs-on: ubuntu-latest
if: always()
steps:
- name: "affected-check must be successful (status: ${{ needs.affected-check.result }})"
run: exit ${{ needs.affected-check.result == 'success' && '0' || '1' }}
if: always()
- name: "tests must not fail (status: ${{ needs.tests.result }})"
run: exit ${{ needs.tests.result == 'fail' && '1' || '0' }}
if: always() |
Beta Was this translation helpful? Give feedback.
Hi @pmeier,
I’m afraid it’s not supported. If the checkrun is required, it has to be completed and return a status value.
The only exception is if you’re an administrator, you can still merge the pull request.
Thanks.