nitter/build/generate.go
Peter Kurfer c1c1667d9f
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is passing
feat(gitea): add lint-pr command
lint-pr runs golangci-lint, captures the result and uses it directly without temporary files
It also allows to automatically retrieve the PRs base commit and run golangci-lint only against changes in the current PR
2023-03-09 12:15:35 +01:00

47 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", "./...")
}