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

Commit 2342c73

Browse files
authored
Merge pull request #1 from SpringQL/ci/release-workflow-test
add branch protection toggling
2 parents e74ce51 + f8148e2 commit 2342c73

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

.github/workflows/release.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
uses: actions/checkout@v2
2727
with:
2828
ref: main
29+
token: ${{ secrets.GHPAT_FOR_PUSH_RELEASE }}
2930

3031
- name: Show initial git status
3132
run: |
@@ -87,8 +88,6 @@ jobs:
8788
- name: git tag
8889
run: |
8990
git tag "v${RELEASE_VERSION}"
90-
git tag "springql@${RELASE_VERSION}"
91-
git tag "springql-core@${RELASE_VERSION}"
9291
9392
- name: Show final git status
9493
run: |
@@ -97,13 +96,25 @@ jobs:
9796
git status -v >> $GITHUB_STEP_SUMMARY
9897
echo '```' >> $GITHUB_STEP_SUMMARY
9998
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+
100106
- name: git push
101107
run: |
102-
git remote set-url origin https://github-actions:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}
103-
git push -v origin main
104-
git push -v origin "v${RELEASE_VERSION}"
105-
git push -v origin "springql@${RELEASE_VERSION}"
106-
git push -v origin "springql-core@${RELEASE_VERSION}"
108+
git remote set-url origin "https://github-actions:${{ secrets.GHPAT_FOR_PUSH_RELEASE }}@github.com/${GITHUB_REPOSITORY}"
109+
git push -v --force origin main
110+
git push -v --force origin "v${RELEASE_VERSION}"
111+
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
107118
108119
- name: cargo publish
109120
run: |
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)