Skip to content

Commit ed604c7

Browse files
Merge pull request #14 from HichemTab-tech/fix-workflow
Restrict auto-bumper to maintainers only
2 parents 1e92ab3 + 60118dc commit ed604c7

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

.github/workflows/auto-bumper.yml

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,43 @@ jobs:
1515
runs-on: ubuntu-latest
1616
if: (contains( github.event.pull_request.labels.*.name, 'auto-bump') || (contains(github.event.comment.body, '@github-bot') && contains(github.event.comment.body, 'bump')))
1717
steps:
18+
- name: Check permissions (maintainer-only)
19+
id: perm
20+
uses: actions/github-script@v7
21+
with:
22+
script: |
23+
const { owner, repo } = context.repo;
24+
const username = context.payload.comment?.user?.login;
25+
if (!username) {
26+
core.setFailed('No commenter found in payload.');
27+
return;
28+
}
29+
// Determine the commenter's permission level on this repo
30+
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
31+
owner,
32+
repo,
33+
username,
34+
});
35+
const allowed = ['admin', 'maintain'].includes(data.permission);
36+
core.setOutput('allowed', String(allowed));
37+
38+
- name: Deny if not maintainer
39+
if: steps.perm.outputs.allowed != 'true'
40+
uses: actions/github-script@v7
41+
with:
42+
script: |
43+
const { owner, repo } = context.repo;
44+
const issue_number = context.issue.number;
45+
const login = context.payload.comment?.user?.login || 'user';
46+
await github.rest.issues.createComment({
47+
owner,
48+
repo,
49+
issue_number,
50+
body: `❌ @${login}, only maintainers can bump versions. Please ask a maintainer to run "@github-bot bump".`
51+
});
1852
1953
- name: React 👍 to triggering comment
54+
if: steps.perm.outputs.allowed == 'true'
2055
uses: actions/github-script@v7
2156
with:
2257
script: |
@@ -48,13 +83,15 @@ jobs:
4883
}
4984
5085
- name: Checkout
86+
if: steps.perm.outputs.allowed == 'true'
5187
uses: actions/checkout@v4
5288
with:
5389
ref: ${{ github.event.pull_request.head.ref }}
5490
fetch-depth: 0
5591
token: ${{ secrets.GITHUB_TOKEN }}
5692

5793
- name: Add comment to PR
94+
if: steps.perm.outputs.allowed == 'true'
5895
uses: actions/github-script@v7
5996
with:
6097
script: |
@@ -67,31 +104,36 @@ jobs:
67104
body: `Okay BOSS, ⏳ Bumping version from ${pkg.version}...`
68105
})
69106
70-
71107
- name: Setup Node & pnpm
108+
if: steps.perm.outputs.allowed == 'true'
72109
uses: actions/setup-node@v3
73110
with:
74111
node-version: '23'
75112

76113
- name: Install pnpm
114+
if: steps.perm.outputs.allowed == 'true'
77115
run: npm install -g pnpm
78116

79117
- name: Install dependencies
118+
if: steps.perm.outputs.allowed == 'true'
80119
run: pnpm install
81120

82121
- name: Configure Git
122+
if: steps.perm.outputs.allowed == 'true'
83123
run: |
84124
git config --global user.name 'GitHub Action'
85125
git config --global user.email '[email protected]'
86126
87127
- name: Bump version
128+
if: steps.perm.outputs.allowed == 'true'
88129
run: |
89130
pnpm run bump
90131
git add package.json
91132
git commit -m "chore: bump version"
92133
git push
93134
94135
- name: Add comment to PR
136+
if: steps.perm.outputs.allowed == 'true'
95137
uses: actions/github-script@v7
96138
with:
97139
script: |
@@ -102,5 +144,4 @@ jobs:
102144
owner: context.repo.owner,
103145
repo: context.repo.repo,
104146
body: `✅ Version bumped to ${pkg.version}`
105-
})
106-
147+
})

0 commit comments

Comments
 (0)