Skip to content

Commit 807bb73

Browse files
Merge pull request #18 from WilderForge/ghsa
Fix #17 - GHSA-m6r3-c73x-8fw5
2 parents 1ea67ab + cdd7775 commit 807bb73

3 files changed

Lines changed: 44 additions & 132 deletions

File tree

.github/workflows/RebuildApprovedPR.yml

Lines changed: 0 additions & 98 deletions
This file was deleted.

.github/workflows/ValidateApproval.yaml

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ on:
44
pull_request_review:
55
types: [submitted]
66

7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
actions: write
11+
statuses: write
12+
713
jobs:
814
approve_and_run:
915
runs-on: ubuntu-latest
@@ -24,29 +30,24 @@ jobs:
2430
)
2531
)
2632
steps:
27-
- name: Checking Approval
33+
- name: Handle Approved Review
34+
if: |
35+
github.event.review.state == 'approved' || startsWith(github.event.review.body, 'approved')
2836
id: "checking_approval"
2937
run: |
30-
DESC="null"
31-
if [[ "${{ github.event.review.state }}" == "approved" || "${{ github.event.review.body }}" == approved* ]]; then
32-
DESC="${{ github.event.review.user.login }} APPROVED build for ${{ github.event.review.commit_id }}"
33-
echo $DESC
34-
echo "conclusion=success" >> "$GITHUB_ENV"
35-
echo "description=$DESC" >> "$GITHUB_ENV"
36-
exit 0
37-
elif [[ "${{ github.event.review.body }}" == reject* ]]; then
38-
DESC="${{ github.event.review.user.login }} REJECTED build for ${{ github.event.review.commit_id }}"
39-
echo $DESC
40-
echo "conclusion=failure" >> "$GITHUB_ENV"
41-
echo "description=$DESC" >> "$GITHUB_ENV"
42-
exit 1
43-
else
44-
DESC="Assertion Error: Review body expected start with 'approved' or 'reject'. This step should have been skipped but it ran anyway!"
45-
echo $DESC
46-
echo "conclusion=failure" >> "$GITHUB_ENV"
47-
echo "description=$DESC" >> "$GITHUB_ENV"
48-
exit 1
49-
fi
38+
DESC="${{ github.event.review.user.login }} APPROVED build for ${{ github.event.review.commit_id }}"
39+
echo "$DESC"
40+
echo "conclusion=success" >> "$GITHUB_ENV"
41+
echo "description=$DESC" >> "$GITHUB_ENV"
42+
43+
- name: Rejected Review Handling
44+
if: startsWith(github.event.review.body, 'reject')
45+
run: |
46+
DESC="${{ github.event.review.user.login }} REJECTED build for ${{ github.event.review.commit_id }}"
47+
echo "$DESC"
48+
echo "conclusion=failure" >> "$GITHUB_ENV"
49+
echo "description=$DESC" >> "$GITHUB_ENV"
50+
exit 1
5051
5152
- name: Post Status Check
5253
if:
@@ -76,23 +77,28 @@ jobs:
7677

7778
- name: Trigger Build Commit Workflow
7879
if: success()
80+
env:
81+
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
7982
run: |
80-
# Get the source branch of the PR (from the pull_request object)
81-
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
82-
83+
echo "Triggering workflow for branch: $PR_BRANCH"
84+
85+
# Construct JSON payload safely using jq
86+
JSON_PAYLOAD=$(jq -n --arg ref "refs/heads/$PR_BRANCH" \
87+
--arg sha "${{ github.event.review.commit_id }}" \
88+
'{ref: $ref, inputs: {sha: $sha}}')
89+
8390
# Define the API endpoint for dispatching the workflow
8491
WORKFLOW_URL="https://api.github.com/repos/${{ github.repository }}/actions/workflows/build.yml/dispatches"
85-
86-
# Trigger the workflow for the branch of the pull request
87-
echo "Triggering workflow for branch: $PR_BRANCH"
88-
RESPONSE=$(curl -s -w "%{http_code}" -o response.json -X POST \
92+
93+
# Trigger the workflow
94+
HTTP_CODE=$(curl -s -o response.json -w "%{http_code}" -X POST \
8995
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
90-
-d '{"ref": "refs/heads/'${PR_BRANCH}'", "inputs": {"sha": "${{ github.event.review.commit_id }}"}}' \
96+
-H "Accept: application/vnd.github.v3+json" \
97+
-d "$JSON_PAYLOAD" \
9198
"$WORKFLOW_URL")
92-
93-
# Check if the HTTP status code is 2xx (successful)
94-
if [[ "$RESPONSE" -lt 200 || "$RESPONSE" -ge 300 ]]; then
95-
echo "Error triggering the workflow: HTTP $RESPONSE"
99+
100+
if [[ "$HTTP_CODE" -lt 200 || "$HTTP_CODE" -ge 300 ]]; then
101+
echo "Error triggering the workflow: HTTP $HTTP_CODE"
96102
cat response.json
97103
exit 1
98104
else

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
branches:
1414
- master
1515

16+
permissions:
17+
contents: read
18+
statuses: write
19+
1620
jobs:
1721
build_commit:
1822
runs-on: [self-hosted, linux]
@@ -95,4 +99,4 @@ jobs:
9599
\"context\": \"Build Status\",
96100
\"target_url\": \"$TARGET_URL\"
97101
}" \
98-
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.COMMIT_SHA }}"
102+
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.COMMIT_SHA }}"

0 commit comments

Comments
 (0)