@@ -3,71 +3,85 @@ name: Playwright Tests
33on :
44 deployment_status :
55
6- defaults :
7- run :
8- working-directory : ./
9-
10- permissions :
11- contents : read # for checkout repository
12-
136jobs :
147 run-e2es :
15- if : github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.ref != 'refs/heads/main'
8+ if : github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.ref != 'refs/heads/main' && github.event.deployment_status.environment == 'staging'
169 runs-on : ubuntu-latest
17- name : Run E2E tests
1810 steps :
1911 - name : Checkout repository
2012 uses : actions/checkout@v4
2113
22- - name : Install Node.js
23- uses : actions/setup-node@v4
24- with :
25- node-version : 20
26-
27- - name : Install pnpm
28- uses : pnpm/action-setup@v4
29- with :
30- version : latest
31-
32- - name : Install packages
33- run : pnpm install --frozen-lockfile
14+ - name : Install dependencies
15+ run : npm ci && npx playwright install --with-deps
3416
35- - name : Install Playwright dependencies
36- run : pnpm exec playwright install-deps
17+ - name : Create PandaDoc Webhook (drpcrd-staging)
18+ id : pandadoc-webhook
19+ run : |
20+ RESPONSE=$(curl -X POST "https://api.pandadoc.com/public/v1/webhooks" \
21+ -H "Authorization: Bearer ${{ secrets.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+ }')
3737
38- - name : Install Playwright
39- run : pnpm exec playwright install
38+ SHARED_KEY=$(echo "$RESPONSE" | jq -r '.shared_key')
39+ echo "PANDADOC_WEBHOOK_SHARED_KEY=$SHARED_KEY" >> $GITHUB_ENV
4040
41- - name : Configure PandaDoc Webhook
41+ - name : Store PandaDoc Webhook Key in Vercel
4242 run : |
43- curl -X POST https://api.pandadoc .com/public/v1/webhooks \
44- -H "Authorization: Bearer ${{ secrets.PANDADOC_API_KEY }}" \
43+ curl -X PATCH " https://api.vercel .com/v9/projects/${{ secrets.VERCEL_PROJECT_ID }}/env/PANDADOC_WEBHOOK_SHARED_KEY" \
44+ -H "Authorization: Bearer ${{ secrets.VERCEL_API_KEY }}" \
4545 -H "Content-Type: application/json" \
4646 -d '{
47- "url": "${{ github.event.deployment_status.environment_url }}/api/webhook/pandadoc",
48- "events": ["document.completed"],
49- "shared_key": "${{ secrets.PANDADOC_WEBHOOK_SHARED_KEY }}"
50- }'
47+ "value": "'${{ env.PANDADOC_WEBHOOK_SHARED_KEY }}'",
48+ "target": ["preview", "production"]
49+ }'
5150
52- - name : Set Vercel Environment Variable
51+ - name : Restart Vercel Deployment to Load Env Variables
5352 run : |
54- curl -X PATCH https://api.vercel.com/v9/projects/${{ secrets.VERCEL_PROJECT_ID }}/env \
55- -H "Authorization: Bearer ${{ secrets.VERCEL_API_TOKEN }}" \
53+ curl -X POST " https://api.vercel.com/v13/deployments" \
54+ -H "Authorization: Bearer ${{ secrets.VERCEL_API_KEY }}" \
5655 -H "Content-Type: application/json" \
5756 -d '{
58- "key": "PANDADOC_WEBHOOK_SHARED_KEY",
59- "value": "${{ secrets.PANDADOC_WEBHOOK_SHARED_KEY }}",
60- "target": ["staging"]
61- }'
57+ "name": "${{ secrets.VERCEL_PROJECT_ID }}",
58+ "target": "staging"
59+ }'
60+
61+ - name : Wait for Deployment to Complete
62+ run : sleep 30 # Allow time for the environment variables to take effect
6263
63- - name : Run E2E tests
64+ - name : Run Playwright Tests
6465 env :
65- NEXT_PUBLIC_URL : ${{ github.event.deployment_status.environment_url }}
66- run : pnpm test:e2e
66+ BASE_URL : ${{ github.event.deployment_status.environment_url }}
67+ run : npx playwright test
6768
6869 - name : Upload Playwright Report
69- if : always()
7070 uses : actions/upload-artifact@v4
71+ if : always()
72+ with :
73+ name : playwright-report
74+ path : playwright-report/
75+ retention-days : 7
76+
77+ - name : GitHub Notification
78+ if : failure()
79+ uses : actions/github-script@v6
7180 with :
72- name : reports
73- path : playwright/reports/
81+ script : |
82+ github.issues.createComment({
83+ issue_number: 1,
84+ owner: context.repo.owner,
85+ repo: context.repo.repo,
86+ body: "🚨 Playwright tests failed after deployment!"
87+ });
0 commit comments