🐛 fix(update): 修正 Linux 变体自动更新失效

- 更新资产选择逻辑按当前 Linux 可执行文件变体匹配 release 包
- Linux 更新脚本优先查找与当前二进制同名的新文件
- 补充自动更新回归测试并更新 backlog 记录

Fixes #337
This commit is contained in:
Syngnat
2026-04-17 12:17:11 +08:00
parent a2cad9f7ce
commit 8c79f2af0c
3 changed files with 79 additions and 2 deletions

View File

@@ -493,6 +493,19 @@ func fetchLatestRelease() (*githubRelease, error) {
}
func expectedAssetName(goos, goarch, version string) (string, error) {
executablePath := ""
if goos == "linux" {
if path, err := os.Executable(); err == nil {
if resolved, resolveErr := filepath.EvalSymlinks(path); resolveErr == nil && strings.TrimSpace(resolved) != "" {
path = resolved
}
executablePath = path
}
}
return expectedAssetNameForExecutable(goos, goarch, version, executablePath)
}
func expectedAssetNameForExecutable(goos, goarch, version, executablePath string) (string, error) {
version = strings.TrimSpace(version)
version = strings.TrimPrefix(version, "v")
version = strings.TrimPrefix(version, "V")
@@ -517,12 +530,26 @@ func expectedAssetName(goos, goarch, version string) (string, error) {
}
case "linux":
if goarch == "amd64" {
return fmt.Sprintf("GoNavi-%s-Linux-Amd64.tar.gz", version), nil
return fmt.Sprintf("GoNavi-%s-Linux-Amd64%s.tar.gz", version, resolveLinuxReleaseArtifactSuffix(executablePath)), nil
}
}
return "", fmt.Errorf("当前平台暂不支持在线更新:%s/%s", goos, goarch)
}
func resolveLinuxReleaseArtifactSuffix(executablePath string) string {
normalizedPath := strings.ToLower(strings.TrimSpace(executablePath))
if normalizedPath == "" {
return ""
}
normalizedPath = strings.ReplaceAll(normalizedPath, "\\", "/")
compactPath := strings.ReplaceAll(normalizedPath, "_", "")
compactPath = strings.ReplaceAll(compactPath, "-", "")
if strings.Contains(normalizedPath, "webkit41") || strings.Contains(compactPath, "webkit241") || strings.Contains(compactPath, "webkit41") {
return "-WebKit41"
}
return ""
}
func findReleaseAsset(assets []githubAsset, name string) (*githubAsset, error) {
for _, asset := range assets {
if asset.Name == name {
@@ -1195,8 +1222,12 @@ while kill -0 $PID 2>/dev/null; do
done
TMPDIR=$(mktemp -d)
tar -xzf "$ARCHIVE" -C "$TMPDIR"
NEWBIN="$TMPDIR/GoNavi"
TARGET_NAME="$(basename "$TARGET")"
NEWBIN="$TMPDIR/$TARGET_NAME"
if [ ! -f "$NEWBIN" ]; then
NEWBIN=$(find "$TMPDIR" -type f -name "$TARGET_NAME" | head -n 1)
fi
if [ -z "$NEWBIN" ] || [ ! -f "$NEWBIN" ]; then
NEWBIN=$(find "$TMPDIR" -type f -name "GoNavi" | head -n 1)
fi
if [ -z "$NEWBIN" ] || [ ! -f "$NEWBIN" ]; then