Skip to content

Commit 91195db

Browse files
committed
fix: enhance beta versioning logic in workflow
1 parent 2d74766 commit 91195db

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

.github/workflows/beta-release.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,36 @@ jobs:
3030
- name: "Create build"
3131
run: npm run build
3232

33-
- name: "Get version from package.json and create beta version"
33+
- name: "Get version and package name from package.json and create beta version"
3434
id: get_version
3535
run: |
36+
PACKAGE_NAME=$(node -p 'require("./package.json").name')
3637
BASE_VERSION=$(node -p 'require("./package.json").version')
37-
BETA_VERSION="$BASE_VERSION-beta"
38+
39+
# Fetch all published versions for this package
40+
ALL_VERSIONS=$(npm view $PACKAGE_NAME versions --json 2>/dev/null || echo "[]")
41+
42+
# Get latest beta for this base version
43+
LATEST_BETA=$(echo $ALL_VERSIONS | jq -r '.[] | select(startswith("'"$BASE_VERSION"'-beta."))' | sort -V | tail -n 1)
44+
45+
if [ -z "$LATEST_BETA" ]; then
46+
COUNTER=1
47+
else
48+
COUNTER=$(echo $LATEST_BETA | sed -E 's/.*-beta\.([0-9]+)$/\1/')
49+
COUNTER=$((COUNTER + 1))
50+
fi
51+
52+
BETA_VERSION="$BASE_VERSION-beta.$COUNTER"
53+
54+
echo "package=$PACKAGE_NAME" >> $GITHUB_OUTPUT
3855
echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT
39-
echo "Beta version: $BETA_VERSION"
56+
echo "Beta version: $BETA_VERSION for package: $PACKAGE_NAME"
4057
4158
- name: "Check if beta version already exists on NPM"
4259
run: |
60+
PACKAGE_NAME=${{ steps.get_version.outputs.package }}
4361
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
62+
if npm view $PACKAGE_NAME@$BETA_VERSION version 2>/dev/null; then
4663
echo "Error: Beta version $BETA_VERSION already exists on NPM!"
4764
exit 1
4865
fi
@@ -55,4 +72,5 @@ jobs:
5572
- name: "Publish beta to NPM"
5673
run: npm publish --tag beta --access public
5774
env:
58-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
75+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
76+

0 commit comments

Comments
 (0)