The best way to control Claude Code, Codex and more from any computer or phone

main
yml 140 lines 5.28 KB
Raw
1 name: Web Preview
2
3 # Label a PR `preview:web` to get a hosted-web preview deployment on Vercel for
4 # that push and every subsequent push. The deployment is a plain (non-prod,
5 # non-aliased) deploy into the existing hosted-web Vercel project, so the
6 # latest/nightly channel aliases are never touched.
7 #
8 # The build intentionally omits the T3 Connect cloud config (Clerk keys, relay
9 # URL): previews boot as the hosted-static app with manual pairing only. Pair a
10 # server into a preview with `t3 pair --tailscale` (or any reachable HTTPS
11 # backend) and open the pairing URL against the preview origin.
12 #
13 # The preview must be opened at the exact deployment URL from the PR comment.
14 # Vite bakes that URL in as the hosted origin (via VERCEL_URL), and
15 # `isHostedStaticApp` matches on origin, so branch-alias URLs will not
16 # self-identify as the hosted app.
17
18 on:
19 pull_request:
20 types: [labeled, synchronize, reopened]
21
22 permissions:
23 contents: read
24 pull-requests: write
25
26 concurrency:
27 group: web-preview-${{ github.event.pull_request.number }}
28 cancel-in-progress: true
29
30 jobs:
31 deploy:
32 name: Deploy web preview
33 # Same-repo PRs only: fork PRs do not receive the Vercel secrets, and this
34 # workflow should skip rather than fail for them. On `labeled` events, only
35 # the preview label itself triggers a deploy.
36 if: >-
37 github.event.pull_request.head.repo.full_name == github.repository &&
38 contains(github.event.pull_request.labels.*.name, 'preview:web') &&
39 (github.event.action != 'labeled' || github.event.label.name == 'preview:web')
40 runs-on: blacksmith-8vcpu-ubuntu-2404
41 timeout-minutes: 10
42 env:
43 VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
44 VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
45 VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
46 VERCEL_TEAM_SLUG: ${{ vars.VERCEL_TEAM_SLUG }}
47 steps:
48 - name: Checkout
49 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
50 with:
51 ref: ${{ github.event.pull_request.head.sha }}
52 sparse-checkout: |
53 /*
54 !/.repos/
55 sparse-checkout-cone-mode: false
56
57 - name: Setup Vite+
58 uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1.15.0
59 with:
60 node-version-file: package.json
61 cache: true
62 run-install: |
63 args:
64 - --filter=@t3tools/scripts...
65 - --filter=@t3tools/web...
66
67 - id: deploy
68 name: Deploy preview
69 shell: bash
70 run: |
71 set -euo pipefail
72
73 if [[ -z "${VERCEL_TOKEN:-}" || -z "${VERCEL_ORG_ID:-}" || -z "${VERCEL_PROJECT_ID:-}" ]]; then
74 echo "Missing one or more required Vercel secrets: VERCEL_TOKEN, VERCEL_ORG_ID, VERCEL_PROJECT_ID." >&2
75 exit 1
76 fi
77
78 vercel_scope="${VERCEL_TEAM_SLUG:-$VERCEL_ORG_ID}"
79
80 deployment_output="$(
81 vp dlx vercel@53.1.1 deploy \
82 --archive=tgz \
83 --yes \
84 --token "$VERCEL_TOKEN" \
85 --scope "$vercel_scope" \
86 --build-env "VITE_RELEASE_CHANNEL=preview"
87 )"
88 printf '%s\n' "$deployment_output"
89 # Vercel can print lockfile warnings to stdout before the deployment URL.
90 deployment_url="$(printf '%s\n' "$deployment_output" | grep -E '^https://[[:alnum:].-]+\.vercel\.app$')"
91 if [[ "$deployment_url" == *$'\n'* ]]; then
92 echo "Vercel returned multiple deployment URLs." >&2
93 exit 1
94 fi
95
96 echo "Deployed $deployment_url"
97 echo "deployment_url=$deployment_url" >> "$GITHUB_OUTPUT"
98
99 - name: Comment deployment URL
100 uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
101 env:
102 DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment_url }}
103 HEAD_SHA: ${{ github.event.pull_request.head.sha }}
104 with:
105 script: |
106 const marker = "<!-- web-preview-deploy -->";
107 const body = [
108 marker,
109 "### Web preview",
110 "",
111 `${process.env.DEPLOYMENT_URL} (for ${process.env.HEAD_SHA.slice(0, 7)})`,
112 "",
113 "Open this exact URL — the hosted-app origin is baked in at build time.",
114 "Pair a server into it with `t3 pair --tailscale`, or paste a host + pairing",
115 "code under Settings → Connections.",
116 ].join("\n");
117
118 const { data: comments } = await github.rest.issues.listComments({
119 owner: context.repo.owner,
120 repo: context.repo.repo,
121 issue_number: context.payload.pull_request.number,
122 per_page: 100,
123 });
124 const existing = comments.find((comment) => comment.body?.includes(marker));
125
126 if (existing) {
127 await github.rest.issues.updateComment({
128 owner: context.repo.owner,
129 repo: context.repo.repo,
130 comment_id: existing.id,
131 body,
132 });
133 } else {
134 await github.rest.issues.createComment({
135 owner: context.repo.owner,
136 repo: context.repo.repo,
137 issue_number: context.payload.pull_request.number,
138 body,
139 });
140 }