48 lines
1,004 B
Go
48 lines
1,004 B
Go
|
//go:build mage
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/magefile/mage/mg"
|
||
|
"github.com/magefile/mage/sh"
|
||
|
"github.com/magefile/mage/target"
|
||
|
"golang.org/x/exp/slog"
|
||
|
)
|
||
|
|
||
|
func Generate(ctx context.Context) error {
|
||
|
mockeryVersion, err := getLatestReleaseTag(ctx, "vektra/mockery")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if err := ensureGoTool("mockery", "github.com/vektra/mockery/v2", mockeryVersion); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
mg.Deps(GenerateGo)
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func GenerateGo() error {
|
||
|
lastMockGeneration, err := target.NewestModTime(GeneratedMockFiles...)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
lastSourceModification, err := target.NewestModTime(GoSourceFiles...)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
slog.Debug("Determined last time mocks where generated", slog.Time("lastMockGeneration", lastMockGeneration))
|
||
|
|
||
|
if lastMockGeneration.After(lastSourceModification) {
|
||
|
slog.Info("Skipping unnecessary 'go generate' invocation")
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
return sh.RunV("go", "generate", "-x", "./...")
|
||
|
}
|