Skip to content

Commit 3356fca

Browse files
authored
Merge pull request #2 from kernel/chore/changesets
chore(ci): adopt Changesets for releases
2 parents d542f2e + ba27171 commit 3356fca

7 files changed

Lines changed: 103 additions & 87 deletions

File tree

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets).
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md).

.changeset/config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.4/schema.json",
3+
"changelog": [
4+
"@changesets/changelog-github",
5+
{ "repo": "kernel/managed-auth-react" }
6+
],
7+
"commit": false,
8+
"fixed": [],
9+
"linked": [],
10+
"access": "public",
11+
"baseBranch": "main",
12+
"updateInternalDependencies": "patch",
13+
"ignore": ["@onkernel/managed-auth-react-demo"]
14+
}

.github/workflows/release.yaml

Lines changed: 42 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
name: Release
22

3-
# Publishing flow:
4-
# 1. PRs land on main (passing the test workflow)
5-
# 2. Bump `packages/managed-auth-react/package.json` "version" on main
6-
# 3. Tag and push: `git tag v0.1.0-alpha.1 && git push --tags`
7-
# 4. This workflow validates the tag matches package.json, builds, and
8-
# publishes to npm via OIDC trusted publishers (no NPM_TOKEN needed).
3+
# Changesets-driven release flow:
4+
# 1. Contributors include `.changeset/*.md` files in their PRs describing
5+
# the version bump (patch | minor | major) and the change.
6+
# 2. When PRs land on main, this workflow runs and the changesets bot
7+
# either:
8+
# a. Opens (or updates) a single "Version Packages" PR that bumps
9+
# package.json versions, regenerates CHANGELOG.md, and deletes
10+
# the consumed changeset files. Reviewers approve + merge it
11+
# when ready to ship.
12+
# b. If no pending changesets exist (i.e. the Version PR was just
13+
# merged), runs `bun run release` which builds the package and
14+
# runs `changeset publish` — that calls `npm publish` for every
15+
# package version not yet on the registry, then tags + GitHub
16+
# releases each.
917
#
10-
# One-time setup before the first release:
11-
# - On npmjs.com → @onkernel/managed-auth-react → Settings → Trusted Publishers
12-
# add this repository + workflow filename + the `release` job name.
13-
# - The first publish under OIDC requires the package to already exist
14-
# OR the publishing user to have permission to create scoped packages
15-
# under @onkernel.
18+
# No manual git tags, no manual package.json edits, no main-branch
19+
# bypasses. Releases go through the normal PR + status-check + approval
20+
# flow like any other change.
21+
#
22+
# `--provenance` is intentionally omitted from the publish: npm requires
23+
# a public source repository for provenance attestations and this repo
24+
# is `internal`-visibility. Re-add via .changeset/config.json once the
25+
# repo flips public.
26+
1627
on:
1728
push:
18-
tags:
19-
- 'v*'
29+
branches: [main]
2030

2131
permissions:
22-
contents: write # creating GitHub releases
23-
id-token: write # npm OIDC trusted publishing
32+
contents: write # opening/merging the version PR + tagging releases
33+
pull-requests: write # opening the version PR
34+
id-token: write # npm OIDC trusted publishing
35+
36+
concurrency:
37+
group: ${{ github.workflow }}-${{ github.ref }}
2438

2539
jobs:
2640
release:
@@ -32,7 +46,6 @@ jobs:
3246
fetch-depth: 0
3347

3448
- name: Set up Bun
35-
# Pin to package.json `packageManager` — same reason as test.yaml.
3649
uses: oven-sh/setup-bun@v2
3750
with:
3851
bun-version: "1.2.21"
@@ -43,70 +56,22 @@ jobs:
4356
node-version: '20'
4457
registry-url: 'https://registry.npmjs.org'
4558

46-
# OIDC trusted publishers require npm >= 11.5.1the version bundled
47-
# with Node 20 is older. This is the same workaround the CLI uses.
59+
# OIDC trusted publishing requires npm >= 11.5.1; the version
60+
# bundled with Node 20 is older.
4861
- name: Ensure latest npm
4962
run: npm install -g npm@latest
5063

51-
# Catch the most common release foot-gun: tag pushed before bumping
52-
# package.json. Fail loud here instead of publishing a mismatched
53-
# version that npm can't ever republish under the right tag.
54-
- name: Verify tag matches package.json
55-
run: |
56-
TAG_VERSION="${GITHUB_REF_NAME#v}"
57-
PKG_VERSION="$(node -p "require('./packages/managed-auth-react/package.json').version")"
58-
echo "Tag version: $TAG_VERSION"
59-
echo "package.json version: $PKG_VERSION"
60-
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
61-
echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $PKG_VERSION"
62-
exit 1
63-
fi
64-
6564
- name: Install dependencies
6665
run: bun install --frozen-lockfile
6766

