diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 572fdb9..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,125 +0,0 @@ -name: CI/CD Workflow --> Deploy and Run E2E Tests - -on: - pull_request: - push: - branches: - - main - release: - types: [created] - -jobs: - deploy: - name: Deploy to Vercel - runs-on: ubuntu-latest - - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Install Vercel CLI - run: npm install --global vercel@latest - - - name: Pull Vercel Environment Information - run: | - if [[ "${{ github.event_name }}" == "release" ]]; then - vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} - else - vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} - fi - - - name: Build Project Artifacts - run: | - if [[ "${{ github.event_name }}" == "release" ]]; then - vercel build --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} - else - vercel build --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} - fi - - - name: Deploy to Vercel - id: deploy - run: | - if [[ "${{ github.event_name }}" == "release" ]]; then - DEPLOY_URL=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | tail -1) - else - DEPLOY_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | tail -1) - fi - echo "DEPLOYMENT_URL=${DEPLOY_URL}" >> $GITHUB_ENV - echo "Deployed to: $DEPLOY_URL" - - env: - VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} - - e2e: - name: Run E2E Tests - runs-on: ubuntu-latest - needs: deploy - - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Install pnpm - run: npm install -g pnpm - - - name: Install Dependencies - run: pnpm install - - - name: Install Playwright - run: pnpm playwright install - - - name: Run Playwright Tests - run: pnpm playwright test - env: - BASE_URL: ${{ env.DEPLOYMENT_URL }} - - - #notify: - # name: Notify Team on Failure - # runs-on: ubuntu-latest - # needs: e2e - # if: failure() - # steps: - # - name: Send Slack Notification - # uses: slackapi/slack-github-action@v1.24.0 - # with: - # payload: | - # { - # "text": "🚨 Production deployment failed! Check logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" - # } - # env: - # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} - -# rollback: - # name: Rollback on Failure - # runs-on: ubuntu-latest - # needs: e2e - # if: failure() - - # steps: - # - name: Checkout Code - # uses: actions/checkout@v3 - - # - name: Install Vercel CLI - # run: npm install --global vercel@latest - - # - name: Authenticate Vercel CLI - # run: vercel login --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} - - # - name: Get Last Successful Production Deployment - # id: get_last_deployment - # run: | - # echo "Fetching last successful production deployment..." - # LAST_DEPLOYMENT=$(vercel list --prod --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} | grep -Eo 'https://[a-zA-Z0-9.-]+\.vercel\.app' | tail -1) - # if [[ -z "$LAST_DEPLOYMENT" ]]; then - # echo "❌ No previous successful deployment found! Rollback failed." - # exit 1 - # fi - # echo "✅ Last successful deployment found: $LAST_DEPLOYMENT" - # echo "LAST_DEPLOYMENT=$LAST_DEPLOYMENT" >> $GITHUB_ENV - - # - name: Rollback to Last Working Deployment - # run: | - # echo "Rolling back to: $LAST_DEPLOYMENT" - # vercel promote $LAST_DEPLOYMENT --token=${{ secrets.VERCEL_TOKEN_MY_PROJECT }} - # echo "✅ Rollback successful! Restored $LAST_DEPLOYMENT" diff --git a/.github/workflows/panda-webhook.yml b/.github/workflows/panda-webhook.yml new file mode 100644 index 0000000..637fcf1 --- /dev/null +++ b/.github/workflows/panda-webhook.yml @@ -0,0 +1,158 @@ +# 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' +# runs-on: ubuntu-latest +# steps: +# - name: Checkout repository +# uses: actions/checkout@v4 + +# - name: Install dependencies +# run: npm ci && npx playwright install --with-deps + +# - name: Create PandaDoc Webhook +# id: pandadoc-webhook +# run: | +# RESPONSE=$(curl -X POST "https://api.pandadoc.com/public/v1/webhooks" \ +# -H "Authorization: Bearer ${{ env.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: 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!" +# }); + +name: Playwright Tests + +on: + deployment_status: + +permissions: + contents: read + issues: write # ✅ Required for issue comments + +jobs: + run-e2es: + if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && github.ref != 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: npm ci && npx playwright install --with-deps + + - name: Create PandaDoc Webhook + id: pandadoc-webhook + run: | + # Check if PANDADOC_API_KEY is set + if [[ -z "${{ env.PANDADOC_API_KEY }}" ]]; then + echo "❌ PandaDoc API Key is missing!" + exit 1 + fi + + # Make the API request + RESPONSE=$(curl -s -X POST "https://api.pandadoc.com/public/v1/webhooks" \ + -H "Authorization: Bearer ${{ env.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" + ] + }') + + # Validate the response before using jq + if [[ -z "$RESPONSE" || "$RESPONSE" == "null" ]]; then + echo "❌ Error: No response received from PandaDoc API" + exit 1 + fi + + echo "📩 API Response: $RESPONSE" + + # Extract shared_key from response using jq + SHARED_KEY=$(echo "$RESPONSE" | jq -r '.shared_key') + + # Check if shared_key is valid + if [[ "$SHARED_KEY" == "null" || -z "$SHARED_KEY" ]]; then + echo "❌ Failed to create PandaDoc webhook. API response: $RESPONSE" + exit 1 + fi + + echo "✅ PandaDoc Webhook Created Successfully!" + echo "PANDADOC_WEBHOOK_SHARED_KEY=$SHARED_KEY" >> $GITHUB_ENV + + - 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: + github-token: ${{ secrets.GITHUB_TOKEN }} # ✅ Fix GitHub API auth + script: | + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: 1, + body: "🚨 Playwright tests failed after deployment!" + });