Deploy to Cloudflare #323
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: Deploy to Cloudflare | |
| permissions: | |
| contents: read | |
| deployments: write | |
| checks: write | |
| on: | |
| workflow_run: | |
| workflows: ["Test"] | |
| types: | |
| - completed | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| name: Deploy to Cloudflare | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| # pnpm/action-setup@v4 | |
| - uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda | |
| name: Install pnpm | |
| with: | |
| run_install: false | |
| - name: Get pnpm store directory | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
| - uses: actions/cache@v4 | |
| name: Setup pnpm cache | |
| with: | |
| path: ${{ env.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| - name: Install dependencies | |
| run: pnpm install | |
| # === BUILD AND DEPLOY CANARY WORKER === | |
| - name: Build | |
| run: pnpm -w run build | |
| env: | |
| SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
| - name: Deploy to Canary Worker | |
| id: deploy_canary | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: packages/mcp-cloudflare | |
| command: deploy --config wrangler.canary.jsonc | |
| packageManager: pnpm | |
| - name: Wait for Canary to Propagate | |
| if: success() | |
| run: | | |
| echo "Waiting 30 seconds for canary deployment to propagate..." | |
| sleep 30 | |
| # === SMOKE TEST CANARY === | |
| - name: Run Smoke Tests on Canary | |
| id: canary_smoke_tests | |
| if: success() | |
| env: | |
| PREVIEW_URL: https://sentry-mcp-canary.getsentry.workers.dev | |
| run: | | |
| echo "Running smoke tests against canary worker..." | |
| cd packages/smoke-tests | |
| pnpm test:ci | |
| - name: Publish Canary Smoke Test Report | |
| uses: mikepenz/action-junit-report@cf701569b05ccdd861a76b8607a66d76f6fd4857 | |
| if: always() && steps.canary_smoke_tests.outcome != 'skipped' | |
| with: | |
| report_paths: "packages/smoke-tests/tests.junit.xml" | |
| check_name: "Canary Smoke Test Results" | |
| fail_on_failure: false | |
| # === DEPLOY PRODUCTION WORKER (only if canary tests pass) === | |
| - name: Deploy to Production Worker | |
| id: deploy_production | |
| if: steps.canary_smoke_tests.outcome == 'success' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: packages/mcp-cloudflare | |
| command: deploy | |
| packageManager: pnpm | |
| - name: Wait for Production to Propagate | |
| if: steps.deploy_production.outcome == 'success' | |
| run: | | |
| echo "Waiting 30 seconds for production deployment to propagate..." | |
| sleep 30 | |
| # === SMOKE TEST PRODUCTION === | |
| - name: Run Smoke Tests on Production | |
| id: production_smoke_tests | |
| if: steps.deploy_production.outcome == 'success' | |
| env: | |
| PREVIEW_URL: https://mcp.sentry.dev | |
| run: | | |
| echo "Running smoke tests on production..." | |
| cd packages/smoke-tests | |
| pnpm test:ci | |
| - name: Publish Production Smoke Test Report | |
| uses: mikepenz/action-junit-report@cf701569b05ccdd861a76b8607a66d76f6fd4857 | |
| if: always() && steps.production_smoke_tests.outcome != 'skipped' | |
| with: | |
| report_paths: "packages/smoke-tests/tests.junit.xml" | |
| check_name: "Production Smoke Test Results" | |
| fail_on_failure: false | |
| # === ROLLBACK IF PRODUCTION SMOKE TESTS FAIL === | |
| - name: Rollback Production on Smoke Test Failure | |
| if: steps.production_smoke_tests.outcome == 'failure' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: packages/mcp-cloudflare | |
| command: rollback | |
| packageManager: pnpm | |
| continue-on-error: true | |
| - name: Fail Job if Production Smoke Tests Failed | |
| if: steps.production_smoke_tests.outcome == 'failure' | |
| run: | | |
| echo "Production smoke tests failed - job failed after rollback" | |
| exit 1 |