Playwright Tests #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Playwright Tests | |
| on: | |
| deployment_status: | |
| jobs: | |
| run-e2es: | |
| if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.ref != 'refs/heads/main' && github.event.deployment_status.environment == 'staging' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: npm ci && npx playwright install --with-deps | |
| - name: Fetch Required Secrets from Vercel API | |
| id: fetch-secrets | |
| run: | | |
| # Fetch Vercel Project ID | |
| VERCEL_PROJECT_ID=$(curl -s -X GET "https://api.vercel.com/v9/projects" \ | |
| -H "Authorization: Bearer $(curl -s "https://api.vercel.com/v9/projects/drpcrd-staging/env" | jq -r '.envs[] | select(.key=="VERCEL_API_KEY") | .value')" \ | |
| | jq -r '.projects[] | select(.name=="drpcrd-staging") | .id') | |
| # Fetch Vercel API Key | |
| VERCEL_API_KEY=$(curl -s "https://api.vercel.com/v9/projects/$VERCEL_PROJECT_ID/env" \ | |
| | jq -r '.envs[] | select(.key=="VERCEL_API_KEY") | .value') | |
| # Fetch PandaDoc API Key | |
| PANDADOC_API_KEY=$(curl -s "https://api.vercel.com/v9/projects/$VERCEL_PROJECT_ID/env" \ | |
| | jq -r '.envs[] | select(.key=="PANDADOC_API_KEY") | .value') | |
| # Export to GitHub Actions env | |
| echo "VERCEL_PROJECT_ID=$VERCEL_PROJECT_ID" >> $GITHUB_ENV | |
| echo "VERCEL_API_KEY=$VERCEL_API_KEY" >> $GITHUB_ENV | |
| echo "PANDADOC_API_KEY=$PANDADOC_API_KEY" >> $GITHUB_ENV | |
| - name: Create PandaDoc Webhook (drpcrd-staging) | |
| id: pandadoc-webhook | |
| run: | | |
| RESPONSE=$(curl -X POST "https://api.pandadoc.com/public/v1/webhooks" \ | |
| -H "Authorization: Bearer $PANDADOC_API_KEY" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "name": "drpcrd-staging", | |
| "url": "${{ github.event.deployment_status.environment_url }}/api/webhook/pandadoc", | |
| "event_types": [ | |
| "document.creation_failed", | |
| "document.deleted", | |
| "document.section_added", | |
| "document.state_changed", | |
| "document.updated", | |
| "document.completed", | |
| "pdf.completed", | |
| "recipient.completed_document" | |
| ] | |
| }') | |
| SHARED_KEY=$(echo "$RESPONSE" | jq -r '.shared_key') | |
| echo "PANDADOC_WEBHOOK_SHARED_KEY=$SHARED_KEY" >> $GITHUB_ENV | |
| - name: Store PandaDoc Webhook Key in Vercel | |
| run: | | |
| curl -X PATCH "https://api.vercel.com/v9/projects/$VERCEL_PROJECT_ID/env/PANDADOC_WEBHOOK_SHARED_KEY" \ | |
| -H "Authorization: Bearer $VERCEL_API_KEY" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "value": "'${{ env.PANDADOC_WEBHOOK_SHARED_KEY }}'", | |
| "target": ["preview", "production"] | |
| }' | |
| - name: Restart Vercel Deployment to Load Env Variables | |
| run: | | |
| curl -X POST "https://api.vercel.com/v13/deployments" \ | |
| -H "Authorization: Bearer $VERCEL_API_KEY" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "name": "drpcrd-staging", | |
| "target": "staging" | |
| }' | |
| - name: Wait for Deployment to Complete | |
| run: sleep 30 # Allow time for the environment variables to take effect | |
| - name: Run Playwright Tests | |
| env: | |
| BASE_URL: ${{ github.event.deployment_status.environment_url }} | |
| run: npx playwright test | |
| - name: Upload Playwright Report | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: playwright-report | |
| path: playwright-report/ | |
| retention-days: 7 | |
| - name: GitHub Notification | |
| if: failure() | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| github.issues.createComment({ | |
| issue_number: 1, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: "🚨 Playwright tests failed after deployment!" | |
| }); |