Skip to content

Commit 4c23b89

Browse files
fix: enhance GitHub Actions workflow with error handling and API response validation for PandaDoc webhook creation
1 parent dbf7ce9 commit 4c23b89

File tree

1 file changed

+98
-4
lines changed

1 file changed

+98
-4
lines changed

.github/workflows/panda-webhook.yml

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,77 @@
1+
# name: Playwright Tests
2+
3+
# on:
4+
# deployment_status:
5+
6+
# jobs:
7+
# run-e2es:
8+
# if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.ref != 'refs/heads/main'
9+
# runs-on: ubuntu-latest
10+
# steps:
11+
# - name: Checkout repository
12+
# uses: actions/checkout@v4
13+
14+
# - name: Install dependencies
15+
# run: npm ci && npx playwright install --with-deps
16+
17+
# - name: Create PandaDoc Webhook
18+
# id: pandadoc-webhook
19+
# run: |
20+
# RESPONSE=$(curl -X POST "https://api.pandadoc.com/public/v1/webhooks" \
21+
# -H "Authorization: Bearer ${{ env.PANDADOC_API_KEY }}" \
22+
# -H "Content-Type: application/json" \
23+
# -d '{
24+
# "name": "drpcrd-staging",
25+
# "url": "${{ github.event.deployment_status.environment_url }}/api/webhook/pandadoc",
26+
# "event_types": [
27+
# "document.creation_failed",
28+
# "document.deleted",
29+
# "document.section_added",
30+
# "document.state_changed",
31+
# "document.updated",
32+
# "document.completed",
33+
# "pdf.completed",
34+
# "recipient.completed_document"
35+
# ]
36+
# }')
37+
38+
# SHARED_KEY=$(echo "$RESPONSE" | jq -r '.shared_key')
39+
# echo "PANDADOC_WEBHOOK_SHARED_KEY=$SHARED_KEY" >> $GITHUB_ENV
40+
41+
# - name: Run Playwright tests
42+
# env:
43+
# BASE_URL: ${{ github.event.deployment_status.environment_url }}
44+
# run: npx playwright test
45+
46+
# - name: Upload Playwright Report
47+
# uses: actions/upload-artifact@v4
48+
# if: always()
49+
# with:
50+
# name: playwright-report
51+
# path: playwright-report/
52+
# retention-days: 7
53+
54+
# - name: GitHub Notification
55+
# if: failure()
56+
# uses: actions/github-script@v6
57+
# with:
58+
# script: |
59+
# github.issues.createComment({
60+
# issue_number: 1,
61+
# owner: context.repo.owner,
62+
# repo: context.repo.repo,
63+
# body: "🚨 Playwright tests failed after deployment!"
64+
# });
65+
166
name: Playwright Tests
267

368
on:
469
deployment_status:
570

71+
permissions:
72+
contents: read
73+
issues: write # ✅ Required for issue comments
74+
675
jobs:
776
run-e2es:
877
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.ref != 'refs/heads/main'
@@ -17,12 +86,19 @@ jobs:
1786
- name: Create PandaDoc Webhook
1887
id: pandadoc-webhook
1988
run: |
20-
RESPONSE=$(curl -X POST "https://api.pandadoc.com/public/v1/webhooks" \
89+
# Check if PANDADOC_API_KEY is set
90+
if [[ -z "${{ env.PANDADOC_API_KEY }}" ]]; then
91+
echo "❌ PandaDoc API Key is missing!"
92+
exit 1
93+
fi
94+
95+
# Make the API request
96+
RESPONSE=$(curl -s -X POST "https://api.pandadoc.com/public/v1/webhooks" \
2197
-H "Authorization: Bearer ${{ env.PANDADOC_API_KEY }}" \
2298
-H "Content-Type: application/json" \
2399
-d '{
24100
"name": "drpcrd-staging",
25-
"url": "${{ github.event.deployment_status.environment_url }}/api/webhook/pandadoc",
101+
"url": "'"${{ github.event.deployment_status.environment_url }}"'/api/webhook/pandadoc",
26102
"event_types": [
27103
"document.creation_failed",
28104
"document.deleted",
@@ -35,7 +111,24 @@ jobs:
35111
]
36112
}')
37113
114+
# Validate the response before using jq
115+
if [[ -z "$RESPONSE" || "$RESPONSE" == "null" ]]; then
116+
echo "❌ Error: No response received from PandaDoc API"
117+
exit 1
118+
fi
119+
120+
echo "📩 API Response: $RESPONSE"
121+
122+
# Extract shared_key from response using jq
38123
SHARED_KEY=$(echo "$RESPONSE" | jq -r '.shared_key')
124+
125+
# Check if shared_key is valid
126+
if [[ "$SHARED_KEY" == "null" || -z "$SHARED_KEY" ]]; then
127+
echo "❌ Failed to create PandaDoc webhook. API response: $RESPONSE"
128+
exit 1
129+
fi
130+
131+
echo "✅ PandaDoc Webhook Created Successfully!"
39132
echo "PANDADOC_WEBHOOK_SHARED_KEY=$SHARED_KEY" >> $GITHUB_ENV
40133
41134
- name: Run Playwright tests
@@ -55,10 +148,11 @@ jobs:
55148
if: failure()
56149
uses: actions/github-script@v6
57150
with:
151+
github-token: ${{ secrets.GITHUB_TOKEN }} # ✅ Fix GitHub API auth
58152
script: |
59-
github.issues.createComment({
60-
issue_number: 1,
153+
github.rest.issues.createComment({
61154
owner: context.repo.owner,
62155
repo: context.repo.repo,
156+
issue_number: 1,
63157
body: "🚨 Playwright tests failed after deployment!"
64158
});

0 commit comments

Comments
 (0)