Skip to content

Commit 1fe4b47

Browse files
committed
fix(FR-1730): Update the workflow file to correctly tag releases for backend.ai-ui (#4786)
resolves #4715 (FR-1730) This PR improves the npm package publishing workflow by adding a more sophisticated version management strategy: - Added a new `determine-publish-strategy.sh` script that: - Skips publishing alpha versions completely - Automatically publishes RC and beta versions to their respective tags - For stable releases, compares the version with the latest published version - Only publishes if the new version is higher than the currently published one - Prevents accidental downgrades or republishing of the same version - Updated the GitHub workflow to use this new script, making the publishing process more robust and preventing version conflicts **Checklist:** - [ ] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after
1 parent 81732e2 commit 1fe4b47

File tree

2 files changed

+132
-11
lines changed

2 files changed

+132
-11
lines changed

.github/workflows/publish-backend.ai-ui.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,26 @@ jobs:
5757
cd packages/backend.ai-ui
5858
npm publish --tag canary --access public --no-git-checks
5959
60-
- name: Determine npm tag from git tag
60+
- name: Determine npm tag and publish strategy
6161
if: github.ref_type == 'tag'
6262
id: determine-tag
6363
run: |
64-
GIT_TAG="${GITHUB_REF#refs/tags/v}"
64+
cd packages/backend.ai-ui
65+
# Extract version from GITHUB_REF (refs/tags/v25.17.2 -> 25.17.2)
66+
VERSION="${GITHUB_REF#refs/tags/v}"
6567
66-
if [[ "$GIT_TAG" == *"-rc"* ]]; then
67-
NPM_TAG="rc"
68-
elif [[ "$GIT_TAG" == *"-beta"* ]]; then
69-
NPM_TAG="beta"
70-
else
71-
NPM_TAG="latest"
72-
fi
68+
# Run the script and capture stdout (key=value pairs)
69+
SCRIPT_OUTPUT=$(./scripts/determine-publish-strategy.sh "$VERSION")
7370
74-
echo "npm_tag=${NPM_TAG}" >> $GITHUB_OUTPUT
71+
# Parse each line and write to GITHUB_OUTPUT
72+
echo "$SCRIPT_OUTPUT" | while IFS='=' read -r key value; do
73+
if [ -n "$key" ]; then
74+
echo "${key}=${value}" >> $GITHUB_OUTPUT
75+
fi
76+
done
7577
7678
- name: Publish to npm
77-
if: github.ref_type == 'tag'
79+
if: github.ref_type == 'tag' && steps.determine-tag.outputs.should_publish == 'true'
7880
run: |
7981
cd packages/backend.ai-ui
8082
npm publish --tag ${{ steps.determine-tag.outputs.npm_tag }} --access public --no-git-checks
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
PACKAGE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
7+
PACKAGE_JSON="${PACKAGE_DIR}/package.json"
8+
9+
# Get git tag from argument (expects version without 'v' prefix, e.g., 25.17.2)
10+
GIT_TAG="$1"
11+
12+
if [ -z "$GIT_TAG" ]; then
13+
echo "Error: No git tag provided" >&2
14+
echo "Usage: $0 <version>" >&2
15+
echo "Example: $0 25.17.2-rc.0" >&2
16+
exit 1
17+
fi
18+
19+
echo "Analyzing version: ${GIT_TAG}" >&2
20+
21+
PACKAGE_NAME=$(node -p "require('${PACKAGE_JSON}').name")
22+
23+
# Determine npm tag based on version suffix
24+
if [[ "$GIT_TAG" == *"-alpha"* ]]; then
25+
echo "⏭️ Alpha version detected. Skipping npm publish." >&2
26+
echo "should_publish=false"
27+
echo "npm_tag="
28+
exit 0
29+
elif [[ "$GIT_TAG" == *"-rc"* ]]; then
30+
echo "✅ RC version detected. Publishing to rc tag without version check." >&2
31+
echo "should_publish=true"
32+
echo "npm_tag=rc"
33+
exit 0
34+
elif [[ "$GIT_TAG" == *"-beta"* ]]; then
35+
echo "✅ Beta version detected. Publishing to beta tag without version check." >&2
36+
echo "should_publish=true"
37+
echo "npm_tag=beta"
38+
exit 0
39+
else
40+
NPM_TAG="latest"
41+
fi
42+
43+
echo " Determined npm tag: ${NPM_TAG}" >&2
44+
45+
# Get the latest published version for the latest tag
46+
LATEST_VERSION=$(npm view "${PACKAGE_NAME}@${NPM_TAG}" version 2>/dev/null || echo "0.0.0")
47+
48+
echo " Current version: ${GIT_TAG}" >&2
49+
echo " Latest published ${NPM_TAG} version: ${LATEST_VERSION}" >&2
50+
51+
# Function to extract base version (major.minor.patch) from semver string
52+
extract_base_version() {
53+
local version="$1"
54+
# Extract major.minor.patch, ignoring prerelease tags
55+
echo "$version" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/'
56+
}
57+
58+
# Function to compare two semver versions (major.minor.patch only)
59+
# Returns: 0 if v1 > v2, 1 if v1 == v2, 2 if v1 < v2
60+
compare_versions() {
61+
local v1="$1"
62+
local v2="$2"
63+
64+
# Split versions into components
65+
IFS='.' read -r -a v1_parts <<< "$v1"
66+
IFS='.' read -r -a v2_parts <<< "$v2"
67+
68+
# Compare major, minor, patch
69+
for i in 0 1 2; do
70+
local part1="${v1_parts[$i]:-0}"
71+
local part2="${v2_parts[$i]:-0}"
72+
73+
if (( part1 > part2 )); then
74+
return 0 # v1 > v2
75+
elif (( part1 < part2 )); then
76+
return 2 # v1 < v2
77+
fi
78+
done
79+
80+
return 1 # v1 == v2
81+
}
82+
83+
# Extract base versions for comparison
84+
CURRENT_BASE=$(extract_base_version "$GIT_TAG")
85+
LATEST_BASE=$(extract_base_version "$LATEST_VERSION")
86+
87+
echo " Comparing base versions: ${CURRENT_BASE} vs ${LATEST_BASE}" >&2
88+
89+
# Compare versions (temporarily disable exit on error for return codes)
90+
set +e
91+
compare_versions "$CURRENT_BASE" "$LATEST_BASE"
92+
COMPARISON=$?
93+
set -e
94+
95+
# Output results to stdout (GitHub Actions will capture this)
96+
case "$COMPARISON" in
97+
0) # Current > Latest
98+
echo "✅ Version ${GIT_TAG} is publishable (> ${LATEST_VERSION})" >&2
99+
echo "should_publish=true"
100+
echo "npm_tag=${NPM_TAG}"
101+
exit 0
102+
;;
103+
1) # Current == Latest
104+
echo "⏭️ Skipping publish: version ${GIT_TAG} is already published as ${LATEST_VERSION}" >&2
105+
echo "should_publish=false"
106+
echo "npm_tag="
107+
exit 0
108+
;;
109+
2) # Current < Latest
110+
echo "⏭️ Skipping publish: version ${GIT_TAG} is lower than latest ${LATEST_VERSION}" >&2
111+
echo "should_publish=false"
112+
echo "npm_tag="
113+
exit 0
114+
;;
115+
*)
116+
echo "Error: Unexpected comparison result" >&2
117+
exit 1
118+
;;
119+
esac

0 commit comments

Comments
 (0)