Skip to content

Commit 963f628

Browse files
release: cut -rcN release candidates under the rc dist-tag and promote them (#4)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 17aa1a5 commit 963f628

3 files changed

Lines changed: 94 additions & 17 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Release
22

33
# Stages one package on npm when a <package>-v<version> tag is pushed
4-
# (vitest-v0.6.5, mocha-v0.1.0); a maintainer then reviews and releases it
4+
# (vitest-v0.6.5, mocha-v0.1.0, jest-v0.2.0-rc1); a maintainer then reviews and releases it
55
# with `npm stage approve <id>` (2FA prompt). The tag must match the
66
# package's package.json, and a version already on the registry is never
77
# republished. Uses npm trusted publishing (OIDC), so no token is stored; each
@@ -52,5 +52,13 @@ jobs:
5252
echo "${name}@${version} is already published" >&2
5353
exit 1
5454
fi
55-
- run: npm stage publish --provenance --access public # prepack runs the build
55+
# A release candidate goes under the dist-tag `rc`: `latest`, which a plain
56+
# install and version ranges resolve, stays on the last production release.
57+
- name: Pick the dist-tag
58+
run: |
59+
case "$GITHUB_REF_NAME" in
60+
*-rc[0-9]*) echo "DIST_TAG=rc" >> "$GITHUB_ENV" ;;
61+
*) echo "DIST_TAG=latest" >> "$GITHUB_ENV" ;;
62+
esac
63+
- run: npm stage publish --provenance --access public --tag "$DIST_TAG" # prepack runs the build
5664
working-directory: packages/${{ env.PACKAGE }}

