Skip to content

Commit bc1f592

Browse files
Thomo1318Thomo1318
authored andcommitted
fix(ci): use pull_request_target for PR write access
GITHUB_TOKEN has restricted permissions on pull_request events
1 parent 7a0f7bb commit bc1f592

File tree

2 files changed

+54
-29
lines changed

2 files changed

+54
-29
lines changed

.github/workflows/badgetizr.yml

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Badgetizr PR Badges
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types:
66
- opened
77
- reopened
@@ -13,6 +13,11 @@ concurrency:
1313
group: badgetizr-${{ github.event.pull_request.number }}
1414
cancel-in-progress: true
1515

16+
permissions:
17+
contents: read
18+
pull-requests: write
19+
issues: write
20+
1621
jobs:
1722
badgetizr-start:
1823
# Skip Dependabot PRs
@@ -23,20 +28,29 @@ jobs:
2328
- name: Checkout
2429
uses: actions/checkout@v4
2530

31+
- name: Clone Badgetizr
32+
run: |
33+
git clone --depth 1 --branch 3.0.2 https://github.com/aiKrice/homebrew-badgetizr.git /tmp/badgetizr
34+
chmod +x /tmp/badgetizr/badgetizr
35+
36+
- name: Install dependencies
37+
run: |
38+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
39+
sudo chmod +x /usr/local/bin/yq
40+
2641
- name: Badgetizr - Start
27-
uses: aiKrice/homebrew-badgetizr@3.0.2
28-
with:
29-
pr_id: ${{ github.event.pull_request.number }}
30-
configuration: .badgetizr.yml
31-
pr_destination_branch: ${{ github.event.pull_request.base.ref }}
32-
pr_build_number: ${{ github.run_id }}
33-
pr_build_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
34-
ci_status: "started"
35-
ci_text: "Running CI"
42+
run: |
43+
cd /tmp/badgetizr
44+
./badgetizr -c $GITHUB_WORKSPACE/.badgetizr.yml \
45+
--pr-id=${{ github.event.pull_request.number }} \
46+
--pr-destination-branch=${{ github.event.pull_request.base.ref }} \
47+
--pr-build-number=${{ github.run_id }} \
48+
--pr-build-url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
49+
--ci-status=started \
50+
--ci-text="Running CI"
3651
env:
3752
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3853

39-
# Wait for other CI jobs to complete
4054
badgetizr-result:
4155
needs: [badgetizr-start]
4256
runs-on: ubuntu-latest
@@ -46,28 +60,38 @@ jobs:
4660
- name: Checkout
4761
uses: actions/checkout@v4
4862

63+
- name: Clone Badgetizr
64+
run: |
65+
git clone --depth 1 --branch 3.0.2 https://github.com/aiKrice/homebrew-badgetizr.git /tmp/badgetizr
66+
chmod +x /tmp/badgetizr/badgetizr
67+
68+
- name: Install dependencies
69+
run: |
70+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
71+
sudo chmod +x /usr/local/bin/yq
72+
4973
- name: Badgetizr - Success
50-
if: ${{ success() }}
51-
uses: aiKrice/homebrew-badgetizr@3.0.2
52-
with:
53-
pr_id: ${{ github.event.pull_request.number }}
54-
configuration: .badgetizr.yml
55-
pr_destination_branch: ${{ github.event.pull_request.base.ref }}
56-
pr_build_number: ${{ github.run_id }}
57-
pr_build_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
58-
ci_status: "passed"
74+
if: ${{ needs.badgetizr-start.result == 'success' }}
75+
run: |
76+
cd /tmp/badgetizr
77+
./badgetizr -c $GITHUB_WORKSPACE/.badgetizr.yml \
78+
--pr-id=${{ github.event.pull_request.number }} \
79+
--pr-destination-branch=${{ github.event.pull_request.base.ref }} \
80+
--pr-build-number=${{ github.run_id }} \
81+
--pr-build-url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
82+
--ci-status=passed
5983
env:
6084
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6185

6286
- name: Badgetizr - Failed
63-
if: ${{ failure() }}
64-
uses: aiKrice/homebrew-badgetizr@3.0.2
65-
with:
66-
pr_id: ${{ github.event.pull_request.number }}
67-
configuration: .badgetizr.yml
68-
pr_destination_branch: ${{ github.event.pull_request.base.ref }}
69-
pr_build_number: ${{ github.run_id }}
70-
pr_build_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
71-
ci_status: "failed"
87+
if: ${{ needs.badgetizr-start.result != 'success' }}
88+
run: |
89+
cd /tmp/badgetizr
90+
./badgetizr -c $GITHUB_WORKSPACE/.badgetizr.yml \
91+
--pr-id=${{ github.event.pull_request.number }} \
92+
--pr-destination-branch=${{ github.event.pull_request.base.ref }} \
93+
--pr-build-number=${{ github.run_id }} \
94+
--pr-build-url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
95+
--ci-status=failed
7296
env:
7397
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test-badgetizr.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test PR

0 commit comments

Comments
 (0)