Skip to content

Commit 5aedc39

Browse files
committed
feat(ci): add +latest suffix for promoting prereleases to @latest
1 parent 346ac9c commit 5aedc39

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

.gitlab-ci.yml

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,31 +205,45 @@ cli:npm:publish:
205205
exit 1
206206
fi
207207
208-
# npm requires SemVer. We accept an optional leading 'v' in git tags for npm publishing,
209-
# but the raw git tag is still treated as the canonical version string elsewhere (e.g. in container /VERSION).
210-
TAG_VERSION="$RAW_TAG"
208+
# npm requires SemVer. We accept an optional leading 'v' in git tags (e.g., v0.14.0 or 0.14.0).
211209
NPM_VERSION="${RAW_TAG#v}"
212210
if ! printf '%s' "$NPM_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([-+][-0-9A-Za-z.]+)?$'; then
213211
echo "Invalid npm version derived from git tag: RAW_TAG='$RAW_TAG' -> NPM_VERSION='$NPM_VERSION' (must be SemVer)"
214212
exit 1
215213
fi
216214
215+
# Determine npm dist-tags:
216+
# - X.Y.Z (final release) → @latest
217+
# - X.Y.Z-beta.N → @latest + @beta
218+
# - X.Y.Z-rc.N → @latest + @rc
219+
# - X.Y.Z-dev.N → @dev only
217220
DIST_TAG=""
218-
if printf '%s' "$NPM_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-(dev|beta|rc)\.[0-9]+$'; then
219-
DIST_TAG="$(printf '%s' "$NPM_VERSION" | sed -E 's/^.*-(dev|beta|rc)\.[0-9]+$/\1/')"
220-
elif printf '%s' "$NPM_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
221+
EXTRA_TAG=""
222+
if printf '%s' "$NPM_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
221223
DIST_TAG="latest"
224+
elif printf '%s' "$NPM_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+$'; then
225+
DIST_TAG="latest"
226+
EXTRA_TAG="beta"
227+
elif printf '%s' "$NPM_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$'; then
228+
DIST_TAG="latest"
229+
EXTRA_TAG="rc"
230+
elif printf '%s' "$NPM_VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-dev\.[0-9]+$'; then
231+
DIST_TAG="dev"
222232
fi
223233
224-
if [ "$DIST_TAG" != "dev" ] && [ "$DIST_TAG" != "beta" ] && [ "$DIST_TAG" != "rc" ] && [ "$DIST_TAG" != "latest" ]; then
225-
echo "Unsupported version: $NPM_VERSION (expected X.Y.Z, X.Y.Z-dev.N, X.Y.Z-beta.N, or X.Y.Z-rc.N)"
234+
if [ -z "$DIST_TAG" ]; then
235+
echo "Unsupported version: $NPM_VERSION (expected X.Y.Z, X.Y.Z-beta.N, X.Y.Z-rc.N, or X.Y.Z-dev.N)"
226236
exit 1
227237
fi
228238
229239
# Configure npm auth without committing credentials
230240
printf "//registry.npmjs.org/:_authToken=%s\n" "$NPM_TOKEN" > ~/.npmrc
231241
232-
echo "Publishing postgresai@${NPM_VERSION} to dist-tag ${DIST_TAG}"
242+
if [ -n "$EXTRA_TAG" ]; then
243+
echo "Publishing postgresai@${NPM_VERSION} to dist-tags: ${DIST_TAG}, ${EXTRA_TAG}"
244+
else
245+
echo "Publishing postgresai@${NPM_VERSION} to dist-tag: ${DIST_TAG}"
246+
fi
233247
cd cli
234248
# Use bun for faster install and build
235249
export BUN_INSTALL="$HOME/.bun" && export PATH="$BUN_INSTALL/bin:$PATH"
@@ -239,6 +253,10 @@ cli:npm:publish:
239253
bun run build
240254
npm publish --dry-run --tag "$DIST_TAG" --access public
241255
npm publish --tag "$DIST_TAG" --access public
256+
# Add extra dist-tag if specified (e.g., @beta or @rc in addition to @latest)
257+
if [ -n "$EXTRA_TAG" ]; then
258+
npm dist-tag add "postgresai@${NPM_VERSION}" "$EXTRA_TAG"
259+
fi
242260
243261
# Wait until the registry sees the new postgresai version. This prevents the pgai step from
244262
# failing due to eventual consistency when verifying/pinning dependencies.
@@ -251,13 +269,21 @@ cli:npm:publish:
251269
done
252270
npm view "postgresai@${NPM_VERSION}" version >/dev/null
253271
254-
echo "Publishing pgai@${NPM_VERSION} (wrapper) to dist-tag ${DIST_TAG}"
272+
if [ -n "$EXTRA_TAG" ]; then
273+
echo "Publishing pgai@${NPM_VERSION} (wrapper) to dist-tags: ${DIST_TAG}, ${EXTRA_TAG}"
274+
else
275+
echo "Publishing pgai@${NPM_VERSION} (wrapper) to dist-tag: ${DIST_TAG}"
276+
fi
255277
cd ../pgai
256278
# Update version + dependency so `npx pgai@<tag>` pulls the matching postgresai version.
257279
npm pkg set "dependencies.postgresai=$NPM_VERSION"
258280
npm version --no-git-tag-version "$NPM_VERSION"
259281
npm publish --dry-run --tag "$DIST_TAG" --access public
260282
npm publish --tag "$DIST_TAG" --access public
283+
# Add extra dist-tag if specified
284+
if [ -n "$EXTRA_TAG" ]; then
285+
npm dist-tag add "pgai@${NPM_VERSION}" "$EXTRA_TAG"
286+
fi
261287
262288
for i in $(seq 1 30); do
263289
if npm view "pgai@${NPM_VERSION}" version >/dev/null 2>&1; then

0 commit comments

Comments
 (0)