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

Support Disabling\Enabling enforce_admins As Part of Push #508

Closed
GreasyAvocado opened this issue May 23, 2023 · 5 comments
Closed

Support Disabling\Enabling enforce_admins As Part of Push #508

GreasyAvocado opened this issue May 23, 2023 · 5 comments
Labels
status: pending More info is needed before deciding what to do

Comments

@GreasyAvocado
Copy link

Hi,

In my use case, I do git push from GitHub Actions workflows to master branches.
I have branch protection rules on master, so as part of the workflow I first disable the enforce_admins setting, then git push, and finally enable enforce_admins.

I modify enforce_admins as follows:

curl -X DELETE -u USER:TOKEN https://api.github.com/repos/ORGANIZATION/REPOSITORY/branches/master/protection/enforce_admins
curl -X POST -u USER:TOKEN https://api.github.com/repos/ORGANIZATION/REPOSITORY/branches/master/protection/enforce_admins

Is it something that can be added to the action?
So that if the action tries to push, and gets a protected branch hook declined response, it'll try to disable enforce_admins, push again, and reenable enforce_admins at the end.

@GreasyAvocado GreasyAvocado added the status: pending More info is needed before deciding what to do label May 23, 2023
@GreasyAvocado
Copy link
Author

Alternatively, I think it makes more sense to just add a generic way to run GitHub API calls pre\post push, and not something specific for enforce_admins.

WDYT?

@EndBug
Copy link
Owner

EndBug commented May 24, 2023

I think it would be better if you handle that outside of the action, by running the call in a step before and after the action's

The action usually takes a couple of seconds to run, so the timing should not cause too many issues unless you're dealing with frequent concurrency (which can, and in your case should, be prevented for this kinds of operations)

You can make sure the rule is always reset to the original status by using if: ${{ always() }} in your step ;)

@GreasyAvocado
Copy link
Author

Got it.
Thanks for the reply!

@GreasyAvocado GreasyAvocado closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2023
@GreasyAvocado
Copy link
Author

For anyone who might have the same issue, I've worked around it by migrating the GitHub repo from Branch Protection Rules to Repository Rules.

More details here:
https://github.com/orgs/community/discussions/43460
https://github.blog/changelog/2023-04-17-introducing-repository-rules-public-beta/

@EndBug
Copy link
Owner

EndBug commented Aug 17, 2023

That's awesome! Thanks for sharing ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending More info is needed before deciding what to do
Projects
None yet
Development

No branches or pull requests

2 participants