Skip to content

Commit 0648a88

Browse files
committed
ci: replace branch-protection-bot with actions/github-script
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
1 parent b9d9744 commit 0648a88

2 files changed

Lines changed: 54 additions & 22 deletions

File tree

.github/workflows/bake_update.yml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,40 @@ jobs:
4444
git diff
4545
4646
- name: Temporarily disable "include administrators" branch protection
47-
if: ${{ always() && github.ref == 'refs/heads/main' }}
47+
if: always() && github.ref == 'refs/heads/main'
4848
id: disable_include_admins
49-
uses: benjefferies/branch-protection-bot@af281f37de86139d1c7a27b91176b5dc1c2c827c # v1.1.2
49+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
5050
with:
51-
access_token: ${{ secrets.REPO_GHA_PAT }}
52-
branch: main
53-
enforce_admins: false
51+
github-token: ${{ secrets.REPO_GHA_PAT }}
52+
script: |
53+
const params = {
54+
owner: 'cloudnative-pg',
55+
repo: 'postgres-containers',
56+
branch: 'main',
57+
};
58+
const { data } = await github.rest.repos.getAdminBranchProtection(params);
59+
core.setOutput('initial_status', data.enabled);
60+
if (data.enabled) {
61+
await github.rest.repos.deleteAdminBranchProtection(params);
62+
}
5463
5564
- uses: EndBug/add-and-commit@cc9c08ba6c8df3b93a8f2db63e89b98368ae2ae8 # v11
5665
with:
5766
author_name: CloudNativePG Automated Updates
5867
author_email: noreply@cnpg.com
5968
message: 'chore: update PostgreSQL versions'
6069

61-
- name: Enable "include administrators" branch protection
62-
uses: benjefferies/branch-protection-bot@af281f37de86139d1c7a27b91176b5dc1c2c827c # v1.1.2
63-
if: ${{ always() && github.ref == 'refs/heads/main' }}
70+
- name: Restore "include administrators" branch protection
71+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
72+
if: |
73+
always() &&
74+
github.ref == 'refs/heads/main' &&
75+
steps.disable_include_admins.outputs.initial_status == 'true'
6476
with:
65-
access_token: ${{ secrets.REPO_GHA_PAT }}
66-
branch: main
67-
enforce_admins: ${{ steps.disable_include_admins.outputs.initial_status }}
77+
github-token: ${{ secrets.REPO_GHA_PAT }}
78+
script: |
79+
await github.rest.repos.setAdminBranchProtection({
80+
owner: 'cloudnative-pg',
81+
repo: 'postgres-containers',
82+
branch: 'main',
83+
});

.github/workflows/catalogs.yml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,22 @@ jobs:
8383

8484
# TODO: remove this step once system images are EOL
8585
- name: Temporarily disable "include administrators" branch protection
86-
if: ${{ always() && github.ref == 'refs/heads/main' }}
86+
if: always() && github.ref == 'refs/heads/main'
8787
id: disable_include_admins
88-
uses: benjefferies/branch-protection-bot@af281f37de86139d1c7a27b91176b5dc1c2c827c # v1.1.2
88+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
8989
with:
90-
access_token: ${{ secrets.REPO_GHA_PAT }}
91-
branch: main
92-
enforce_admins: false
90+
github-token: ${{ secrets.REPO_GHA_PAT }}
91+
script: |
92+
const params = {
93+
owner: 'cloudnative-pg',
94+
repo: 'postgres-containers',
95+
branch: 'main',
96+
};
97+
const { data } = await github.rest.repos.getAdminBranchProtection(params);
98+
core.setOutput('initial_status', data.enabled);
99+
if (data.enabled) {
100+
await github.rest.repos.deleteAdminBranchProtection(params);
101+
}
93102
94103
# TODO: remove this step once system images are EOL
95104
- name: Legacy diff
@@ -110,10 +119,17 @@ jobs:
110119
message: 'chore: update imageCatalogs'
111120

112121
# TODO: remove this step once system images are EOL
113-
- name: Enable "include administrators" branch protection
114-
uses: benjefferies/branch-protection-bot@af281f37de86139d1c7a27b91176b5dc1c2c827c # v1.1.2
115-
if: ${{ always() && github.ref == 'refs/heads/main' }}
122+
- name: Restore "include administrators" branch protection
123+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
124+
if: |
125+
always() &&
126+
github.ref == 'refs/heads/main' &&
127+
steps.disable_include_admins.outputs.initial_status == 'true'
116128
with:
117-
access_token: ${{ secrets.REPO_GHA_PAT }}
118-
branch: main
119-
enforce_admins: ${{ steps.disable_include_admins.outputs.initial_status }}
129+
github-token: ${{ secrets.REPO_GHA_PAT }}
130+
script: |
131+
await github.rest.repos.setAdminBranchProtection({
132+
owner: 'cloudnative-pg',
133+
repo: 'postgres-containers',
134+
branch: 'main',
135+
});

0 commit comments

Comments
 (0)