Skip to content

Commit bff0e30

Browse files
committed
ci: publish a preview of every package on every push
A change to the CLI or a plugin can now be run straight from a branch, without a release: npx https://pkg.pr.new/datocms@<commit-sha> environments:list Nothing reaches npm, no version is spent, and there is nothing to clean up afterwards. Also gives `@datocms/cli-utils` the `repository` field it was missing, which is what pkg.pr.new reads to mint the short URL form — the other four packages already had one. Runs only on pushes to branches of this repo, so a fork cannot mint a URL under our namespace without a maintainer pushing the code first. Claude-Session: https://claude.ai/code/session_01TbxhxyU1XBsSKtoCJXwAoD
1 parent f145fea commit bff0e30

5 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Every commit pushed to a branch of this repo gets an installable preview of
2+
# every package, without publishing anything to npm:
3+
#
4+
# npx https://pkg.pr.new/datocms@<commit-sha> environments:list
5+
#
6+
# The point is to cross a repo boundary while developing. A change here can be
7+
# tried inside a consumer that lives in another repository — `cms`, a demo, a
8+
# customer project — from a real tarball, instead of `npm link` or pinning a
9+
# git branch by hand and remembering to unpin it later. Installing one preview
10+
# pulls in the previews of its siblings from the same commit, so a change that
11+
# spans several packages is tried as one coherent set.
12+
#
13+
# Pull requests opened from forks are deliberately not published: this runs on
14+
# pushes to branches of *this* repo, which only people with write access can
15+
# make, so an unreviewed fork cannot mint a URL under our namespace. If we ever
16+
# want fork previews too, pkg.pr.new documents an "approved pull requests only"
17+
# recipe that gates them behind a maintainer's review.
18+
name: Continuous releases
19+
20+
on:
21+
push:
22+
# Every branch. Defining `branches` on its own also means tag pushes don't
23+
# trigger this, which is what we want: a tag points at a commit that was
24+
# already published when it landed on its branch.
25+
branches: ["**"]
26+
27+
permissions: {}
28+
29+
jobs:
30+
publish:
31+
runs-on: ubuntu-latest
32+
33+
steps:
34+
- uses: actions/checkout@v7
35+
- name: Use Node.js
36+
uses: actions/setup-node@v7
37+
with:
38+
node-version-file: .nvmrc
39+
cache: "npm"
40+
- run: npm ci
41+
- run: npm run build
42+
# Once for all the packages, not once per package: pkg.pr.new expects a
43+
# single invocation per workflow run, and rejects the rest as spam.
44+
- run: npm exec -- pkg-pr-new publish --commentWithSha './packages/*'

‎README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ live APIs: they need a `.env` at the root (copy `.env.sample`) and, for
3333
WordPress, `docker compose up` in `packages/cli-plugin-wordpress`. Each suite
3434
checks its prerequisites first and tells you which one is missing.
3535

36+
## Trying a change before it's released
37+
38+
Every push to a branch here publishes a preview of all the packages, which you
39+
can run or install anywhere — no npm release, no `npm link`:
40+
41+
```
42+
npx https://pkg.pr.new/datocms@<commit-sha> environments:list
43+
npm i https://pkg.pr.new/@datocms/cli-plugin-wordpress@<commit-sha>
44+
```
45+
46+
The exact URLs show up in the commit's check run on GitHub, and in a comment on
47+
the pull request once there is one. Installing one preview pulls in the previews
48+
of its siblings built from the same commit, so a change spanning several
49+
packages can be tried as one coherent set.
50+
51+
Previews are throwaway: they are never published to npm, and the URL stops
52+
resolving after a while. Never commit one to a `package.json` that ships.
53+
3654
## Releasing
3755

3856
Maintainers only. A release publishes the packages that changed, and gives them

‎package-lock.json‎

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

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"lint-staged": "^13.1.0",
3131
"mocha": "^10",
3232
"oclif": "^4",
33+
"pkg-pr-new": "^0.0.88",
3334
"rimraf": "^3.0.2",
3435
"ts-node": "^10.2.1",
3536
"tslib": "^2.3.1",

‎packages/cli-utils/package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"author": "Stefano Verna <s.verna@datocms.com>",
66
"homepage": "https://github.com/datocms/cli",
77
"license": "MIT",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/datocms/cli.git",
11+
"directory": "packages/cli-utils"
12+
},
813
"main": "lib/index.js",
914
"types": "lib/index.d.ts",
1015
"directories": {

0 commit comments

Comments
 (0)