Skip to content

Commit a5e2e2f

Browse files
committed
Add stable main compute preview
1 parent 1a3731f commit a5e2e2f

6 files changed

Lines changed: 80 additions & 13 deletions

File tree

.changeset/main-compute-preview.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@prisma/studio-core": patch
3+
---
4+
5+
Keep the Compute preview environment for `main` updated whenever the default branch receives new commits.

.github/workflows/compute-preview.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- opened
77
- reopened
88
- synchronize
9+
push:
10+
branches:
11+
- main
912
delete:
1013

1114
permissions:
@@ -19,12 +22,14 @@ concurrency:
1922

2023
jobs:
2124
deploy-preview:
22-
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
25+
if: >-
26+
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
27+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
2328
runs-on: ubuntu-latest
2429
steps:
2530
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2631
with:
27-
ref: ${{ github.event.pull_request.head.sha }}
32+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
2833

2934
- name: Setup pnpm
3035
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
@@ -53,10 +58,11 @@ jobs:
5358
id: deploy
5459
env:
5560
PRISMA_API_TOKEN: ${{ secrets.STUDIO_PREVIEW_COMPUTE_TOKEN }}
56-
PREVIEW_BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
61+
PREVIEW_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
5762
run: node scripts/compute-preview/compute-preview-deploy.mjs
5863

5964
- name: Comment preview URL on PR
65+
if: github.event_name == 'pull_request'
6066
env:
6167
GITHUB_REPOSITORY: ${{ github.repository }}
6268
GITHUB_TOKEN: ${{ github.token }}

Architecture/compute-preview-deploy.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Compute Preview Deploys
22

3-
This document is normative for branch-scoped Compute preview deployments.
3+
This document is normative for branch-scoped and default-branch Compute preview
4+
deployments.
45

56
## Purpose
67

7-
Pull requests need a live Studio preview without manually creating and cleaning up
8-
Compute services for every branch.
8+
Pull requests need a live Studio preview without manually creating and cleaning
9+
up Compute services for every branch. The default branch also needs one stable
10+
preview that always reflects the latest merged Studio state.
911

1012
The preview deployment path uses the existing `pnpm build:deploy` artifact and
1113
publishes it into the dedicated Compute project named `studio-preview`.
@@ -14,17 +16,23 @@ publishes it into the dedicated Compute project named `studio-preview`.
1416

1517
- A preview deploy MUST run when a pull request is opened, reopened, or updated
1618
with new commits.
19+
- A stable default-branch preview deploy MUST run when new commits are pushed to
20+
`main`.
1721
- Preview deploys MUST only run for branches inside this repository. Forked pull
1822
requests MUST NOT receive the Compute token.
1923
- A preview service MUST be destroyed when the corresponding Git branch is
2024
deleted.
25+
- The stable `main` preview service MUST NOT be destroyed by branch-deletion
26+
cleanup.
2127
- Because the GitHub `delete` event is evaluated from the default branch
2228
workflow set, this workflow MUST be merged to `main` before branch-deletion
2329
cleanup becomes automatic for later branches.
2430

2531
## Service Naming
2632

27-
- Preview services MUST be keyed by the pull request branch name.
33+
- Pull request preview services MUST be keyed by the pull request branch name.
34+
- The stable default-branch preview service MUST be keyed by the literal
35+
`main` ref name.
2836
- Because Compute service names need a filesystem- and URL-safe shape, the raw
2937
branch name MUST be normalized to a lowercase slug containing only
3038
alphanumeric segments separated by `-`.
@@ -49,9 +57,10 @@ publishes it into the dedicated Compute project named `studio-preview`.
4957

5058
## PR Feedback
5159

52-
- Successful preview deploys MUST post the live service URL back to the pull
53-
request.
60+
- Successful pull request preview deploys MUST post the live service URL back to
61+
the pull request.
5462
- The PR comment MUST be sticky: later deploys for the same PR update the
5563
existing preview comment instead of creating duplicates.
5664
- The comment MUST include the original branch name plus the resolved Compute
5765
service name so any slug normalization stays visible.
66+
- Default-branch preview deploys MUST NOT post a pull request comment.

