Accept Merge Request #165: (feature/hant -> develop)

Merge Request: 新打包

Created By: @todayswind
Accepted By: @todayswind
URL: https://g-bcrc3009.coding.net/p/allocatr/d/allocatr/git/merge/165?initial=true
This commit is contained in:
todayswind 2025-06-20 18:09:51 +08:00 committed by Coding
commit c32811f90c

44
deploy-if-new-tag.sh Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
set -e
SITE_FILE="application/extra/site.php"
# 获取本地当前 tag假设是当前 HEAD 所在 tag
current_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
# 拉取最新 tags
git fetch --tags
# 获取远程最新 tag
latest_tag=$(git tag --sort=-v:refname | head -n 1)
echo "当前 tag: ${current_tag}"
echo "远程最新 tag: ${latest_tag}"
# 函数:将 tag 转换成整数用于比较
version_to_int() {
local IFS=.
read -r major minor patch <<< "$1"
printf "%03d%03d%03d" "$major" "$minor" "$patch"
}
if [ "$(version_to_int "$latest_tag")" -gt "$(version_to_int "$current_tag")" ]; then
echo "🚀 检测到新版本,准备更新为 $latest_tag"
# 拉取代码并 checkout 到该 tag注意如果是部署环境建议 --force
git checkout -f "tags/$latest_tag"
# 更新 site.php 文件中的版本号
if [ -f "$SITE_FILE" ]; then
sed -i.bak "s/'version' => '.*'/'version' => '${latest_tag}'/" "$SITE_FILE"
rm "$SITE_FILE.bak"
echo "✅ 已更新 $SITE_FILE 为版本 $latest_tag"
else
echo "⚠️ 找不到 $SITE_FILE,未更新版本号"
fi
echo "✅ 部署完成,新版本:$latest_tag"
else
echo "🟢 当前已是最新版本,无需更新"
fi