nurse/magefiles/tools.go
Peter 59d2d26984
All checks were successful
concourse-ci/golangci-lint golangci-lint run
concourse-ci/gotestsum gotestsum
feat: add concourse pipeline
2022-12-30 21:41:30 +01:00

34 lines
788 B
Go

package main
import (
"fmt"
"os/exec"
"github.com/magefile/mage/sh"
"go.uber.org/zap"
)
var (
GoReleaser = sh.RunCmd("goreleaser")
GoInstall = sh.RunCmd("go", "install")
GoBuild = sh.RunCmd("go", "build")
)
func ensureGoTool(toolName, importPath, version string) error {
return checkForTool(toolName, func() error {
logger := zap.L()
toolToInstall := fmt.Sprintf("%s@%s", importPath, version)
logger.Info("Installing Go tool", zap.String("toolToInstall", toolToInstall))
return GoInstall(toolToInstall)
})
}
func checkForTool(toolName string, fallbackAction func() error) error {
logger := zap.L()
if _, err := exec.LookPath(toolName); err != nil {
logger.Warn("tool is missing", zap.String("toolName", toolName))
return fallbackAction()
}
return nil
}