I also have requirement like you that I only want some specific people (not all collaborators) are allowed to approve changes to the main branch. And I did as follows for Github Free public repository
:
- write a
Github Actions
file that check the name of person who runs it. If this is name of powerful collaborator, the Actions will succeed.
name: actions_on_main_branch
on:
pull_request_target:
types:
- opened
- synchronize
- reopened
branches:
- 'main'
jobs:
job1:
name: check_adminA
runs-on: ubuntu-latest
env:
NAME_ADMIN: adminA
steps:
- name: st1
if: ${{ github.actor != env.NAME_ADMIN }}
run: exit 1
- name: st2
if: ${{ github.actor == env.NAME_ADMIN }}
run: echo "ok"
in repo settings, add rule to protect 'main' branch. in that rule, select 'Require status checks to pass before merging'
and select jobs
that you specified previously in github actions file. (if jobs not showing, try creating pull request that trigger those github actions, after that jobs will be found on search bar) (you can also select 'Include administrators'
)

By doing that, changes are made to 'main' branch have to go through pull request and those checks will run and fail and prevent merging. Until the powerful collaborators (adminA, adminB) go to that pull request and re-run them, those checks succeeds and allows merging.
(The pull_request_target event makes Github-actions
run on the context of base branch instead of the merging branch. So you don't have to worry github-actions file are edited to be passed easily from outside.)