68-
# Build before typecheck so the demo workspace can resolve
69-
# `@onkernel/managed-auth-react`'s emitted .d.ts. Same ordering as
70-
# test.yaml.
71-
- name: Build package
72-
run: bun run --filter '@onkernel/managed-auth-react' build
73-
74-
- name: Typecheck
75-
run: bun run typecheck
76-
77-
# The package's `files: ["dist", "README.md", "LICENSE"]` references
78-
# a LICENSE that lives at the repo root, not in the package directory.
79-
# Copy it in before publishing so npm includes it in the tarball.
80-
- name: Copy LICENSE into package
81-
run: cp LICENSE packages/managed-auth-react/LICENSE
82-
83-
# npm requires --tag for any version with a hyphen (alpha/beta/rc).
84-
# Stable releases get the default `latest` tag; prereleases land
85-
# under `alpha` so `npm install @onkernel/managed-auth-react` keeps
86-
# picking up stable versions only.
87-
#
88-
# `--provenance` is intentionally omitted: npm requires a public
89-
# source repository for provenance attestations and this repo is
90-
# `internal`. Re-add `--provenance` if the repo goes public.
91-
- name: Publish to npm
92-
working-directory: packages/managed-auth-react
93-
run: |
94-
NPM_TAG="latest"
95-
if [[ "$GITHUB_REF_NAME" == *-* ]]; then
96-
NPM_TAG="alpha"
97-
fi
98-
npm publish --access public --tag "$NPM_TAG"
99-
100-
- name: Create GitHub release
67+
- name: Create release PR or publish
68+
uses: changesets/action@v1
69+
with:
70+
# Runs when there are no pending .changeset/*.md files —
71+
# i.e. immediately after the Version Packages PR is merged.
72+
publish: bun run release
73+
# PR title for the bot's open Version Packages PR.
74+
title: "chore: version packages"
75+
commit: "chore: version packages"
10176
env:
102-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103-
run: |
104-
# Mark prerelease for any tag that includes a hyphen (alpha, beta, rc).
105-
PRERELEASE_FLAG=""
106-
if [[ "$GITHUB_REF_NAME" == *-* ]]; then
107-
PRERELEASE_FLAG="--prerelease"
108-
fi
109-
gh release create "$GITHUB_REF_NAME" \
110-
--title "$GITHUB_REF_NAME" \
111-
--generate-notes \
112-
$PRERELEASE_FLAG
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.prettierignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Bun and Changesets re-serialize package.json on every install / version
2+
# bump and use single-line arrays. Prettier wraps JSON arrays multi-line.
3+
# Letting prettier touch package.json would cause endless format churn,
4+
# so its formatting is owned by bun + changesets, not prettier.
5+
**/package.json
6+
7+
# Generated build output and lockfiles
8+
**/dist/**
9+
bun.lock
10+
11+
# Auto-generated changelog (managed by changesets)
12+
**/CHANGELOG.md

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,31 @@ Every successful build (JS + DTS) replaces the consumer's `dist/`, so refreshing
4343
## CI / releases
4444

4545
- `.github/workflows/test.yaml` runs on every PR and push to `main`: `format:check`, `typecheck`, `build`, and a `npm pack --dry-run` to verify publishability.
46-
- `.github/workflows/release.yaml` triggers on `v*` tags. Verifies the tag matches `package.json`, builds, and publishes to npm via OIDC trusted publishing (`--provenance`). Hyphenated tags like `v0.2.0-beta.1` are marked as GitHub prereleases.
46+
- `.github/workflows/release.yaml` runs on every push to `main` and is driven by [Changesets](https://github.com/changesets/changesets). Either opens/updates a "Version Packages" PR, or — when that PR is merged — publishes to npm via OIDC trusted publishing.
4747

48-
To cut a release:
48+
Bun is pinned to `1.2.21` in both workflows (and in `packageManager` at the root) so lockfile-format drift across bun majors doesn't silently break CI.
4949

50-
```bash
51-
# Bump the version in packages/managed-auth-react/package.json on main, then:
52-
git tag v0.2.0
53-
git push origin v0.2.0
54-
```
50+
### Cutting a release
5551

56-
Bun is pinned to `1.2.21` in both workflows (and in `packageManager` at the root) so lockfile-format drift across bun majors doesn't silently break CI.
52+
The release flow is fully PR-driven — no direct `package.json` edits, no manual `git tag`, no main-branch bypasses.
53+
54+
1. **In any PR that changes published behavior**, add a changeset:
55+
56+
```bash
57+
bun run changeset
58+
```
59+
60+
The CLI asks which packages changed and which bump (patch / minor / major), then writes a `.changeset/<random>.md` file describing the change. Commit it alongside your code.
61+
62+
Skip the changeset for tooling/infra/docs PRs that don't affect what consumers see.
63+
64+
2. **Merge your PR to `main`.** The Changesets bot runs and either:
65+
- Opens (or updates) a single **"chore: version packages"** PR that bumps `package.json` versions, regenerates `CHANGELOG.md`, and deletes the consumed changeset files. Multiple feature PRs accumulate into the same Version PR.
66+
- If no pending changesets exist (i.e. the Version PR was just merged), runs `bun run release` which builds the package and calls `changeset publish``npm publish` for every version not yet on the registry, then tags + creates the GitHub release.
67+
68+
3. **To ship**, review and merge the open Version PR. The next workflow run publishes.
69+
70+
That's it. The git tag, npm publish, and GitHub release are all created by the bot on Version-PR merge.
5771

5872
## License
5973

bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"typecheck": "bun run --filter '*' typecheck",
1212
"lint": "bun run --filter '*' lint",
1313
"format": "prettier --write \"**/*.{ts,tsx,js,json,md,css}\"",
14-
"format:check": "prettier --check \"**/*.{ts,tsx,js,json,md,css}\""
14+
"format:check": "prettier --check \"**/*.{ts,tsx,js,json,md,css}\"",
15+
"changeset": "changeset",
16+
"version-packages": "changeset version",
17+
"release": "bun run --filter '@onkernel/managed-auth-react' build && cp LICENSE packages/managed-auth-react/LICENSE && changeset publish"
1518
},
1619
"devDependencies": {
1720
"@types/node": "^20",

0 commit comments

Comments
 (0)