Skip to content

Commit

Permalink
build(mage): ⏪ revert back to slog over fmt.Println
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed May 28, 2024
1 parent 7759eba commit 8a1d208
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
8 changes: 3 additions & 5 deletions build/magefiles/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main

import (
"errors"
"fmt"
"log/slog"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
Expand All @@ -19,7 +19,7 @@ var ErrBuildFailed = errors.New("build failed")

// Full runs all prep steps and then builds the binary.
func (Build) Full() error {
fmt.Println("Starting full build.")
slog.Info("Starting full build.")

// Make everything nice, neat, and proper
mg.Deps(Preps.Tidy)
Expand Down Expand Up @@ -62,8 +62,6 @@ func buildProject() error {

output := "dist/go-hass-agent-" + targetArch

fmt.Println("Running go build...")
fmt.Println("Output binary", output)
fmt.Println("Additional ldflags", ldflags)
slog.Info("Running go build...", "output", output, "ldflags", ldflags)
return sh.RunWithV(envMap, "go", "build", "-ldflags="+ldflags, "-o", output)
}
10 changes: 5 additions & 5 deletions build/magefiles/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package main

import (
"fmt"
"log/slog"
"os"

"github.com/magefile/mage/mg"
Expand All @@ -21,13 +21,13 @@ type Checks mg.Namespace

// Lint runs various static checkers to ensure you follow The Rules(tm).
func (Checks) Lint() error {
fmt.Println("Running linter (go vet)...")
slog.Info("Running linter (go vet)...")
if err := sh.RunV("golangci-lint", "run"); err != nil {
fmt.Println("WARN: linter had problems")
slog.Warn("Linter reported issues.", "error", err.Error())
}

if FoundOrInstalled("staticcheck", "honnef.co/go/tools/cmd/staticcheck@latest") {
fmt.Println("Running linter (staticcheck)...")
slog.Info("Running linter (staticcheck)...")
if err := sh.RunV("staticcheck", "-f", "stylish", "./..."); err != nil {
return err
}
Expand All @@ -38,7 +38,7 @@ func (Checks) Lint() error {

// Licenses pulls down any dependent project licenses, checking for "forbidden ones".
func (Checks) Licenses() error {
fmt.Println("Running go-licenses...")
slog.Info("Running go-licenses...")

// Make the directory for the license files
err := os.MkdirAll("licenses", os.ModePerm)
Expand Down
5 changes: 3 additions & 2 deletions build/magefiles/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
import (
"errors"
"fmt"
"log/slog"
"os"
"os/exec"
"runtime"
Expand Down Expand Up @@ -55,7 +56,7 @@ func SudoWrap(cmd string, args ...string) error {
func FoundOrInstalled(executableName, installURL string) (isInstalled bool) {
_, missing := exec.LookPath(executableName)
if missing != nil {
fmt.Println("Installing tool", executableName, "from url", installURL)
slog.Info("Installing tool.", "tool", executableName, "url", installURL)
err := sh.Run("go", "install", installURL)
if err != nil {
return false
Expand Down Expand Up @@ -144,7 +145,7 @@ func GenerateEnv() (map[string]string, error) {
targetArch = v
}
if targetArch != "" && targetArch != runtime.GOARCH {
fmt.Println("Cross compilation request from host arch", runtime.GOARCH, "to target arch", targetArch)
slog.Info("Cross compilation requested.", "host", runtime.GOARCH, "target", targetArch)

// Update NFPM_ARCH tro the target arch.
envMap["NFPM_ARCH"] = targetArch
Expand Down
5 changes: 3 additions & 2 deletions build/magefiles/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
import (
"errors"
"fmt"
"log/slog"
"slices"

"github.com/magefile/mage/mg"
Expand Down Expand Up @@ -38,7 +39,7 @@ func (Package) Nfpm() error {
}

for _, pkgformat := range pkgformats {
fmt.Println("Building package with nfpm in format:", pkgformat)
slog.Info("Building package with nfpm.", "format", pkgformat)
args := slices.Concat(nfpmBaseArgs, []string{"--packager", pkgformat})
if err := sh.RunWithV(envMap, "nfpm", args...); err != nil {
return err
Expand All @@ -54,7 +55,7 @@ func (Package) FyneCross() error {
}

if err := fyneCrossCmd("-arch", targetArch); err != nil {
fmt.Println("fyne-cross finished but with errors. Continuing anyway.", "Error was:", err.Error())
slog.Warn("fyne-cross finished but with errors. Continuing anyway.", "error", err.Error())
}
return sh.Copy(
"fyne-cross/dist/linux-"+targetArch+"/go-hass-agent-"+targetArch+".tar.xz",
Expand Down
7 changes: 4 additions & 3 deletions build/magefiles/preps.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"fmt"
"log/slog"
"os"
"runtime"

Expand All @@ -24,13 +25,13 @@ var generators = map[string]string{

// Tidy runs go mod tidy to update the go.mod and go.sum files.
func (Preps) Tidy() error {
fmt.Println("Running go mod tidy...")
slog.Info("Running go mod tidy...")
return sh.Run("go", "mod", "tidy")
}

// Format prettifies your code in a standard way to prevent arguments over curly braces.
func (Preps) Format() error {
fmt.Println("Running go fmt...")
slog.Info("Running go fmt...")
return sh.RunV("go", "fmt", "./...")
}

Expand All @@ -42,7 +43,7 @@ func (Preps) Generate() error {
}
}

fmt.Println("Running go generate...")
slog.Info("Running go generate...")
return sh.RunV("go", "generate", "-v", "./...")
}

Expand Down
5 changes: 3 additions & 2 deletions build/magefiles/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main

import (
"fmt"
"log/slog"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
Expand All @@ -21,13 +22,13 @@ func (Tests) Test() error {
return fmt.Errorf("cannot run test: %w", err)
}

fmt.Println("Running go test...")
slog.Info("Running go test...")
return sh.RunV("go", "test", "-ldflags="+ldflags, "-coverprofile=coverage.txt", "-v", "./...")
}

// Benchmark runs go test -bench on the project.
func (Tests) Benchmark() error {
fmt.Println("Running go test -bench...")
slog.Info("Running go test -bench...")
return sh.RunV("go", "test", "-bench=.", "./...")
}

Expand Down

0 comments on commit 8a1d208

Please sign in to comment.