diff --git a/README.md b/README.md index d0276d7..f090cb5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ Self-Update library for Github, Gitea and Gitlab hosted applications in Go ============================================================== -[![Godoc reference](https://godoc.org/github.com/creativeprojects/go-selfupdate?status.svg)](http://godoc.org/github.com/creativeprojects/go-selfupdate) -[![Build](https://github.com/creativeprojects/go-selfupdate/workflows/Build/badge.svg)](https://github.com/creativeprojects/go-selfupdate/actions) +[![Godoc reference](https://godoc.org/github.com/sinspired/go-selfupdate?status.svg)](http://godoc.org/github.com/sinspired/go-selfupdate) +[![Build](https://github.com/sinspired/go-selfupdate/workflows/Build/badge.svg)](https://github.com/sinspired/go-selfupdate/actions) [![codecov](https://codecov.io/gh/creativeprojects/go-selfupdate/branch/main/graph/badge.svg?token=3FejM0fkw2)](https://codecov.io/gh/creativeprojects/go-selfupdate) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=creativeprojects_go-selfupdate&metric=bugs)](https://sonarcloud.io/summary/new_code?id=creativeprojects_go-selfupdate) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=creativeprojects_go-selfupdate&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=creativeprojects_go-selfupdate) diff --git a/arch.go b/arch.go index e4b1cf8..4f77f91 100644 --- a/arch.go +++ b/arch.go @@ -27,6 +27,9 @@ func getAdditionalArch(arch string, goarm uint8, universalArch string) []string if arch == "amd64" { additionalArch = append(additionalArch, "x86_64") } + if arch == "386" { + additionalArch = append(additionalArch, "i386", "x86", "x86_32") + } if universalArch != "" { additionalArch = append(additionalArch, universalArch) } diff --git a/arch_test.go b/arch_test.go index 8013b42..b68f87c 100644 --- a/arch_test.go +++ b/arch_test.go @@ -23,6 +23,8 @@ func TestAdditionalArch(t *testing.T) { {"arm", 4, "", []string{"arm"}}, // go is not supporting below armv5 {"amd64", 0, "", []string{"amd64", "x86_64"}}, {"amd64", 0, "all", []string{"amd64", "x86_64", "all"}}, + {"386", 0, "", []string{"386", "i386", "x86", "x86_32"}}, + {"386", 0, "all", []string{"386", "i386", "x86", "x86_32", "all"}}, } for _, testItem := range testData { diff --git a/cmd/detect-latest-release/README.md b/cmd/detect-latest-release/README.md index 578bf3c..587e151 100644 --- a/cmd/detect-latest-release/README.md +++ b/cmd/detect-latest-release/README.md @@ -1,9 +1,9 @@ -This command line tool is a small wrapper of [`selfupdate.DetectLatest()`](https://pkg.go.dev/github.com/creativeprojects/go-selfupdate/selfupdate#DetectLatest). +This command line tool is a small wrapper of [`selfupdate.DetectLatest()`](https://pkg.go.dev/github.com/sinspired/go-selfupdate/selfupdate#DetectLatest). Please install using `go get`. ``` -$ go get -u github.com/creativeprojects/go-selfupdate/cmd/detect-latest-release +$ go get -u github.com/sinspired/go-selfupdate/cmd/detect-latest-release ``` To know the usage, please try the command without any argument. @@ -12,7 +12,7 @@ To know the usage, please try the command without any argument. $ detect-latest-release ``` -For example, following shows the latest version of [resticprofile](https://github.com/creativeprojects/resticprofile). +For example, following shows the latest version of [resticprofile](https://github.com/sinspired/resticprofile). ``` $ detect-latest-release creativeprojects/resticprofile diff --git a/cmd/detect-latest-release/main.go b/cmd/detect-latest-release/main.go index 3dad50f..add7d1b 100644 --- a/cmd/detect-latest-release/main.go +++ b/cmd/detect-latest-release/main.go @@ -7,8 +7,8 @@ import ( "log" "os" - "github.com/creativeprojects/go-selfupdate" - "github.com/creativeprojects/go-selfupdate/cmd" + "github.com/sinspired/go-selfupdate" + "github.com/sinspired/go-selfupdate/cmd" ) const ( diff --git a/cmd/detect-latest-release/update.go b/cmd/detect-latest-release/update.go index e571d3f..d4859b8 100644 --- a/cmd/detect-latest-release/update.go +++ b/cmd/detect-latest-release/update.go @@ -6,7 +6,7 @@ import ( "log" "runtime" - "github.com/creativeprojects/go-selfupdate" + "github.com/sinspired/go-selfupdate" ) // keep this function here, this is the example from the README diff --git a/cmd/get-release/README.md b/cmd/get-release/README.md index feb66d2..f029a13 100644 --- a/cmd/get-release/README.md +++ b/cmd/get-release/README.md @@ -3,7 +3,7 @@ Download and install the latest release of any binary from GitHub. ## Installation ``` -$ go get -u github.com/creativeprojects/go-selfupdate/cmd/get-release +$ go get -u github.com/sinspired/go-selfupdate/cmd/get-release ``` ## Usage diff --git a/cmd/get-release/main.go b/cmd/get-release/main.go index e36b8a3..23a3387 100644 --- a/cmd/get-release/main.go +++ b/cmd/get-release/main.go @@ -13,8 +13,8 @@ import ( "runtime" "strings" - "github.com/creativeprojects/go-selfupdate" - "github.com/creativeprojects/go-selfupdate/cmd" + "github.com/sinspired/go-selfupdate" + "github.com/sinspired/go-selfupdate/cmd" ) func main() { diff --git a/cmd/source.go b/cmd/source.go index d9bfea4..1906631 100644 --- a/cmd/source.go +++ b/cmd/source.go @@ -5,7 +5,7 @@ import ( "net/url" "strings" - "github.com/creativeprojects/go-selfupdate" + "github.com/sinspired/go-selfupdate" ) // SplitDomainSlug tries to make sense of the repository string diff --git a/doc.go b/doc.go index 2b1cc6b..c1d36b8 100644 --- a/doc.go +++ b/doc.go @@ -15,16 +15,16 @@ If newer version than itself is detected, it downloads released binary from GitH There are some naming rules. Please read following links. Naming Rules of Released Binaries: - https://github.com/creativeprojects/go-selfupdate#naming-rules-of-released-binaries + https://github.com/sinspired/go-selfupdate#naming-rules-of-released-binaries Naming Rules of Git Tags: - https://github.com/creativeprojects/go-selfupdate#naming-rules-of-versions-git-tags + https://github.com/sinspired/go-selfupdate#naming-rules-of-versions-git-tags This package is hosted on GitHub: - https://github.com/creativeprojects/go-selfupdate + https://github.com/sinspired/go-selfupdate Small CLI tools as wrapper of this library are available also: - https://github.com/creativeprojects/go-selfupdate/cmd/detect-latest-release - https://github.com/creativeprojects/go-selfupdate/cmd/go-get-release + https://github.com/sinspired/go-selfupdate/cmd/detect-latest-release + https://github.com/sinspired/go-selfupdate/cmd/go-get-release */ package selfupdate diff --git a/github_source.go b/github_source.go index dcaf779..741894b 100644 --- a/github_source.go +++ b/github_source.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "os" + "strings" "github.com/google/go-github/v74/github" "golang.org/x/oauth2" @@ -93,6 +94,42 @@ func (s *GitHubSource) DownloadReleaseAsset(ctx context.Context, rel *Release, a if rel == nil { return nil, ErrInvalidRelease } + // Check if the AssetURL contains more than one "https://" + useGithubProxy := strings.Count(rel.AssetURL, "https://") > 1 + // If the AssetURL contains more than 2 "https://", it means it's using a GitHub Proxy service. + // In this case, we should download the asset directly from the AssetURL instead of using the GitHub API. + // This is a workaround for the issue that the GitHub API does not support downloading assets from GitHub Proxy services. + if useGithubProxy { + // Determine download url based on asset id. + var downloadUrl string + if rel.AssetID == assetID { + downloadUrl = rel.AssetURL + } else if rel.ValidationAssetID == assetID { + downloadUrl = rel.ValidationAssetURL + } + if downloadUrl == "" { + return nil, fmt.Errorf("asset ID %d: %w", assetID, ErrAssetNotFound) + } + // Download the asset directly from the AssetURL + req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadUrl, http.NoBody) + if err != nil { + return nil, fmt.Errorf("failed to create download request:%w", err) + } + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return nil, fmt.Errorf("download failed:%w", err) + } + + // The caller is responsible for closing resp.Body + if resp.StatusCode != http.StatusOK { + defer resp.Body.Close() + return nil, fmt.Errorf("download failed, status code:%d", resp.StatusCode) + } + + return resp.Body, nil + } + // continue with the normal GitHub API download owner, repo, err := rel.repository.GetSlug() if err != nil { return nil, err diff --git a/go.mod b/go.mod index 88a23a8..6682891 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/creativeprojects/go-selfupdate +module github.com/sinspired/go-selfupdate go 1.24.7 diff --git a/internal/path_test.go b/internal/path_test.go index 0b75e00..4f8ae99 100644 --- a/internal/path_test.go +++ b/internal/path_test.go @@ -3,7 +3,7 @@ package internal_test import ( "testing" - "github.com/creativeprojects/go-selfupdate/internal" + "github.com/sinspired/go-selfupdate/internal" "github.com/stretchr/testify/assert" ) diff --git a/path.go b/path.go index b7f0ae0..17dba55 100644 --- a/path.go +++ b/path.go @@ -1,6 +1,6 @@ package selfupdate -import "github.com/creativeprojects/go-selfupdate/internal" +import "github.com/sinspired/go-selfupdate/internal" func ExecutablePath() (string, error) { return internal.GetExecutablePath() diff --git a/update.go b/update.go index 2f1ce05..36f2d22 100644 --- a/update.go +++ b/update.go @@ -10,8 +10,8 @@ import ( "strings" "github.com/Masterminds/semver/v3" - "github.com/creativeprojects/go-selfupdate/internal" - "github.com/creativeprojects/go-selfupdate/update" + "github.com/sinspired/go-selfupdate/internal" + "github.com/sinspired/go-selfupdate/update" ) // UpdateTo downloads an executable from the source provider and replace current binary with the downloaded one. diff --git a/update/apply.go b/update/apply.go index ad03c53..d812ffb 100644 --- a/update/apply.go +++ b/update/apply.go @@ -9,7 +9,7 @@ import ( "os" "path/filepath" - "github.com/creativeprojects/go-selfupdate/internal" + "github.com/sinspired/go-selfupdate/internal" ) var ( diff --git a/update/doc.go b/update/doc.go index d1bc6c8..01a6320 100644 --- a/update/doc.go +++ b/update/doc.go @@ -9,7 +9,7 @@ This example shows how to update a program remotely from a URL. "fmt" "net/http" - "github.com/creativeprojects/go-selfupdate/update" + "github.com/sinspired/go-selfupdate/update" ) func doUpdate(url string) error { @@ -49,7 +49,7 @@ specified as a hex string. "encoding/hex" "io" - "github.com/creativeprojects/go-selfupdate/update" + "github.com/sinspired/go-selfupdate/update" ) func updateWithChecksum(binary io.Reader, hexChecksum string) error { @@ -85,7 +85,7 @@ with the private key and distribute the signature along with the update. "encoding/hex" "io" - "github.com/creativeprojects/go-selfupdate/update" + "github.com/sinspired/go-selfupdate/update" ) var publicKey = []byte(` diff --git a/update_test.go b/update_test.go index ccaca70..fe43d3a 100644 --- a/update_test.go +++ b/update_test.go @@ -190,7 +190,7 @@ func TestInvalidSlugForUpdate(t *testing.T) { } func TestInvalidAssetURL(t *testing.T) { - err := UpdateTo(context.Background(), "https://github.com/creativeprojects/non-existing-repo/releases/download/v1.2.3/foo.zip", "foo.zip", "foo") + err := UpdateTo(context.Background(), "https://github.com/sinspired/non-existing-repo/releases/download/v1.2.3/foo.zip", "foo.zip", "foo") assert.Error(t, err) assert.Contains(t, err.Error(), "failed to download a release file") } diff --git a/updater.go b/updater.go index f5d57ab..c827eff 100644 --- a/updater.go +++ b/updater.go @@ -5,7 +5,7 @@ import ( "regexp" "runtime" - "github.com/creativeprojects/go-selfupdate/internal" + "github.com/sinspired/go-selfupdate/internal" ) // Updater is responsible for managing the context of self-update.