Skip to content

Commit 6783ae1

Browse files
authored
fix: enhance beta versioning logic in workflow (#125)
1 parent 2d74766 commit 6783ae1

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

.github/workflows/beta-release.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: "Beta Release"
22

33
on:
4-
push:
5-
branches:
6-
- beta
74
workflow_dispatch:
85

96
permissions:
@@ -30,19 +27,36 @@ jobs:
3027
- name: "Create build"
3128
run: npm run build
3229

33-
- name: "Get version from package.json and create beta version"
30+
- name: "Get version and package name from package.json and create beta version"
3431
id: get_version
3532
run: |
33+
PACKAGE_NAME=$(node -p 'require("./package.json").name')
3634
BASE_VERSION=$(node -p 'require("./package.json").version')
37-
BETA_VERSION="$BASE_VERSION-beta"
35+
36+
# Fetch all published versions for this package
37+
ALL_VERSIONS=$(npm view $PACKAGE_NAME versions --json 2>/dev/null || echo "[]")
38+
39+
# Get latest beta for this base version
40+
LATEST_BETA=$(echo $ALL_VERSIONS | jq -r '.[] | select(startswith("'"$BASE_VERSION"'-beta."))' | sort -V | tail -n 1)
41+
42+
if [ -z "$LATEST_BETA" ]; then
43+
COUNTER=1
44+
else
45+
COUNTER=$(echo $LATEST_BETA | sed -E 's/.*-beta\.([0-9]+)$/\1/')
46+
COUNTER=$((COUNTER + 1))
47+
fi
48+
49+
BETA_VERSION="$BASE_VERSION-beta.$COUNTER"
50+
51+
echo "package=$PACKAGE_NAME" >> $GITHUB_OUTPUT
3852
echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT
39-
echo "Beta version: $BETA_VERSION"
53+
echo "Beta version: $BETA_VERSION for package: $PACKAGE_NAME"
4054
4155
- name: "Check if beta version already exists on NPM"
4256
run: |
57+
PACKAGE_NAME=${{ steps.get_version.outputs.package }}
4358
BETA_VERSION=${{ steps.get_version.outputs.version }}
44-
# Check if version exists on npm
45-
if npm view @browserstack/mcp-server@$BETA_VERSION version 2>/dev/null; then
59+
if npm view $PACKAGE_NAME@$BETA_VERSION version 2>/dev/null; then
4660
echo "Error: Beta version $BETA_VERSION already exists on NPM!"
4761
exit 1
4862
fi
@@ -55,4 +69,5 @@ jobs:
5569
- name: "Publish beta to NPM"
5670
run: npm publish --tag beta --access public
5771
env:
58-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
72+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
73+

0 commit comments

Comments
 (0)