...
1
16
17 package mage
18
19 import (
20 "fmt"
21 "log"
22 "runtime"
23
24 "github.com/uwu-tools/magex/pkg"
25 "github.com/uwu-tools/magex/pkg/downloads"
26 )
27
28 const defaultCosignVersion = "v2.2.0"
29
30
31 func EnsureCosign(version string) error {
32 if version == "" {
33 version = defaultCosignVersion
34 }
35
36 log.Printf("Checking if `cosign` version %s is installed\n", version)
37 found, err := pkg.IsCommandAvailable("cosign", "version", version)
38 if err != nil {
39 return err
40 }
41
42 if !found {
43 fmt.Println("`cosign` not found")
44 return InstallCosign(version)
45 }
46
47 fmt.Println("`cosign` is installed!")
48 return nil
49 }
50
51
52 func InstallCosign(version string) error {
53 fmt.Println("Will install `cosign`")
54 target := "cosign"
55 if runtime.GOOS == "windows" {
56 target = "cosign.exe"
57 }
58
59 opts := downloads.DownloadOptions{
60 UrlTemplate: "https://github.com/sigstore/cosign/releases/download/{{.VERSION}}/cosign-{{.GOOS}}-{{.GOARCH}}",
61 Name: target,
62 Version: version,
63 Ext: "",
64 }
65
66 return downloads.DownloadToGopathBin(opts)
67 }
68
View as plain text