Skip to content

Commit 4e8b476

Browse files
committed
fix: use short commit sha for next snapshot versions
changesets' {commit} template placeholder only resolves to the full 40-char sha with no short option, producing unreadable versions like 0.0.0-next-db4b842bd8a6605da1374a1b5b66f4eb28f6d0c5. Compute the short sha ourselves and pass it as the snapshot name instead, giving e.g. 0.0.0-next-c047e22.
1 parent c047e22 commit 4e8b476

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

.github/workflows/publish-next.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- run: bun run build
2626

27-
- run: bunx changeset version --snapshot next --snapshot-prerelease-template "{tag}-{commit}"
27+
- run: bunx changeset version --snapshot "next-$(git rev-parse --short HEAD)" --snapshot-prerelease-template "{tag}"
2828

2929
- run: bun publish --registry https://npm.pkg.github.com --tag next --tolerate-republish
3030
env:

openspec/changes/publish-next-github-packages/design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The package name is currently unscoped (`fetchify`). GitHub Packages' npm regist
2020
## Decisions
2121

2222
**Snapshot versioning via `changeset version --snapshot next`, run in CI (not committed).**
23-
Changesets supports a "snapshot" release mode designed exactly for this: with `--snapshot-prerelease-template "{tag}-{commit}"` it computes a version like `0.0.0-next-<full-commit-sha>` from any pending changesets (or a synthetic one if none exist) without touching `.changeset/*.md` files in the working tree or requiring a commit. (Changesets' `getCurrentCommitId` doesn't expose a short-sha option via the CLI template, so the full 40-character sha is used.) The workflow runs this in a throwaway checkout, publishes the resulting `dist`, and discards the version bump — `develop`'s `package.json` version is never mutated. This avoids diverging from the stable versioning flow and needs no new tooling since `@changesets/cli` is already a dependency.
23+
Changesets supports a "snapshot" release mode designed exactly for this: it computes a version from any pending changesets (or a synthetic one if none exist) without touching `.changeset/*.md` files in the working tree or requiring a commit. Changesets' built-in `{commit}` template placeholder only resolves to the full 40-character sha (`getCurrentCommitId` doesn't expose a short-sha option via the CLI), so to get a short, readable version the workflow instead computes the short sha itself (`git rev-parse --short HEAD`) and passes it as the snapshot name — `--snapshot "next-$(git rev-parse --short HEAD)" --snapshot-prerelease-template "{tag}"` — producing e.g. `0.0.0-next-c047e22`. The workflow runs this in a throwaway checkout, publishes the resulting `dist`, and discards the version bump — `develop`'s `package.json` version is never mutated. This avoids diverging from the stable versioning flow and needs no new tooling since `@changesets/cli` is already a dependency.
2424

2525
**Pending changesets must be keyed to the renamed package.** All existing `.changeset/*.md` files were authored with `"fetchify"` as the package key. Changesets matches changeset files to workspace packages by the `name` field in `package.json`, so after the rename to `@kamsteegsoftware/fetchify`, `changeset version` (snapshot or stable) fails with `Found changeset <id> for package fetchify which is not in the workspace` unless those files are updated to `"@kamsteegsoftware/fetchify"` in the same change. Verified locally: renaming the package without updating pending changesets reproduces the error; updating the frontmatter keys resolves it.
2626
- Alternative considered: hand-rolled `<base-version>-next.<sha>` via shell/`jq`. Rejected — reinvents what changesets already does correctly, and wouldn't respect pending changeset bump types.

openspec/changes/publish-next-github-packages/tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
- [x] 2.1 Create `.github/workflows/publish-next.yml` triggered on `push` to `develop` and `workflow_dispatch`
1212
- [x] 2.2 Add steps: checkout, `oven-sh/setup-bun@v2`, `bun install --frozen-lockfile`, `bun run build`
13-
- [x] 2.3 Add a step that runs `bunx changeset version --snapshot next --snapshot-prerelease-template "{tag}-{commit}"` to compute the pre-release version without committing the result
13+
- [x] 2.3 Add a step that runs `bunx changeset version --snapshot "next-$(git rev-parse --short HEAD)" --snapshot-prerelease-template "{tag}"` to compute the pre-release version (short-sha suffixed) without committing the result
1414
- [x] 2.4 Add a step that publishes the built package to GitHub Packages under the `next` dist-tag, authenticated via `GITHUB_TOKEN` (`bun publish --registry https://npm.pkg.github.com --tag next`, auth via `NPM_CONFIG_TOKEN`)
1515
- [x] 2.5 Grant the workflow `packages: write` permission
1616

0 commit comments

Comments
 (0)