Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions arch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions cmd/detect-latest-release/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/detect-latest-release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion cmd/detect-latest-release/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/get-release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/get-release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 37 additions & 0 deletions github_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/http"
"os"
"strings"

"github.com/google/go-github/v74/github"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/creativeprojects/go-selfupdate
module github.com/sinspired/go-selfupdate

go 1.24.7

Expand Down
2 changes: 1 addition & 1 deletion internal/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion path.go
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion update/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"path/filepath"

"github.com/creativeprojects/go-selfupdate/internal"
"github.com/sinspired/go-selfupdate/internal"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions update/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(`
Expand Down
2 changes: 1 addition & 1 deletion update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down