forked from ava-labs/avalanche-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.go
124 lines (105 loc) · 3.02 KB
/
github.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package binutils
import (
"fmt"
"github.com/ava-labs/avalanche-cli/pkg/constants"
)
const (
linux = "linux"
darwin = "darwin"
windows = "windows"
zipExtension = "zip"
tarExtension = "tar.gz"
)
type GithubDownloader interface {
GetDownloadURL(version string, installer Installer) (string, string, error)
}
type (
subnetEVMDownloader struct{}
avalancheGoDownloader struct{}
)
var (
_ GithubDownloader = (*subnetEVMDownloader)(nil)
_ GithubDownloader = (*avalancheGoDownloader)(nil)
)
func GetGithubLatestReleaseURL(org, repo string) string {
return "https://api.github.com/repos/" + org + "/" + repo + "/releases/latest"
}
func NewAvagoDownloader() GithubDownloader {
return &avalancheGoDownloader{}
}
func (avalancheGoDownloader) GetDownloadURL(version string, installer Installer) (string, string, error) {
// NOTE: if any of the underlying URLs change (github changes, release file names, etc.) this fails
goarch, goos := installer.GetArch()
var avalanchegoURL string
var ext string
switch goos {
case linux:
avalanchegoURL = fmt.Sprintf(
"https://github.com/%s/%s/releases/download/%s/avalanchego-linux-%s-%s.tar.gz",
constants.AvaLabsOrg,
constants.AvalancheGoRepoName,
version,
goarch,
version,
)
ext = tarExtension
case darwin:
avalanchegoURL = fmt.Sprintf(
"https://github.com/%s/%s/releases/download/%s/avalanchego-macos-%s.zip",
constants.AvaLabsOrg,
constants.AvalancheGoRepoName,
version,
version,
)
ext = zipExtension
// EXPERIMENTAL WIN, no support
case windows:
avalanchegoURL = fmt.Sprintf(
"https://github.com/%s/%s/releases/download/%s/avalanchego-win-%s-experimental.zip",
constants.AvaLabsOrg,
constants.AvalancheGoRepoName,
version,
version,
)
ext = zipExtension
default:
return "", "", fmt.Errorf("OS not supported: %s", goos)
}
return avalanchegoURL, ext, nil
}
func NewSubnetEVMDownloader() GithubDownloader {
return &subnetEVMDownloader{}
}
func (subnetEVMDownloader) GetDownloadURL(version string, installer Installer) (string, string, error) {
// NOTE: if any of the underlying URLs change (github changes, release file names, etc.) this fails
goarch, goos := installer.GetArch()
var subnetEVMURL string
ext := tarExtension
switch goos {
case linux:
subnetEVMURL = fmt.Sprintf(
"https://github.com/%s/%s/releases/download/%s/%s_%s_linux_%s.tar.gz",
constants.AvaLabsOrg,
constants.SubnetEVMRepoName,
version,
constants.SubnetEVMRepoName,
version[1:], // WARN subnet-evm isn't consistent in its release naming, it's omitting the v in the file name...
goarch,
)
case darwin:
subnetEVMURL = fmt.Sprintf(
"https://github.com/%s/%s/releases/download/%s/%s_%s_darwin_%s.tar.gz",
constants.AvaLabsOrg,
constants.SubnetEVMRepoName,
version,
constants.SubnetEVMRepoName,
version[1:],
goarch,
)
default:
return "", "", fmt.Errorf("OS not supported: %s", goos)
}
return subnetEVMURL, ext, nil
}