Skip to content

Commit e4dfc59

Browse files
committed
chore: add pkg.pr.new preview package releases
Publishes installable preview builds of the public @trigger.dev/* packages for every branch push via pkg.pr.new, without touching the npm registry. Reviewers and users can install any branch with `npm i https://pkg.pr.new/@trigger.dev/sdk@<sha>`. A pre-build stamp rewrites each public package to a unique 0.0.0-preview-<sha> version so previews can never collide with real npm versions in consumer lockfiles/caches, and so updateVersion.ts bakes the preview version into the runtime VERSION constant. Sibling workspace specifiers are relaxed to workspace:* so pnpm pack resolves cleanly after the bump.
1 parent 4c4ed22 commit e4dfc59

4 files changed

Lines changed: 183 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: 📦 Preview packages (pkg.pr.new)
2+
3+
# Publishes installable preview builds of the public @trigger.dev/* packages
4+
# for every push to a branch, via https://pkg.pr.new. These are NOT published
5+
# to npm — pkg.pr.new serves them by commit SHA and drops install instructions
6+
# in a comment on the associated PR, e.g.
7+
# npm i https://pkg.pr.new/@trigger.dev/sdk@<sha>
8+
#
9+
# Prerequisites:
10+
# - The pkg.pr.new GitHub App must be installed on triggerdotdev/trigger.dev
11+
# (https://github.com/apps/pkg-pr-new). Publishing fails until it is.
12+
#
13+
# Fork note: pkg.pr.new authenticates with a GitHub Actions OIDC token, which
14+
# GitHub does not issue to pull_request workflows from forks. This `push`
15+
# trigger therefore covers branches pushed to this repo (the core team), not
16+
# external fork PRs. Adding fork coverage would require a workflow_run two-stage
17+
# setup.
18+
19+
on:
20+
push:
21+
branches-ignore:
22+
- main
23+
- changeset-release/main
24+
paths:
25+
- "packages/**"
26+
- "pnpm-lock.yaml"
27+
- "pnpm-workspace.yaml"
28+
- "turbo.json"
29+
- ".github/workflows/preview-packages.yml"
30+
- "scripts/stamp-preview-version.mjs"
31+
32+
concurrency:
33+
group: preview-packages-${{ github.ref }}
34+
cancel-in-progress: true
35+
36+
permissions:
37+
contents: read
38+
id-token: write # OIDC token used by pkg.pr.new to authenticate the publish
39+
40+
jobs:
41+
publish:
42+
name: Build and publish previews
43+
runs-on: ubuntu-latest
44+
if: github.repository == 'triggerdotdev/trigger.dev'
45+
steps:
46+
- name: ⬇️ Checkout repo
47+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
48+
with:
49+
fetch-depth: 0
50+
persist-credentials: false
51+
52+
- name: ⎔ Setup pnpm
53+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
54+
with:
55+
version: 10.33.2
56+
57+
- name: ⎔ Setup node
58+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
59+
with:
60+
node-version: 20.20.0
61+
cache: "pnpm"
62+
63+
- name: 📥 Install dependencies
64+
run: pnpm install --frozen-lockfile
65+
66+
- name: 📀 Generate Prisma client
67+
run: pnpm run generate
68+
69+
# Stamp a unique 0.0.0-preview-<sha> version before building so it can't
70+
# collide with real npm versions and so updateVersion.ts bakes it into the
71+
# runtime VERSION constant. See scripts/stamp-preview-version.mjs.
72+
- name: 🏷️ Stamp preview version
73+
run: node scripts/stamp-preview-version.mjs
74+
env:
75+
GITHUB_SHA: ${{ github.sha }}
76+
77+
- name: 🔨 Build packages
78+
run: pnpm run build --filter "@trigger.dev/*" --filter "trigger.dev"
79+
80+
- name: 🚀 Publish previews to pkg.pr.new
81+
run: pnpm exec pkg-pr-new publish --pnpm --compact --commentWithSha './packages/*'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"autoprefixer": "^10.4.12",
6060
"eslint-plugin-turbo": "^2.0.4",
6161
"lefthook": "^1.11.3",
62+
"pkg-pr-new": "0.0.75",
6263
"pkg-types": "1.1.3",
6364
"prettier": "^3.0.0",
6465
"tsx": "^3.7.1",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/stamp-preview-version.mjs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Rewrites the version of every public packages/* package to a unique,
2+
// preview-only semver (0.0.0-preview-<sha>) BEFORE the build runs.
3+
//
4+
// Why this exists:
5+
// pkg.pr.new serves preview builds by commit SHA but does NOT change the
6+
// package.json "version" field (as of 0.0.75). If a preview is published
7+
// while package.json still says e.g. 4.5.0-rc.4, a consumer who installs the
8+
// preview pins 4.5.0-rc.4 to the pkg.pr.new tarball in their lockfile/cache,
9+
// and a later `npm i @trigger.dev/sdk@4.5.0-rc.4` from npm can resolve to the
10+
// stale preview. See stackblitz-labs/pkg.pr.new#250 and #390.
11+
//
12+
// A 0.0.0- prefix can never satisfy a real semver range, so the collision
13+
// becomes structurally impossible (the same convention React/Next canaries
14+
// use).
15+
//
16+
// Running BEFORE the build also means scripts/updateVersion.ts bakes this
17+
// same preview version into the runtime VERSION constant, so previews are
18+
// self-identifying (trigger --version, the x-trigger-cli-version header, the
19+
// MCP server version, etc.) rather than all reporting the RC version.
20+
//
21+
// Sibling workspace: specifiers are relaxed to workspace:* so `pnpm pack`
22+
// resolves them against the rewritten versions without range-validation
23+
// errors. packages/python pins peerDependencies as workspace:^4.5.0-rc.4,
24+
// which would otherwise be unsatisfiable once the sibling version changes.
25+
//
26+
// Note: pkg.pr.new PR #525 adds a built-in --previewVersion flag. Once that
27+
// ships we could drop the version-rewrite half here, but we still want a
28+
// pre-build stamp so updateVersion.ts picks up the preview version (the flag
29+
// rewrites at pack time, which is too late for the baked VERSION constant).
30+
31+
import { readdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
32+
import { join } from "node:path";
33+
import { execSync } from "node:child_process";
34+
35+
const PACKAGES_DIR = "packages";
36+
const DEP_SECTIONS = [
37+
"dependencies",
38+
"devDependencies",
39+
"peerDependencies",
40+
"optionalDependencies",
41+
];
42+
43+
function resolveSha() {
44+
const sha = process.argv[2] || process.env.GITHUB_SHA;
45+
if (sha) return sha;
46+
try {
47+
return execSync("git rev-parse HEAD", { encoding: "utf8" }).trim();
48+
} catch {
49+
throw new Error(
50+
"Could not determine commit SHA (pass as the first argument or set GITHUB_SHA)"
51+
);
52+
}
53+
}
54+
55+
const sha = resolveSha().slice(0, 7);
56+
const previewVersion = `0.0.0-preview-${sha}`;
57+
58+
const dirs = readdirSync(PACKAGES_DIR, { withFileTypes: true }).filter((e) =>
59+
e.isDirectory()
60+
);
61+
62+
// First pass: collect every public package name so we know which workspace
63+
// specifiers point at a sibling whose version we are about to change.
64+
const publicNames = new Set();
65+
const manifests = [];
66+
for (const dir of dirs) {
67+
const pkgPath = join(PACKAGES_DIR, dir.name, "package.json");
68+
if (!existsSync(pkgPath)) continue;
69+
const json = JSON.parse(readFileSync(pkgPath, "utf8"));
70+
manifests.push({ pkgPath, json });
71+
if (!json.private && json.name) publicNames.add(json.name);
72+
}
73+
74+
// Second pass: stamp the version and relax sibling workspace specifiers.
75+
let stamped = 0;
76+
for (const { pkgPath, json } of manifests) {
77+
if (json.private) continue;
78+
json.version = previewVersion;
79+
for (const section of DEP_SECTIONS) {
80+
const deps = json[section];
81+
if (!deps) continue;
82+
for (const [name, spec] of Object.entries(deps)) {
83+
if (publicNames.has(name) && String(spec).startsWith("workspace:")) {
84+
deps[name] = "workspace:*";
85+
}
86+
}
87+
}
88+
writeFileSync(pkgPath, `${JSON.stringify(json, null, 2)}\n`);
89+
stamped++;
90+
}
91+
92+
console.log(`Stamped ${stamped} public package(s) to ${previewVersion}`);

0 commit comments

Comments
 (0)