Skip to content

Commit

Permalink
use the mage from release-utils
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Mar 27, 2023
1 parent d9f1f04 commit e70969c
Showing 1 changed file with 2 additions and 60 deletions.
62 changes: 2 additions & 60 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/carolynvs/magex/pkg"
"github.com/carolynvs/magex/pkg/archive"
"github.com/carolynvs/magex/pkg/downloads"
"github.com/magefile/mage/sh"

"sigs.k8s.io/release-utils/mage"
Expand Down Expand Up @@ -141,7 +138,7 @@ func BuildImages() error {
// BuildImagesLocal build images locally and not push
func BuildImagesLocal() error {
fmt.Println("Building image with ko for local test...")
if err := EnsureKO(""); err != nil {
if err := mage.EnsureKO("0.13.0"); err != nil {
return err
}

Expand All @@ -164,7 +161,7 @@ func BuildStaging() error {
return err
}

if err := EnsureKO(""); err != nil {
if err := mage.EnsureKO(""); err != nil {
return err
}

Expand Down Expand Up @@ -252,58 +249,3 @@ func getBuildDateTime() string {
date, _ := sh.Output("date", "+%Y-%m-%dT%H:%M:%SZ")
return date
}

// Maybe we can move this to release-utils
func EnsureKO(version string) error {
versionToInstall := version
if versionToInstall == "" {
versionToInstall = "0.13.0"
}

fmt.Printf("Checking if `ko` version %s is installed\n", versionToInstall)
found, err := pkg.IsCommandAvailable("ko", "version", versionToInstall)
if err != nil {
return err
}

if !found {
fmt.Println("`ko` not found")
return InstallKO(versionToInstall)
}

fmt.Println("`ko` is installed!")
return nil
}

// Maybe we can move this to release-utils
func InstallKO(version string) error {
fmt.Println("Will install `ko`")
target := "ko"
if runtime.GOOS == "windows" {
target = "ko.exe"
}

opts := archive.DownloadArchiveOptions{
DownloadOptions: downloads.DownloadOptions{
UrlTemplate: "https://github.com/google/ko/releases/download/v{{.VERSION}}/ko_{{.VERSION}}_{{.GOOS}}_{{.GOARCH}}{{.EXT}}",
Name: "ko",
Version: version,
OsReplacement: map[string]string{
"darwin": "Darwin",
"linux": "Linux",
"windows": "Windows",
},
ArchReplacement: map[string]string{
"amd64": "x86_64",
},
},
ArchiveExtensions: map[string]string{
"linux": ".tar.gz",
"darwin": ".tar.gz",
"windows": ".tar.gz",
},
TargetFileTemplate: target,
}

return archive.DownloadToGopathBin(opts)
}

0 comments on commit e70969c

Please sign in to comment.