Skip to content

Commit 0a217af

Browse files
authored
Add 386 architecture mappings and GitHub Proxy support (#51)
* Supports direct download assets through GitHub Proxy * Add support for 386 architecture
1 parent eb95222 commit 0a217af

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

arch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func getAdditionalArch(arch string, goarm uint8, universalArch string) []string
2727
if arch == "amd64" {
2828
additionalArch = append(additionalArch, "x86_64")
2929
}
30+
if arch == "386" {
31+
additionalArch = append(additionalArch, "i386", "x86", "x86_32")
32+
}
3033
if universalArch != "" {
3134
additionalArch = append(additionalArch, universalArch)
3235
}

arch_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func TestAdditionalArch(t *testing.T) {
2323
{"arm", 4, "", []string{"arm"}}, // go is not supporting below armv5
2424
{"amd64", 0, "", []string{"amd64", "x86_64"}},
2525
{"amd64", 0, "all", []string{"amd64", "x86_64", "all"}},
26+
{"386", 0, "", []string{"386", "i386", "x86", "x86_32"}},
27+
{"386", 0, "all", []string{"386", "i386", "x86", "x86_32", "all"}},
2628
}
2729

2830
for _, testItem := range testData {

github_source.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"net/http"
88
"os"
9+
"strings"
910

1011
"github.com/google/go-github/v74/github"
1112
"golang.org/x/oauth2"
@@ -93,6 +94,42 @@ func (s *GitHubSource) DownloadReleaseAsset(ctx context.Context, rel *Release, a
9394
if rel == nil {
9495
return nil, ErrInvalidRelease
9596
}
97+
// Check if the AssetURL contains more than one "https://"
98+
useGithubProxy := strings.Count(rel.AssetURL, "https://") > 1
99+
// If the AssetURL contains more than 2 "https://", it means it's using a GitHub Proxy service.
100+
// In this case, we should download the asset directly from the AssetURL instead of using the GitHub API.
101+
// This is a workaround for the issue that the GitHub API does not support downloading assets from GitHub Proxy services.
102+
if useGithubProxy {
103+
// Determine download url based on asset id.
104+
var downloadUrl string
105+
if rel.AssetID == assetID {
106+
downloadUrl = rel.AssetURL
107+
} else if rel.ValidationAssetID == assetID {
108+
downloadUrl = rel.ValidationAssetURL
109+
}
110+
if downloadUrl == "" {
111+
return nil, fmt.Errorf("asset ID %d: %w", assetID, ErrAssetNotFound)
112+
}
113+
// Download the asset directly from the AssetURL
114+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadUrl, http.NoBody)
115+
if err != nil {
116+
return nil, fmt.Errorf("failed to create download request:%w", err)
117+
}
118+
119+
resp, err := http.DefaultClient.Do(req)
120+
if err != nil {
121+
return nil, fmt.Errorf("download failed:%w", err)
122+
}
123+
124+
// The caller is responsible for closing resp.Body
125+
if resp.StatusCode != http.StatusOK {
126+
defer resp.Body.Close()
127+
return nil, fmt.Errorf("download failed, status code:%d", resp.StatusCode)
128+
}
129+
130+
return resp.Body, nil
131+
}
132+
// continue with the normal GitHub API download
96133
owner, repo, err := rel.repository.GetSlug()
97134
if err != nil {
98135
return nil, err

0 commit comments

Comments
 (0)