...
1
16
17 package mage
18
19 import (
20 "fmt"
21 "runtime"
22
23 "github.com/uwu-tools/magex/pkg"
24 "github.com/uwu-tools/magex/pkg/archive"
25 "github.com/uwu-tools/magex/pkg/downloads"
26 )
27
28 const defaultKoVersion = "0.15.0"
29
30
31 func EnsureKO(version string) error {
32 if version == "" {
33 version = defaultKoVersion
34 }
35
36 fmt.Printf("Checking if `ko` version %s is installed\n", version)
37 found, err := pkg.IsCommandAvailable("ko", "version", version)
38 if err != nil {
39 return err
40 }
41
42 if !found {
43 fmt.Println("`ko` not found")
44 return InstallKO(version)
45 }
46
47 fmt.Println("`ko` is installed!")
48 return nil
49 }
50
51
52 func InstallKO(version string) error {
53 fmt.Println("Will install `ko`")
54 target := "ko"
55 if runtime.GOOS == "windows" {
56 target = "ko.exe"
57 }
58
59 opts := archive.DownloadArchiveOptions{
60 DownloadOptions: downloads.DownloadOptions{
61 UrlTemplate: "https://github.com/ko-build/ko/releases/download/v{{.VERSION}}/ko_{{.VERSION}}_{{.GOOS}}_{{.GOARCH}}{{.EXT}}",
62 Name: "ko",
63 Version: version,
64 OsReplacement: map[string]string{
65 "darwin": "Darwin",
66 "linux": "Linux",
67 "windows": "Windows",
68 },
69 ArchReplacement: map[string]string{
70 "amd64": "x86_64",
71 },
72 },
73 ArchiveExtensions: map[string]string{
74 "linux": ".tar.gz",
75 "darwin": ".tar.gz",
76 "windows": ".tar.gz",
77 },
78 TargetFileTemplate: target,
79 }
80
81 return archive.DownloadToGopathBin(opts)
82 }
83
View as plain text