feat(selfupgrade): when url empty, using GetTestReleaseAPIURL for test .
This commit is contained in:
parent
e93d7a01a7
commit
7813726ec8
1 changed files with 41 additions and 18 deletions
|
|
@ -119,7 +119,24 @@ func UpdateSelfFromRelease(releaseURL, platform, arch, programName string) error
|
||||||
// UpdateSelf updates the running executable by fetching the latest release
|
// UpdateSelf updates the running executable by fetching the latest release
|
||||||
// and applying the binary matching programName.
|
// and applying the binary matching programName.
|
||||||
func UpdateSelf(programName string) error {
|
func UpdateSelf(programName string) error {
|
||||||
return UpdateSelfFromRelease("", "", "", programName)
|
// Default to test repo for now. Use GetProdReleaseAPIURL() for production.
|
||||||
|
return UpdateSelfFromRelease(GetTestReleaseAPIURL(), runtime.GOOS, runtime.GOARCH, programName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetReleaseAPIURL returns the GitHub Releases API URL for the given repo owner.
|
||||||
|
// Example: owner="sky5454" -> https://api.github.com/repos/sky5454/picoclaw/releases/latest
|
||||||
|
func GetReleaseAPIURL(owner string) string {
|
||||||
|
return fmt.Sprintf("https://api.github.com/repos/%s/picoclaw/releases/latest", owner)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTestReleaseAPIURL returns the test release API URL (user fork).
|
||||||
|
func GetTestReleaseAPIURL() string {
|
||||||
|
return GetReleaseAPIURL("sky5454")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetProdReleaseAPIURL returns the production release API URL (upstream).
|
||||||
|
func GetProdReleaseAPIURL() string {
|
||||||
|
return GetReleaseAPIURL("sipeed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// findAssetURL resolves the appropriate asset URL for the given release
|
// findAssetURL resolves the appropriate asset URL for the given release
|
||||||
|
|
@ -132,7 +149,13 @@ func findAssetURL(releaseURL, platform, arch string) (string, error) {
|
||||||
|
|
||||||
apiURL := buildReleaseAPIURL(releaseURL)
|
apiURL := buildReleaseAPIURL(releaseURL)
|
||||||
if apiURL == "" {
|
if apiURL == "" {
|
||||||
apiURL = "https://api.github.com/repos/sipeed/picoclaw/releases/latest"
|
// If caller provided an empty releaseURL, default to test repo.
|
||||||
|
// Otherwise fall back to production repo API URL.
|
||||||
|
if strings.TrimSpace(releaseURL) == "" {
|
||||||
|
apiURL = GetTestReleaseAPIURL()
|
||||||
|
} else {
|
||||||
|
apiURL = GetProdReleaseAPIURL()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Get(apiURL)
|
resp, err := http.Get(apiURL)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue