Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
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
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