|
| 1 | +name: Deploy Worker - Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [prereleased, released] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: deploy-worker-${{ github.event.release.prerelease && 'staging' || 'production' }} |
| 9 | + cancel-in-progress: false |
| 10 | + |
| 11 | +jobs: |
| 12 | + deploy: |
| 13 | + name: Deploy to ${{ github.event.release.prerelease && 'Staging' || 'Production' }} |
| 14 | + runs-on: ubuntu-latest |
| 15 | + environment: |
| 16 | + name: ${{ github.event.release.prerelease && 'staging' || 'production' }} |
| 17 | + url: ${{ github.event.release.prerelease && 'https://bench-api-stg.zephyr-cloud.io' || 'https://bench-api.zephyr-cloud.io' }} |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + ref: ${{ github.event.release.tag_name }} |
| 24 | + |
| 25 | + - name: Install pnpm |
| 26 | + uses: pnpm/action-setup@v4 |
| 27 | + with: |
| 28 | + version: 9 |
| 29 | + |
| 30 | + - name: Setup Node.js |
| 31 | + uses: actions/setup-node@v4 |
| 32 | + with: |
| 33 | + node-version: '24' |
| 34 | + cache: 'pnpm' |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: pnpm install --frozen-lockfile |
| 38 | + |
| 39 | + - name: Build worker dependencies |
| 40 | + run: pnpm build |
| 41 | + |
| 42 | + - name: Deploy to Cloudflare Workers |
| 43 | + uses: cloudflare/wrangler-action@v3 |
| 44 | + with: |
| 45 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 46 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 47 | + workingDirectory: apps/worker |
| 48 | + environment: ${{ github.event.release.prerelease && 'staging' || 'production' }} |
| 49 | + command: deploy --env ${{ github.event.release.prerelease && 'staging' || 'production' }} |
| 50 | + |
| 51 | + - name: Run database migrations |
| 52 | + uses: cloudflare/wrangler-action@v3 |
| 53 | + with: |
| 54 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 55 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 56 | + workingDirectory: apps/worker |
| 57 | + command: d1 migrations apply ${{ github.event.release.prerelease && 'ze-benchmarks-staging' || 'ze-benchmarks-prod' }} --env ${{ github.event.release.prerelease && 'staging' || 'production' }} |
| 58 | + |
| 59 | + - name: Deployment summary |
| 60 | + run: | |
| 61 | + if [ "${{ github.event.release.prerelease }}" == "true" ]; then |
| 62 | + ENVIRONMENT="Staging" |
| 63 | + URL="https://bench-api-stg.zephyr-cloud.io" |
| 64 | + EMOJI="🧪" |
| 65 | + else |
| 66 | + ENVIRONMENT="Production" |
| 67 | + URL="https://bench-api.zephyr-cloud.io" |
| 68 | + EMOJI="🚀" |
| 69 | + fi |
| 70 | +
|
| 71 | + echo "### ${EMOJI} ${ENVIRONMENT} Deployment Successful!" >> $GITHUB_STEP_SUMMARY |
| 72 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 73 | + echo "**Environment:** ${ENVIRONMENT}" >> $GITHUB_STEP_SUMMARY |
| 74 | + echo "**URL:** ${URL}" >> $GITHUB_STEP_SUMMARY |
| 75 | + echo "**Version:** ${{ github.event.release.tag_name }}" >> $GITHUB_STEP_SUMMARY |
| 76 | + echo "**Release Type:** ${{ github.event.release.prerelease && 'Pre-release' || 'Full release' }}" >> $GITHUB_STEP_SUMMARY |
| 77 | + echo "**Deployed by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY |
0 commit comments