Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

111 lines · 5.2 KBRaw History
1name: Deploy
2
3# Deploys Diffinery from main. Uses the repository secrets
4# CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID, and these optional repository
5# variables (the same ones scripts/bootstrap.sh reads):
6# DIFFINERY_DOMAIN where it is served (default diffinery.com)
7# DIFFINERY_ZONE the Cloudflare zone for the route (default: the domain's last two labels)
8# MAIL_DOMAIN sends from notifications@<MAIL_DOMAIN> (default DIFFINERY_DOMAIN)
9# ACCESS_TEAM_DOMAIN e.g. codician.cloudflareaccess.com
10on:
11 push:
12 branches: [main]
13 workflow_dispatch:
14
15permissions:
16 contents: read
17
18concurrency:
19 group: deploy-production
20 cancel-in-progress: false
21
22jobs:
23 deploy:
24 name: Deploy to Cloudflare
25 # Production deploys from Diffinery itself, on its own hosted runners (any
26 # Diffinery, so self-hosted copies deploy themselves too). Running this
27 # workflow by hand on GitHub still deploys, as a fallback.
28 if: ${{ github.server_url != 'https://github.com' || github.event_name == 'workflow_dispatch' }}
29 runs-on: ubuntu-latest
30 timeout-minutes: 45
31 environment:
32 name: production
33 url: https://${{ vars.DIFFINERY_DOMAIN || 'diffinery.com' }}
34 env:
35 DIFFINERY_DOMAIN: ${{ vars.DIFFINERY_DOMAIN || 'diffinery.com' }}
36 DIFFINERY_ZONE: ${{ vars.DIFFINERY_ZONE }}
37 MAIL_DOMAIN: ${{ vars.MAIL_DOMAIN }}
38 CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
39 CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
40 ACCESS_TEAM_DOMAIN: ${{ vars.ACCESS_TEAM_DOMAIN }}
41 steps:
42 - uses: actions/checkout@v4
43 - uses: pnpm/action-setup@v4
44 - uses: actions/setup-node@v4
45 with:
46 node-version: 22
47 cache: pnpm
48 - run: pnpm install --frozen-lockfile
49 - name: Build runner agent and web islands
50 run: pnpm -r --if-present build
51 - name: Typecheck and test
52 run: pnpm -r --if-present typecheck && pnpm -r --if-present test
53
54 - name: Create or update Cloudflare resources
55 id: bootstrap
56 run: scripts/bootstrap.sh
57
58 - name: Deploy Worker and runner image
59 working-directory: apps/diffinery
60 run: pnpm exec wrangler deploy -c wrangler.deploy.jsonc
61
62 - name: Generate Worker secrets (first deploy only)
63 run: scripts/ensure-secrets.sh
64
65 - name: Finish Access setup on first deploy
66 if: steps.bootstrap.outputs.access_team == ''
67 run: |
68 scripts/bootstrap.sh
69 cd apps/diffinery && pnpm exec wrangler deploy -c wrangler.deploy.jsonc --containers-rollout none
70
71 - name: Smoke test
72 run: |
73 # A new custom domain can take a few minutes to get its certificate.
74 for i in $(seq 1 30); do
75 code=$(curl -s -o /dev/null -w '%{http_code}' https://$DIFFINERY_DOMAIN/healthz) && [ "$code" = 200 ] && exit 0
76 sleep 10
77 done
78 echo "::error::https://$DIFFINERY_DOMAIN/healthz did not return 200 (last: $code). Check that the $DIFFINERY_DOMAIN DNS record is proxied (orange cloud)."; exit 1
79
80 - name: Check sign-in pages
81 run: |
82 set -u
83 page=$(curl -sS https://$DIFFINERY_DOMAIN/login)
84 grep -q "Sign in with a passkey" <<<"$page" || { echo "::error::/login is not the Diffinery sign-in page"; exit 1; }
85 echo "/login serves the passkey sign-in page"
86 loc=$(curl -sS -o /dev/null -w '%{http_code} %{redirect_url}' https://$DIFFINERY_DOMAIN/auth/access)
87 echo "/auth/access -> $loc"
88 [[ "$loc" == 302\ https://*.cloudflareaccess.com/* ]] || echo "::warning::/auth/access is not behind Cloudflare Access yet, so email recovery and first admin sign-in will not work"
89 for kind in js css; do
90 asset=$(grep -o "/-/kumo/[a-z0-9]*\.$kind" <<<"$page" | head -1)
91 [ -n "$asset" ] || { echo "::error::/login does not load the Kumo $kind bundle"; exit 1; }
92 code=$(curl -sS -o /dev/null -w '%{http_code}' "https://$DIFFINERY_DOMAIN$asset")
93 [ "$code" = 200 ] || { echo "::error::$asset returned $code"; exit 1; }
94 echo "$asset -> 200"
95 done
96 - name: Check favicon and search metadata
97 run: |
98 set -u
99 for p in /favicon.ico /favicon.svg /favicon-48.png /apple-touch-icon.png /og-image.png /site.webmanifest /robots.txt /sitemap.xml; do
100 code=$(curl -sS -o /dev/null -w '%{http_code} %{content_type}' "https://$DIFFINERY_DOMAIN$p")
101 [[ "$code" == 200\ * ]] || { echo "::error::$p returned $code"; exit 1; }
102 echo "$p -> $code"
103 done
104 home=$(curl -sS https://$DIFFINERY_DOMAIN/)
105 for tag in 'rel="icon" href="/favicon.ico"' 'property="og:image"' 'rel="canonical"' 'application/ld+json'; do
106 grep -qF "$tag" <<<"$home" || { echo "::error::the home page is missing $tag"; exit 1; }
107 done
108 echo "the home page carries the favicon, canonical, Open Graph and structured data tags"
109 bm=$(curl -sS -D - -o /dev/null https://$DIFFINERY_DOMAIN/sitemap.xml | tr -d '\r' | sed -n 's/^x-d1-bookmark: //Ip')
110 [ -n "$bm" ] || { echo "::error::D1 queries don't run in a session (no x-d1-bookmark header)"; exit 1; }
111 echo "D1 sessions are on (bookmark $bm)"