mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-06 22:49:35 +08:00
🐛 fix(update): 修正 Linux 变体自动更新失效
- 更新资产选择逻辑按当前 Linux 可执行文件变体匹配 release 包 - Linux 更新脚本优先查找与当前二进制同名的新文件 - 补充自动更新回归测试并更新 backlog 记录 Fixes #337
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"errors"
|
||||
stdRuntime "runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -158,3 +159,41 @@ func TestCheckForUpdatesSilentlySkipsFailureLogs(t *testing.T) {
|
||||
t.Fatalf("expected silent check to skip error logging, got %d", logged)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpectedAssetNameForExecutableUsesLinuxWebKit41Suffix(t *testing.T) {
|
||||
assetName, err := expectedAssetNameForExecutable(
|
||||
"linux",
|
||||
"amd64",
|
||||
"v0.6.5",
|
||||
"/opt/GoNavi/gonavi-build-linux-amd64-webkit41",
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("expectedAssetNameForExecutable returned error: %v", err)
|
||||
}
|
||||
|
||||
want := "GoNavi-0.6.5-Linux-Amd64-WebKit41.tar.gz"
|
||||
if assetName != want {
|
||||
t.Fatalf("unexpected linux webkit41 asset name: got %q want %q", assetName, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildLinuxScriptPrefersTargetExecutableBasename(t *testing.T) {
|
||||
script := buildLinuxScript(
|
||||
"/tmp/GoNavi-0.6.5-Linux-Amd64-WebKit41.tar.gz",
|
||||
"/opt/GoNavi/gonavi-build-linux-amd64-webkit41",
|
||||
"/tmp/.gonavi-update-linux-0.6.5",
|
||||
12345,
|
||||
)
|
||||
|
||||
mustContain := []string{
|
||||
`TARGET_NAME="$(basename "$TARGET")"`,
|
||||
`NEWBIN="$TMPDIR/$TARGET_NAME"`,
|
||||
`NEWBIN=$(find "$TMPDIR" -type f -name "$TARGET_NAME" | head -n 1)`,
|
||||
`NEWBIN=$(find "$TMPDIR" -type f -name "GoNavi" | head -n 1)`,
|
||||
}
|
||||
for _, want := range mustContain {
|
||||
if !strings.Contains(script, want) {
|
||||
t.Fatalf("linux update script missing required token: %s\nscript:\n%s", want, script)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user