FEATURES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ In that mode the shell hides schema selection, table navigation, and database-on
2626
Studio's local development workflow can temporarily replace the published npm `@prisma/dev` package with the sibling source package from `../team-expansion/dev/server`, while also swapping its `@prisma/streams-local` dependency over to a built local Streams checkout.
2727
That override stays opt-in, rebuilds from the sibling repos by default, and can be reverted without rewriting the tracked lockfile, so experimental Prisma Dev and Durable Streams work can stay local to one Studio checkout.
2828

29-
## Compute PR Preview Deploys
29+
## Compute Preview Deploys
3030

3131
Pull requests can publish the current branch into the dedicated `studio-preview`
3232
Compute project without hand-creating services for each branch.
3333
The preview workflow derives a stable Compute-safe service name from the branch,
3434
reuses that service across later pushes, posts the live URL back to the PR, and
3535
destroys the preview service when the branch is deleted.
36+
The same deployment path also keeps one reserved `main` preview service updated
37+
whenever commits land on the default branch, giving consumers a stable preview of
38+
the latest merged Studio build.
3639

3740
## Introspection Recovery and Retry
3841

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,21 @@ bunx @prisma/compute-cli deploy --skip-build \
419419

420420
## Compute Preview Deploys
421421

422-
This repo also maintains branch-scoped Compute previews for pull requests.
422+
This repo maintains branch-scoped Compute previews for pull requests and one
423+
stable Compute preview for the default branch.
423424

424425
- `.github/workflows/compute-preview.yml` deploys the current PR branch into the
425426
dedicated `studio-preview` Compute project whenever a PR is opened,
426427
reopened, or updated with new commits.
428+
- The same workflow deploys the `main` branch into a reserved `main` Compute
429+
service whenever commits are pushed to the default branch.
427430
- The preview service name is derived from the branch name through a stable
428431
Compute-safe slug, so later pushes reuse the same service instead of creating
429432
duplicates.
430433
- The workflow updates one sticky PR comment with the live preview URL after a
431-
successful deploy.
434+
successful PR deploy.
432435
- When a Git branch is deleted, the same workflow destroys the matching preview
433-
service.
436+
service. The reserved `main` preview is not part of branch-deletion cleanup.
434437

435438
The workflow expects the GitHub Actions secret
436439
`STUDIO_PREVIEW_COMPUTE_TOKEN`, which should contain a Compute API token for the
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { readFileSync } from "node:fs";
2+
import { fileURLToPath, URL } from "node:url";
3+
4+
import { describe, expect, it } from "vitest";
5+
6+
const workflowPath = fileURLToPath(
7+
new URL("../../.github/workflows/compute-preview.yml", import.meta.url),
8+
);
9+
const workflow = readFileSync(workflowPath, "utf8");
10+
11+
describe("compute preview workflow", () => {
12+
it("deploys one stable main preview when main receives new commits", () => {
13+
expect(workflow).toContain(
14+
[
15+
" push:",
16+
" branches:",
17+
" - main",
18+
].join("\n"),
19+
);
20+
expect(workflow).toContain("github.event_name == 'push'");
21+
expect(workflow).toContain("github.ref == 'refs/heads/main'");
22+
expect(workflow).toContain(
23+
"PREVIEW_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}",
24+
);
25+
});
26+
27+
it("keeps PR comments and branch cleanup scoped to PR previews", () => {
28+
expect(workflow).toContain(
29+
[
30+
" - name: Comment preview URL on PR",
31+
" if: github.event_name == 'pull_request'",
32+
].join("\n"),
33+
);
34+
expect(workflow).toContain(
35+
"if: github.event_name == 'delete' && github.event.ref_type == 'branch'",
36+
);
37+
expect(workflow).toContain(
38+
"PREVIEW_BRANCH_NAME: ${{ github.event.ref }}",
39+
);
40+
});
41+
});

0 commit comments

Comments
 (0)