|
| 1 | +name: Deploy Orbit to Cloudflare |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: orbit-production |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + deploy: |
| 18 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 19 | + runs-on: ubuntu-latest |
| 20 | + timeout-minutes: 20 |
| 21 | + environment: |
| 22 | + name: production |
| 23 | + url: https://orbit.sametbasbug.dev |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v7 |
| 28 | + |
| 29 | + - name: Set up Node |
| 30 | + uses: actions/setup-node@v7 |
| 31 | + with: |
| 32 | + node-version: 24 |
| 33 | + cache: npm |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: npm ci |
| 37 | + |
| 38 | + - name: Verify application and static output |
| 39 | + run: | |
| 40 | + npm run check |
| 41 | + npm run build |
| 42 | +
|
| 43 | + - name: Build and verify the live bundle |
| 44 | + run: | |
| 45 | + npm run production:config:check |
| 46 | + npm run worker:build:production:live |
| 47 | +
|
| 48 | + - name: Deploy the main branch |
| 49 | + env: |
| 50 | + CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }} |
| 51 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 52 | + run: | |
| 53 | + short_sha="${GITHUB_SHA::12}" |
| 54 | + npx wrangler deploy \ |
| 55 | + --config wrangler.production.live.jsonc \ |
| 56 | + --tag "main-${short_sha}" \ |
| 57 | + --message "Automatic production deploy from main ${short_sha}" |
| 58 | +
|
| 59 | + - name: Verify the live site |
| 60 | + run: | |
| 61 | + health="$(curl --fail --silent --show-error \ |
| 62 | + --retry 8 --retry-delay 3 --retry-all-errors \ |
| 63 | + https://orbit.sametbasbug.dev/healthz)" |
| 64 | +
|
| 65 | + HEALTH="$health" node -e ' |
| 66 | + const health = JSON.parse(process.env.HEALTH); |
| 67 | + if (health.ok !== true || health.service !== "orbit-v6" || health.environment !== "production") { |
| 68 | + throw new Error(`Unexpected health response: ${JSON.stringify(health)}`); |
| 69 | + } |
| 70 | + ' |
| 71 | +
|
| 72 | + headers="$(mktemp)" |
| 73 | + trap 'rm -f "$headers"' EXIT |
| 74 | + curl --fail --silent --show-error \ |
| 75 | + --retry 8 --retry-delay 3 --retry-all-errors \ |
| 76 | + --dump-header "$headers" --output /dev/null \ |
| 77 | + https://orbit.sametbasbug.dev/ |
| 78 | +
|
| 79 | + grep -qi '^cf-ray:' "$headers" |
| 80 | + if grep -qi '^server: GitHub.com' "$headers"; then |
| 81 | + echo 'Live Orbit unexpectedly resolved to GitHub Pages.' >&2 |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | + if grep -qi '^x-robots-tag:.*noindex' "$headers"; then |
| 85 | + echo 'Live Orbit unexpectedly returned a noindex header.' >&2 |
| 86 | + exit 1 |
| 87 | + fi |
0 commit comments