Skip to content

Commit cab3ff3

Browse files
committed
fixup! ci(release): publish any prerelease tag under its own dist-tag
1 parent 592c33f commit cab3ff3

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,21 @@ jobs:
7373
run: |
7474
# Prerelease tags publish under their own identifier (alpha, beta, rc);
7575
# only a plain vX.Y.Z tag is allowed to move the `latest` dist-tag.
76-
PREID=$(sed -n 's/^v[0-9]\+\.[0-9]\+\.[0-9]\+-\([a-z][a-z0-9]*\).*/\1/p' <<<"$GITHUB_REF_NAME")
77-
pnpm publish -r --access=public --no-git-checks ${PREID:+--tag="$PREID"}
76+
VERSION="${GITHUB_REF_NAME#v}"
77+
if [[ "$VERSION" != *-* ]]; then
78+
pnpm publish -r --access=public --no-git-checks
79+
exit 0
80+
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.
86+
if [[ ! "$PREID" =~ ^[A-Za-z][A-Za-z0-9-]*$ ]]; then
87+
echo "Refusing to publish $GITHUB_REF_NAME: '$PREID' cannot be an npm dist-tag" >&2
88+
exit 1
89+
fi
90+
pnpm publish -r --access=public --no-git-checks --tag="$PREID"
7891
env:
7992
NPM_CONFIG_PROVENANCE: true
8093
# Surfaces npm's OIDC token exchange, which is otherwise silent.

‎scripts/release.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ fi
3434
# out here.
3535
PREID=()
3636
if [ $# -eq 2 ]; then
37+
if [[ ! "$2" =~ ^[a-z][a-z0-9-]*$ ]]; then
38+
echo "Invalid prerelease identifier: '$2' (expected e.g. alpha, beta, rc)"
39+
exit 1
40+
fi
3741
PREID=(--preid "$2")
3842
fi
3943

0 commit comments

Comments
 (0)