|
| 1 | +name: Deploy edge workers |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + operation: |
| 7 | + description: Deployment operation |
| 8 | + required: true |
| 9 | + default: deploy |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - deploy |
| 13 | + - remove-canary |
| 14 | + environment: |
| 15 | + description: Cloudflare environment |
| 16 | + required: true |
| 17 | + default: staging |
| 18 | + type: choice |
| 19 | + options: |
| 20 | + - staging |
| 21 | + - canary |
| 22 | + - production |
| 23 | + worker: |
| 24 | + description: Worker to deploy |
| 25 | + required: true |
| 26 | + default: documentation |
| 27 | + type: choice |
| 28 | + options: |
| 29 | + - both |
| 30 | + - documentation |
| 31 | + - redirects |
| 32 | + - email |
| 33 | + |
| 34 | +permissions: |
| 35 | + contents: read |
| 36 | + |
| 37 | +concurrency: |
| 38 | + group: edge-workers-${{ inputs.environment }} |
| 39 | + cancel-in-progress: false |
| 40 | + |
| 41 | +jobs: |
| 42 | + deploy: |
| 43 | + name: Deploy ${{ inputs.worker }} to ${{ inputs.environment }} |
| 44 | + runs-on: ubuntu-latest |
| 45 | + environment: cloudflare-${{ inputs.environment }} |
| 46 | + steps: |
| 47 | + - name: Validate production ref |
| 48 | + if: inputs.environment == 'production' |
| 49 | + env: |
| 50 | + DEPLOY_REF: ${{ github.ref }} |
| 51 | + DEPLOY_WORKER: ${{ inputs.worker }} |
| 52 | + run: | |
| 53 | + if [[ "$DEPLOY_REF" == refs/heads/main ]]; then exit 0; fi |
| 54 | + if [[ "$DEPLOY_WORKER" == documentation && "$DEPLOY_REF" =~ ^refs/heads/release/[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?-website$ ]]; then exit 0; fi |
| 55 | + echo "Production requires main, or an approved release website branch for documentation." >&2 |
| 56 | + exit 2 |
| 57 | +
|
| 58 | + - name: Validate operation |
| 59 | + if: inputs.operation == 'remove-canary' && inputs.environment != 'canary' |
| 60 | + run: | |
| 61 | + echo "remove-canary requires the canary environment" >&2 |
| 62 | + exit 2 |
| 63 | +
|
| 64 | + - name: Validate canary worker |
| 65 | + if: inputs.environment == 'canary' && inputs.worker != 'documentation' |
| 66 | + run: | |
| 67 | + echo "canary operations require the documentation worker" >&2 |
| 68 | + exit 2 |
| 69 | +
|
| 70 | + - name: Validate email environment |
| 71 | + if: inputs.worker == 'email' && inputs.environment != 'production' |
| 72 | + run: | |
| 73 | + echo "the email worker is deployed only through the production environment" >&2 |
| 74 | + exit 2 |
| 75 | +
|
| 76 | + - name: Checkout |
| 77 | + uses: actions/checkout@v7 |
| 78 | + |
| 79 | + - name: Setup Node |
| 80 | + uses: actions/setup-node@v6 |
| 81 | + with: |
| 82 | + node-version: 24 |
| 83 | + cache: npm |
| 84 | + |
| 85 | + - name: Install dependencies |
| 86 | + run: npm ci |
| 87 | + |
| 88 | + - name: Validate documentation Worker |
| 89 | + if: inputs.worker == 'both' || inputs.worker == 'documentation' |
| 90 | + run: npm run test:docs-worker && npm run check:docs-worker |
| 91 | + |
| 92 | + - name: Validate redirect Worker |
| 93 | + if: inputs.worker == 'both' || inputs.worker == 'redirects' |
| 94 | + run: npm run test:redirect-worker && npm run check:redirect-worker |
| 95 | + |
| 96 | + - name: Validate email Worker |
| 97 | + if: inputs.worker == 'email' |
| 98 | + run: npm run test:email-worker && npm run check:email-worker |
| 99 | + |
| 100 | + - name: Deploy documentation Worker to staging |
| 101 | + if: inputs.operation == 'deploy' && inputs.environment == 'staging' && (inputs.worker == 'both' || inputs.worker == 'documentation') |
| 102 | + run: npx wrangler deploy --env="" --config workers/docs/wrangler.jsonc |
| 103 | + |
| 104 | + - name: Verify staging documentation |
| 105 | + if: inputs.operation == 'deploy' && inputs.environment == 'staging' && (inputs.worker == 'both' || inputs.worker == 'documentation') |
| 106 | + run: | |
| 107 | + version=$(node -p "JSON.parse(require('fs').readFileSync('workers/docs/wrangler.jsonc', 'utf8')).vars.LATEST_DOC_VERSION") |
| 108 | + for attempt in 1 2 3 4 5 6; do |
| 109 | + if node scripts/docs/smoke-worker.mjs https://docs-staging.gecode.dev "$version"; then exit 0; fi |
| 110 | + if [ "$attempt" -eq 6 ]; then exit 1; fi |
| 111 | + echo "Waiting for the staging deployment to propagate (attempt $attempt)." |
| 112 | + sleep 10 |
| 113 | + done |
| 114 | +
|
| 115 | + - name: Deploy documentation Worker to production |
| 116 | + if: inputs.operation == 'deploy' && inputs.environment == 'production' && (inputs.worker == 'both' || inputs.worker == 'documentation') |
| 117 | + run: npx wrangler deploy --env production --config workers/docs/wrangler.jsonc |
| 118 | + |
| 119 | + - name: Deploy documentation Worker to canary |
| 120 | + if: inputs.operation == 'deploy' && inputs.environment == 'canary' && (inputs.worker == 'both' || inputs.worker == 'documentation') |
| 121 | + run: npx wrangler deploy --env canary --config workers/docs/wrangler.jsonc |
| 122 | + |
| 123 | + - name: Verify documentation canary |
| 124 | + if: inputs.operation == 'deploy' && inputs.environment == 'canary' && inputs.worker == 'documentation' |
| 125 | + run: | |
| 126 | + version=$(node -p "JSON.parse(require('fs').readFileSync('workers/docs/wrangler.jsonc', 'utf8')).env.canary.vars.LATEST_DOC_VERSION") |
| 127 | + for attempt in 1 2 3 4 5 6; do |
| 128 | + if node scripts/docs/smoke-worker.mjs https://www.gecode.dev "$version" --immutable-only; then exit 0; fi |
| 129 | + if [ "$attempt" -eq 6 ]; then exit 1; fi |
| 130 | + echo "Waiting for the canary deployment to propagate (attempt $attempt)." |
| 131 | + sleep 10 |
| 132 | + done |
| 133 | +
|
| 134 | + - name: Remove documentation canary |
| 135 | + if: inputs.operation == 'remove-canary' |
| 136 | + run: npx wrangler delete --env canary --config workers/docs/wrangler.jsonc --force |
| 137 | + |
| 138 | + - name: Deploy redirect Worker to staging |
| 139 | + if: inputs.operation == 'deploy' && inputs.environment == 'staging' && (inputs.worker == 'both' || inputs.worker == 'redirects') |
| 140 | + run: npx wrangler deploy --env="" --config workers/redirects/wrangler.jsonc |
| 141 | + |
| 142 | + - name: Deploy redirect Worker to production |
| 143 | + if: inputs.operation == 'deploy' && inputs.environment == 'production' && (inputs.worker == 'both' || inputs.worker == 'redirects') |
| 144 | + run: npx wrangler deploy --env production --config workers/redirects/wrangler.jsonc |
| 145 | + |
| 146 | + - name: Deploy email Worker to production |
| 147 | + if: inputs.operation == 'deploy' && inputs.environment == 'production' && inputs.worker == 'email' |
| 148 | + run: npx wrangler deploy --config workers/email/wrangler.jsonc |
| 149 | + env: |
| 150 | + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 151 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
0 commit comments