Skip to content

Commit db901f8

Browse files
committed
ci(release): publish any prerelease tag under its own dist-tag
The publish step only special-cased "-alpha", so a v5.8.0-beta.1 tag fell through to the else branch and moved the "latest" dist-tag, shipping a prerelease to every consumer on ^5. Derive the dist-tag from the tag's prerelease identifier instead, which covers beta and rc without a branch per channel, and reserve "latest" for plain vX.Y.Z tags. The draft GitHub release is now flagged --prerelease for those versions too. release.sh gains an optional preid argument: lerna defaults the prerelease identifier to "alpha", so beta was previously unreachable through the script.
1 parent 3735985 commit db901f8

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,24 @@ jobs:
7171
- if: github.event_name == 'push'
7272
name: Publish the libraries
7373
run: |
74-
if [[ "${{ github.ref }}" == *"-alpha"* ]]; then
75-
pnpm publish -r --access=public --no-git-checks --tag=alpha
76-
else
74+
# Prerelease tags publish under their own identifier (alpha, beta, rc);
75+
# only a plain vX.Y.Z tag is allowed to move the `latest` dist-tag.
76+
VERSION="${GITHUB_REF_NAME#v}"
77+
if [[ "$VERSION" != *-* ]]; then
7778
pnpm publish -r --access=public --no-git-checks
79+
exit 0
7880
fi
81+
82+
PREID="${VERSION#*-}"
83+
PREID="${PREID%%.*}"
84+
# npm rejects a dist-tag that parses as a semver range, so a numeric
85+
# identifier has no channel to publish under, and `latest` is the
86+
# stable channel a prerelease must never take over.
87+
if [[ ! "$PREID" =~ ^[A-Za-z][A-Za-z0-9-]*$ || "${PREID,,}" == "latest" ]]; then
88+
echo "Refusing to publish $GITHUB_REF_NAME: '$PREID' cannot be a prerelease dist-tag" >&2
89+
exit 1
90+
fi
91+
pnpm publish -r --access=public --no-git-checks --tag="$PREID"
7992
env:
8093
NPM_CONFIG_PROVENANCE: true
8194
# Surfaces npm's OIDC token exchange, which is otherwise silent.
@@ -85,6 +98,10 @@ jobs:
8598
name: Create a draft release
8699
run: |
87100
NEW_VERSION=$(pnpm lerna list --json | jq -r '.[] | select(.name == "@codspeed/core") | .version')
88-
gh release create v$NEW_VERSION --title "v$NEW_VERSION" --generate-notes -d
101+
PRERELEASE=""
102+
if [[ "$NEW_VERSION" == *-* ]]; then
103+
PRERELEASE="--prerelease"
104+
fi
105+
gh release create "v$NEW_VERSION" --title "v$NEW_VERSION" --generate-notes -d $PRERELEASE
89106
env:
90107
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎scripts/release.sh‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Usage: ./scripts/release.sh <major|minor|patch>
2+
# Usage: ./scripts/release.sh <major|minor|patch|premajor|preminor|prepatch|prerelease> [preid]
33
set -ex
44

55
# Fail if not on main
@@ -8,12 +8,24 @@ if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then
88
exit 1
99
fi
1010

11-
if [ $# -ne 1 ]; then
12-
echo "Usage: ./release.sh <major|minor|patch>"
11+
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
12+
echo "Usage: ./release.sh <major|minor|patch|premajor|preminor|prepatch|prerelease> [preid]"
1313
exit 1
1414
fi
1515

16+
# lerna defaults the prerelease identifier to "alpha"; the dist-tag the release
17+
# workflow publishes under is derived from it, so it must be spelled out for
18+
# any other channel.
19+
PREID=()
20+
if [ $# -eq 2 ]; then
21+
if [[ ! "$2" =~ ^[a-z][a-z0-9-]*$ || "$2" == "latest" ]]; then
22+
echo "Invalid prerelease identifier: '$2' (expected e.g. alpha, beta, rc)"
23+
exit 1
24+
fi
25+
PREID=(--preid "$2")
26+
fi
27+
1628
# Fail if there are any unstaged changes left
1729
git diff --exit-code
1830

19-
pnpm lerna version "$1" --force-publish --no-private --sign-git-tag
31+
pnpm lerna version "$1" "${PREID[@]}" --force-publish --no-private --sign-git-tag

0 commit comments

Comments
 (0)