Skip to content

Commit

Permalink
doctl: Resolve versions based on GitHub releases
Browse files Browse the repository at this point in the history
Previously, doctl was pinned to a rather old release (1.56.0). Use the
`GitHubVersionStrategy` to find versions based on GH releases, and simplify URL
construction by providing a `BinaryTemplate` rather than a full `URLTemplate`,
since the binaries live at standard GitHub release paths.

While we're here, add support for doctl Linux ARM binaries since they are now
available.

Signed-off-by: Adam Wolfe Gordon <awg@xvx.ca>
  • Loading branch information
adamwg authored and alexellis committed Jun 5, 2024
1 parent f5bad4a commit 4ff0cf1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
5 changes: 2 additions & 3 deletions pkg/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ func Test_DownloadDigitalOcean(t *testing.T) {

tool := getTool(name, tools)

const toolVersion = "1.46.0"
const toolVersion = "v1.46.0"
const urlTemplate = "https://github.com/digitalocean/doctl/releases/download/v1.46.0/doctl-1.46.0-%s-%s.%s"

tests := []test{
Expand All @@ -1091,11 +1091,10 @@ func Test_DownloadDigitalOcean(t *testing.T) {
arch: arch64bit,
version: toolVersion,
url: fmt.Sprintf(urlTemplate, "darwin", "amd64", "tar.gz")},
// this asserts that we can build a URL for ARM processors, but no asset exists and will yield a 404
{os: "linux",
arch: archARM7,
version: toolVersion,
url: fmt.Sprintf(urlTemplate, "linux", "", "tar.gz")},
url: fmt.Sprintf(urlTemplate, "linux", "arm64", "tar.gz")},
}

for _, tc := range tests {
Expand Down
32 changes: 15 additions & 17 deletions pkg/get/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,34 +642,32 @@ https://github.com/inlets/inletsctl/releases/download/{{.Version}}/{{$fileName}}

tools = append(tools,
Tool{
Owner: "digitalocean",
Repo: "doctl",
Name: "doctl",
Version: "1.56.0",
Description: "Official command line interface for the DigitalOcean API.",
URLTemplate: `
{{$osStr := ""}}
Owner: "digitalocean",
Repo: "doctl",
Name: "doctl",
VersionStrategy: GitHubVersionStrategy,
Description: "Official command line interface for the DigitalOcean API.",
BinaryTemplate: `
{{$osStr := .OS}}
{{ if HasPrefix .OS "ming" -}}
{{$osStr = "windows"}}
{{- else if eq .OS "linux" -}}
{{$osStr = "linux"}}
{{- else if eq .OS "darwin" -}}
{{$osStr = "darwin"}}
{{- end -}}
{{$archStr := ""}}
{{$archStr := .Arch}}
{{- if eq .Arch "x86_64" -}}
{{$archStr = "amd64"}}
{{- else if eq .Arch "armv7l" }}
{{$archStr = "arm64"}}
{{- else if eq .Arch "aarch64" }}
{{$archStr = "arm64"}}
{{- end -}}
{{$archiveStr := ""}}
{{ if HasPrefix .OS "ming" -}}
{{$archiveStr := "tar.gz"}}
{{ if eq $osStr "windows" -}}
{{$archiveStr = "zip"}}
{{- else -}}
{{$archiveStr = "tar.gz"}}
{{- end -}}
https://github.com/digitalocean/doctl/releases/download/v{{.Version}}/doctl-{{.Version}}-{{$osStr}}-{{$archStr}}.{{$archiveStr}}`,
doctl-{{.VersionNumber}}-{{$osStr}}-{{$archStr}}.{{$archiveStr}}`,
})

tools = append(tools,
Expand Down

0 comments on commit 4ff0cf1

Please sign in to comment.