‎README.md‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ pnpm pack --pack-destination /tmp/tarball
4848
BLACKSMITH_E2E_TARBALL=/tmp/tarball/useblacksmith-jest-0.1.0.tgz pnpm run test:e2e
4949
```
5050

51-
Releases are cut per package: `pnpm run release <vitest|mocha|jest> <major|minor|patch>`.
51+
### Releases
52+
53+
Releases are cut per package from `main` with `pnpm run release <vitest|mocha|jest> <action>`.
54+
The script sets the version, pushes the commit and the `<package>-v<version>`
55+
tag, and the Release workflow stages that version on npm.
56+
57+
| Current version | Command | New version | npm dist-tag |
58+
| --- | --- | --- | --- |
59+
| `1.2.3` | `patch`, `minor` or `major` | `1.2.4`, `1.3.0` or `2.0.0` | `latest` |
60+
| `1.2.3` | `patch`, `minor` or `major` with `--rc` | `1.2.4-rc1`, `1.3.0-rc1` or `2.0.0-rc1` | `rc` |
61+
| `1.3.0-rc1` | `rc` | `1.3.0-rc2` | `rc` |
62+
| `1.3.0-rc1` | `promote` | `1.3.0` | `latest` |
63+
64+
A release candidate is not what `npm install @useblacksmith/<package>` or a
65+
version range resolves; install one with `@useblacksmith/<package>@rc` or its
66+
exact version. From a release candidate, `patch`, `minor` and `major` are
67+
refused; from a production version, `rc` and `promote` are.

‎scripts/release.sh‎

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,79 @@
11
#!/usr/bin/env bash
2-
# Cuts a release of one package from main: bumps its package.json, pushes
3-
# that commit, then pushes the <package>-v<version> tag that release.yml publishes.
2+
# Cuts a release of one package from main: sets the version in its
3+
# package.json, pushes that commit, then pushes the <package>-v<version> tag
4+
# that release.yml publishes.
5+
#
6+
# A release candidate (1.3.0-rc1) is published under the npm dist-tag `rc`, so
7+
# `npm install <package>` and version ranges keep resolving to the last
8+
# production release. From a production version name the bump; from a release
9+
# candidate, cut the next candidate or promote it.
410
set -euo pipefail
511

12+
usage() {
13+
cat >&2 <<'USAGE'
14+
usage: pnpm run release <vitest|mocha|jest> <major|minor|patch> [--rc]
15+
pnpm run release <vitest|mocha|jest> <rc|promote>
16+
17+
from a production version (1.2.3):
18+
patch | minor | major 1.2.4 | 1.3.0 | 2.0.0
19+
patch | minor | major --rc 1.2.4-rc1 | 1.3.0-rc1 | 2.0.0-rc1
20+
from a release candidate (1.3.0-rc1):
21+
rc 1.3.0-rc2
22+
promote 1.3.0
23+
USAGE
24+
exit 2
25+
}
26+
627
package=${1:-}
7-
bump=${2:-}
28+
action=${2:-}
29+
flag=${3:-}
830
case "$package" in
931
vitest | mocha | jest) ;;
10-
*) package= ;;
32+
*) usage ;;
1133
esac
12-
case "$bump" in
13-
major | minor | patch) ;;
14-
*) bump= ;;
34+
case "$action" in
35+
major | minor | patch) [ -z "$flag" ] || [ "$flag" = --rc ] || usage ;;
36+
rc | promote) [ -z "$flag" ] || usage ;;
37+
*) usage ;;
1538
esac
16-
if [ -z "$package" ] || [ -z "$bump" ]; then
17-
echo "usage: pnpm run release <vitest|mocha|jest> <major|minor|patch>" >&2
18-
exit 2
19-
fi
39+
[ $# -le 3 ] || usage
2040

2141
cd "$(git rev-parse --show-toplevel)"
2242
manifest="packages/$package/package.json"
2343

44+
current=$(node -p "require('./$manifest').version")
45+
if [[ $current =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-rc([0-9]+))?$ ]]; then
46+
major=${BASH_REMATCH[1]}
47+
minor=${BASH_REMATCH[2]}
48+
patch=${BASH_REMATCH[3]}
49+
candidate=${BASH_REMATCH[5]}
50+
else
51+
echo "$manifest has version $current, which is neither x.y.z nor x.y.z-rcN" >&2
52+
exit 1
53+
fi
54+
55+
if [ -n "$candidate" ]; then
56+
case "$action" in
57+
rc) next="$major.$minor.$patch-rc$((candidate + 1))" ;;
58+
promote) next="$major.$minor.$patch" ;;
59+
*)
60+
echo "$package is at release candidate $current: use rc for the next candidate or promote to release $major.$minor.$patch" >&2
61+
exit 1
62+
;;
63+
esac
64+
else
65+
case "$action" in
66+
major) next="$((major + 1)).0.0" ;;
67+
minor) next="$major.$((minor + 1)).0" ;;
68+
patch) next="$major.$minor.$((patch + 1))" ;;
69+
*)
70+
echo "$package is at $current, not a release candidate: name the bump (major, minor or patch), with --rc for a candidate" >&2
71+
exit 1
72+
;;
73+
esac
74+
[ "$flag" != --rc ] || next="$next-rc1"
75+
fi
76+
2477
branch=$(git rev-parse --abbrev-ref HEAD)
2578
if [ "$branch" != main ]; then
2679
echo "releases are cut from main, not from $branch" >&2
@@ -39,10 +92,10 @@ if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
3992
fi
4093

4194
# The workspace lockfile does not record a workspace package's own version.
42-
version=$(cd "packages/$package" && npm version "$bump" --no-git-tag-version)
43-
tag="$package-$version"
95+
(cd "packages/$package" && npm version "$next" --no-git-tag-version >/dev/null)
96+
tag="$package-v$next"
4497
git commit --quiet -m "release: $tag" -- "$manifest"
4598
git tag "$tag"
4699
git push origin main
47100
git push origin "$tag"
48-
echo "pushed $tag; release.yml stages it on npm"
101+
echo "pushed $tag ($current -> $next); release.yml stages it on npm"

0 commit comments

Comments
 (0)