Skip to content

Commit 0c2efee

Browse files
committed
use group
Signed-off-by: Paul Spooren <mail@aparcar.org>
1 parent b67a707 commit 0c2efee

1 file changed

Lines changed: 34 additions & 19 deletions

File tree

.github/workflows/build-on-comment.yml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,33 @@ on:
44
issue_comment:
55
types: [created, edited]
66

7+
concurrency:
8+
group: build-on-comment-${{ github.event.issue.number || github.event.pull_request.number }}
9+
cancel-in-progress: true
10+
711
jobs:
812
check-and-build:
913
if: github.event.issue.pull_request != null
1014
runs-on: ubuntu-latest
1115

1216
steps:
13-
- name: Checkout repository
14-
uses: actions/checkout@v4
15-
with:
16-
token: ${{ secrets.GITHUB_TOKEN }}
17-
fetch-depth: 0
18-
ref: refs/pull/${{ github.event.issue.number }}/merge
19-
20-
- name: Check if user is in CODEOWNERS
21-
id: check-codeowners
17+
- name: Check if user is in reviewers team
18+
id: check-reviewer
2219
run: |
23-
if [ -f .github/CODEOWNERS ]; then
24-
USERNAME="${{ github.event.comment.user.login }}"
25-
if grep -w "@$USERNAME" .github/CODEOWNERS || grep -w "$USERNAME" .github/CODEOWNERS; then
26-
echo "authorized=true" >> $GITHUB_OUTPUT
27-
else
28-
echo "authorized=false" >> $GITHUB_OUTPUT
29-
fi
20+
USERNAME="${{ github.event.comment.user.login }}"
21+
22+
STATUS_CODE=$(curl -s -H "Authorization: token ${{ secrets.LOOKUP_MEMBERS }}" \
23+
-o response.json -w "%{http_code}" \
24+
https://api.github.com/orgs/openwrt/teams/reviewers/memberships/$USERNAME)
25+
26+
if grep -q '"state": "active"' response.json && [ "$STATUS_CODE" -eq 200 ]; then
27+
echo "authorized=true" >> $GITHUB_OUTPUT
3028
else
31-
echo "Not authorized"
32-
exit 1
29+
echo "authorized=false" >> $GITHUB_OUTPUT
3330
fi
3431
3532
- name: Parse build command
36-
if: steps.check-codeowners.outputs.authorized == 'true'
33+
if: steps.check-reviewer.outputs.authorized == 'true'
3734
id: parse-command
3835
run: |
3936
COMMENT="${{ github.event.comment.body }}"
@@ -51,19 +48,36 @@ jobs:
5148
echo "build_requested=false" >> $GITHUB_OUTPUT
5249
fi
5350
51+
- name: Find existing build comment
52+
if: steps.parse-command.outputs.build_requested == 'true'
53+
id: find-comment
54+
uses: peter-evans/find-comment@v2
55+
with:
56+
issue-number: ${{ github.event.pull_request.number || github.event.issue.number }}
57+
comment-author: "github-actions[bot]"
58+
5459
- name: Create early build comment
5560
if: steps.parse-command.outputs.build_requested == 'true'
5661
id: start-comment
5762
uses: peter-evans/create-or-update-comment@v3
5863
with:
5964
issue-number: ${{ github.event.pull_request.number || github.event.issue.number }}
65+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
6066
body: |
6167
🚧 **Build in progress for** `${{ steps.parse-command.outputs.build_path }}`...
6268
6369
You can follow progress [here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
6470
6571
*Triggered by: @${{ github.event.comment.user.login }}*
6672
73+
- name: Checkout repository
74+
if: steps.check-reviewer.outputs.build_requested == 'true'
75+
uses: actions/checkout@v4
76+
with:
77+
token: ${{ secrets.GITHUB_TOKEN }}
78+
fetch-depth: 0
79+
ref: refs/pull/${{ github.event.issue.number }}/merge
80+
6781
- name: Setup build environment
6882
if: steps.parse-command.outputs.build_requested == 'true'
6983
continue-on-error: true
@@ -92,6 +106,7 @@ jobs:
92106
93107
- name: Upload log
94108
uses: actions/upload-artifact@v4
109+
if: steps.check-reviewer.outputs.authorized == 'true' && (success() || failure())
95110
with:
96111
name: build-log-${{ steps.parse-command.outputs.target }}-${{ steps.parse-command.outputs.subtarget }}-${{ steps.parse-command.outputs.profile }}
97112
path: logs/

0 commit comments

Comments
 (0)