Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit f8148e2

Browse files
committed
enforce admins off/on for push
1 parent 3555cdd commit f8148e2

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

.github/workflows/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,26 @@ jobs:
9696
git status -v >> $GITHUB_STEP_SUMMARY
9797
echo '```' >> $GITHUB_STEP_SUMMARY
9898
99+
- name: Turn off enforce admin
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GHPAT_FOR_PUSH_RELEASE }}
102+
run: |
103+
source .github/workflows/scripts/github-branch-protection.bash
104+
enforce_admins_off
105+
99106
- name: git push
100107
run: |
101108
git remote set-url origin "https://github-actions:${{ secrets.GHPAT_FOR_PUSH_RELEASE }}@github.com/${GITHUB_REPOSITORY}"
102109
git push -v --force origin main
103110
git push -v --force origin "v${RELEASE_VERSION}"
104111
112+
- name: Turn on enforce admin
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.GHPAT_FOR_PUSH_RELEASE }}
115+
run: |
116+
source .github/workflows/scripts/github-branch-protection.bash
117+
enforce_admins_on
118+
105119
- name: cargo publish
106120
run: |
107121
# load helper script
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function get_current_branch_protection_setting() {
2+
gh api --method GET repos/${OWNER}/${REPO}/branches/${BRANCH}/protection | jq '
3+
{
4+
required_status_checks: null,
5+
restrictions: {
6+
users: .restrictions.users | [.[].login],
7+
teams: .restrictions.teams | [.[].slug],
8+
apps: .restrictions.apps | [.[].slug]
9+
},
10+
enforce_admins: .enforce_admins.enabled ,
11+
required_pull_request_reviews: {
12+
dismiss_stale_reviews: .required_pull_request_reviews.dismiss_stale_reviews,
13+
require_code_owner_reviews: .required_pull_request_reviews.require_code_owner_reviews,
14+
required_approving_review_count: .required_pull_request_reviews.required_approving_review_count
15+
},
16+
required_linear_history: .required_linear_history.enabled,
17+
required_signatures: .required_signatures.enabled,
18+
allow_force_pushes: .allow_force_pushes.enabled,
19+
allow_deletions: .allow_deletions.enabled,
20+
block_reations: .block_creations.enabled,
21+
required_conversation_resolution: .required_conversation_resolution.enabled
22+
}'
23+
}
24+
25+
function apply_branch_protection_setting() {
26+
gh api --method PUT -H "Accept: application/vnd.github+json" --input - repos/${OWNER}/${REPO}/branches/${BRANCH}/protection
27+
}
28+
29+
function enfore_admins_off() {
30+
get_current_branch_protection_setting | jq '.enforce_admins = false' | apply_branch_protection_setting
31+
}
32+
33+
export -f enfore_admins_off
34+
35+
function enfore_admins_on() {
36+
get_current_branch_protection_setting | jq '.enforce_admins = true' | apply_branch_protection_setting
37+
}
38+
39+
export -f enfore_admins_on

0 commit comments

Comments
 (0)