feat: 优化更新加速逻辑

This commit is contained in:
digua
2026-01-10 00:09:23 +08:00
parent cabd10a11e
commit 4ed30d5853
2 changed files with 66 additions and 16 deletions

View File

@@ -245,7 +245,8 @@ jobs:
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
- name: Upload to Cloudflare R2
# 上传所有文件到版本目录
- name: Upload to Cloudflare R2 (version directory)
uses: ryand56/r2-upload-action@latest
with:
r2-account-id: ${{ secrets.R2_ACCOUNT_ID }}
@@ -254,3 +255,39 @@ jobs:
r2-bucket: ${{ secrets.R2_BUCKET_NAME }}
source-dir: dist
destination-dir: releases/download/${{ steps.version.outputs.tag }}
# 准备 yml 文件用于根目录上传
# 需要修改 yml 中的 path/url 为包含版本号的完整路径
- name: Prepare yml files for root upload
run: |
mkdir -p dist-yml
VERSION_TAG="${{ steps.version.outputs.tag }}"
# 处理所有 yml 文件
for yml_file in dist/*.yml; do
filename=$(basename "$yml_file")
echo "Processing $filename..."
# 使用 sed 修改 path 和 url 字段,添加版本目录前缀
# path: ChatLab-x.x.x-arm64.dmg → path: vx.x.x/ChatLab-x.x.x-arm64.dmg
# url: ChatLab-x.x.x-arm64.dmg → url: vx.x.x/ChatLab-x.x.x-arm64.dmg
sed -E "s|^(path: )(.+)|\1${VERSION_TAG}/\2|g; s|^( - url: )(.+)|\1${VERSION_TAG}/\2|g" "$yml_file" > "dist-yml/$filename"
echo "Original:"
cat "$yml_file"
echo ""
echo "Modified:"
cat "dist-yml/$filename"
echo "---"
done
# 上传 yml 文件到根目录覆盖旧版本electron-updater 从这里检测更新)
- name: Upload yml files to Cloudflare R2 (root directory)
uses: ryand56/r2-upload-action@latest
with:
r2-account-id: ${{ secrets.R2_ACCOUNT_ID }}
r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }}
r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
r2-bucket: ${{ secrets.R2_BUCKET_NAME }}
source-dir: dist-yml
destination-dir: releases/download