|
| 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 | + |
| 66 | +name: Playwright Tests |
| 67 | + |
| 68 | +on: |
| 69 | + deployment_status: |
| 70 | + |
| 71 | +permissions: |
| 72 | + contents: read |
| 73 | + issues: write # ✅ Required for issue comments |
| 74 | + |
| 75 | +jobs: |
| 76 | + run-e2es: |
| 77 | + if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.event.deployment_status.environment == 'staging' |
| 78 | + runs-on: ubuntu-latest |
| 79 | + steps: |
| 80 | + - name: Checkout repository |
| 81 | + uses: actions/checkout@v4 |
| 82 | + |
| 83 | + - name: Install dependencies |
| 84 | + run: npm ci && npx playwright install --with-deps |
| 85 | + |
| 86 | + - name: Create PandaDoc Webhook |
| 87 | + id: pandadoc-webhook |
| 88 | + run: | |
| 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" \ |
| 97 | + -H "Authorization: Bearer ${{ env.PANDADOC_API_KEY }}" \ |
| 98 | + -H "Content-Type: application/json" \ |
| 99 | + -d '{ |
| 100 | + "name": "drpcrd-staging", |
| 101 | + "url": "'"${{ github.event.deployment_status.environment_url }}"'/api/webhook/pandadoc", |
| 102 | + "event_types": [ |
| 103 | + "document.creation_failed", |
| 104 | + "document.deleted", |
| 105 | + "document.section_added", |
| 106 | + "document.state_changed", |
| 107 | + "document.updated", |
| 108 | + "document.completed", |
| 109 | + "pdf.completed", |
| 110 | + "recipient.completed_document" |
| 111 | + ] |
| 112 | + }') |
| 113 | +
|
| 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 |
| 123 | + 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!" |
| 132 | + echo "PANDADOC_WEBHOOK_SHARED_KEY=$SHARED_KEY" >> $GITHUB_ENV |
| 133 | +
|
| 134 | + - name: Run Playwright tests |
| 135 | + env: |
| 136 | + BASE_URL: ${{ github.event.deployment_status.environment_url }} |
| 137 | + run: npx playwright test |
| 138 | + |
| 139 | + - name: Upload Playwright Report |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + if: always() |
| 142 | + with: |
| 143 | + name: playwright-report |
| 144 | + path: playwright-report/ |
| 145 | + retention-days: 7 |
| 146 | + |
| 147 | + - name: GitHub Notification |
| 148 | + if: failure() |
| 149 | + uses: actions/github-script@v6 |
| 150 | + with: |
| 151 | + github-token: ${{ secrets.GITHUB_TOKEN }} # ✅ Fix GitHub API auth |
| 152 | + script: | |
| 153 | + github.rest.issues.createComment({ |
| 154 | + owner: context.repo.owner, |
| 155 | + repo: context.repo.repo, |
| 156 | + issue_number: 1, |
| 157 | + body: "🚨 Playwright tests failed after deployment!" |
| 158 | + }); |
0 commit comments