Skip to content

Commit efabb8d

Browse files
committed
fix(ci): use semantic version compare in sync_openlist
1 parent 8cb85fc commit efabb8d

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

.github/scripts/check_openlist.sh

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,39 @@
22

33
GIT_REPO="https://github.com/OpenListTeam/OpenList.git"
44

5-
function to_int() {
6-
echo $(echo "$1" | grep -oE '[0-9]+' | tr -d '\n')
5+
function compare_versions() {
6+
local v1="${1#v}"
7+
local v2="${2#v}"
8+
local max_len=0
9+
10+
IFS='.' read -r -a v1_parts <<< "$v1"
11+
IFS='.' read -r -a v2_parts <<< "$v2"
12+
13+
if [ "${#v1_parts[@]}" -gt "${#v2_parts[@]}" ]; then
14+
max_len="${#v1_parts[@]}"
15+
else
16+
max_len="${#v2_parts[@]}"
17+
fi
18+
19+
for ((i=0; i<max_len; i++)); do
20+
local p1="${v1_parts[i]:-0}"
21+
local p2="${v2_parts[i]:-0}"
22+
23+
p1=$(echo "$p1" | grep -oE '^[0-9]+' || echo 0)
24+
p2=$(echo "$p2" | grep -oE '^[0-9]+' || echo 0)
25+
26+
if ((10#$p1 > 10#$p2)); then
27+
echo 1
28+
return
29+
fi
30+
31+
if ((10#$p1 < 10#$p2)); then
32+
echo -1
33+
return
34+
fi
35+
done
36+
37+
echo 0
738
}
839

940
function get_latest_version() {
@@ -28,8 +59,7 @@ do
2859

2960
done
3061

31-
LATEST_VER_INT=$(to_int "$LATEST_VER")
32-
echo "Latest OpenList version $LATEST_VER ${LATEST_VER_INT}"
62+
echo "Latest OpenList version $LATEST_VER"
3363

3464
echo "openlist_version=$LATEST_VER" >> "$GITHUB_ENV"
3565
# VERSION_FILE="$GITHUB_WORKSPACE/openlist_version.txt"
@@ -41,12 +71,11 @@ if [ -z "$VER" ]; then
4171
echo "No version file, use default version ${VER}"
4272
fi
4373

44-
VER_INT=$(to_int $VER)
45-
46-
echo "Current OpenList version: $VER ${VER_INT}"
74+
echo "Current OpenList version: $VER"
4775

76+
COMPARE_RESULT=$(compare_versions "$VER" "$LATEST_VER")
4877

49-
if [ "$VER_INT" -ge "$LATEST_VER_INT" ]; then
78+
if [ "$COMPARE_RESULT" -ge 0 ]; then
5079
echo "Current >= Latest"
5180
echo "openlist_update=0" >> "$GITHUB_ENV"
5281
else

0 commit comments

Comments
 (0)