Skip to content

Commit

Permalink
ci: bump mage-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Voltaire authored and viktorvoltaire committed Jan 20, 2022
1 parent 1db579b commit bb6c911
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .mage/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
require (
github.com/go-logr/logr v1.2.2
github.com/magefile/mage v1.12.1
go.einride.tech/mage-tools v0.28.0
go.einride.tech/mage-tools v0.29.1
)

require (
Expand Down
4 changes: 2 additions & 2 deletions .mage/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHL
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/magefile/mage v1.12.1 h1:oGdAbhIUd6iKamKlDGVtU6XGdy5SgNuCWn7gCTgHDtU=
github.com/magefile/mage v1.12.1/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
go.einride.tech/mage-tools v0.28.0 h1:RSCd3tN6WrtSuudwmqiAzjCKfuTpLtE7bLKqTyuMOMU=
go.einride.tech/mage-tools v0.28.0/go.mod h1:pFpCBZ0U7a6862mks4y6v5xBkT4IhdrcJdEeTEjweMI=
go.einride.tech/mage-tools v0.29.1 h1:kWSsuDZdqka85X/3gPQTfk9KejC59Yua6j2ahT9Z8ZQ=
go.einride.tech/mage-tools v0.29.1/go.mod h1:pFpCBZ0U7a6862mks4y6v5xBkT4IhdrcJdEeTEjweMI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
Expand Down
91 changes: 53 additions & 38 deletions .mage/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,19 @@ import (

"github.com/go-logr/logr"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/magefile/mage/target"
"go.einride.tech/mage-tools/mglog"
"go.einride.tech/mage-tools/mgmake"
"go.einride.tech/mage-tools/mgpath"
"go.einride.tech/mage-tools/mgtool"
"go.einride.tech/mage-tools/targets/mgbuf"
"go.einride.tech/mage-tools/targets/mgyamlfmt"

// mage:import
"go.einride.tech/mage-tools/targets/mggo"

// mage:import
"go.einride.tech/mage-tools/targets/mggolangcilint"

// mage:import
"go.einride.tech/mage-tools/targets/mggoreview"

// mage:import
"go.einride.tech/mage-tools/targets/mgmarkdownfmt"

// mage:import
"go.einride.tech/mage-tools/targets/mgconvco"

// mage:import
"go.einride.tech/mage-tools/targets/mggitverifynodiff"
"go.einride.tech/mage-tools/targets/mgyamlfmt"
"go.einride.tech/mage-tools/tools/mgbuf"
"go.einride.tech/mage-tools/tools/mgconvco"
"go.einride.tech/mage-tools/tools/mggo"
"go.einride.tech/mage-tools/tools/mggolangcilint"
"go.einride.tech/mage-tools/tools/mggoreview"
"go.einride.tech/mage-tools/tools/mgmarkdownfmt"
)

func init() {
Expand All @@ -55,37 +42,64 @@ func init() {

func All() {
mg.Deps(
mg.F(mgconvco.ConvcoCheck, "origin/master..HEAD"),
mgmarkdownfmt.FormatMarkdown,
mgyamlfmt.FormatYaml,
ConvcoCheck,
FormatMarkdown,
mgyamlfmt.FormatYAML,
GoStringer,
Proto.All,
)
mg.Deps(
mggolangcilint.GolangciLint,
mggoreview.Goreview,
mggo.GoTest,
GolangciLint,
Goreview,
GoTest,
)
mg.SerialDeps(
mggo.GoModTidy,
GoModTidy,
mggitverifynodiff.GitVerifyNoDiff,
)
}

func ConvcoCheck(ctx context.Context) error {
mglog.Logger("convco-check").Info("checking...")
return mgconvco.Command(ctx, "check", "origin/master..HEAD").Run()
}

func FormatMarkdown(ctx context.Context) error {
mglog.Logger("format-markdown").Info("formatting..")
return mgmarkdownfmt.Command(ctx, "-w", ".").Run()
}

func GolangciLint(ctx context.Context) error {
mglog.Logger("golangci-lint").Info("running...")
return mggolangcilint.LintCommand(ctx).Run()
}

func Goreview(ctx context.Context) error {
mglog.Logger("goreview").Info("running...")
return mggoreview.Command(ctx, "-c", "1", "./...").Run()
}

func GoModTidy() error {
mglog.Logger("go-mod-tidy").Info("tidying Go module files...")
return mggo.GoModTidy().Run()
}

func GoTest() error {
mglog.Logger("go-test").Info("running Go unit tests..")
return mggo.GoTest().Run()
}

func ProtocGenGoAip() error {
logger := mglog.Logger("protoc-gen-go-aip")
logger.Info("building binary...")
return sh.Run("go", "build", "-o", "build/protoc-gen-go-aip", "./cmd/protoc-gen-go-aip")
mglog.Logger("protoc-gen-go-aip").Info("building binary...")
return mgtool.Command("go", "build", "-o", "build/protoc-gen-go-aip", "./cmd/protoc-gen-go-aip").Run()
}

func BufGenerateTestdata(ctx context.Context) error {
logger := mglog.Logger("buf")
ctx = logr.NewContext(ctx, logger)
mg.SerialDeps(ProtocGenGoAip)
logger.Info("generating testdata stubs...")
cleanup := mgpath.ChangeWorkDir("cmd/protoc-gen-go-aip/internal/genaip/testdata")
defer cleanup()
return mgbuf.Buf(ctx, "generate", "--path", "test")
cmd := mgbuf.Command(ctx, "generate", "--path", "test")
cmd.Dir = mgpath.FromGitRoot("cmd/protoc-gen-go-aip/internal/genaip/testdata")
mglog.Logger("buf").Info("generating testdata stubs...")
return cmd.Run()
}

func GoStringer(ctx context.Context) error {
Expand All @@ -105,8 +119,9 @@ func GoStringer(ctx context.Context) error {
if generate {
logger.Info("generating", "src", methodType, "dst", methodTypeString)
path := fmt.Sprintf("%s:%s", os.Getenv("PATH"), filepath.Dir(goStringer))
err = sh.RunWith(map[string]string{"PATH": path}, "go", "generate", methodType)
if err != nil {
cmd := mgtool.Command("go", "generate", methodType)
cmd.Env = append(cmd.Env, "PATH="+path)
if err := cmd.Run(); err != nil {
return err
}
}
Expand Down
72 changes: 43 additions & 29 deletions .mage/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,39 @@ import (
"os"
"path/filepath"

"github.com/go-logr/logr"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/magefile/mage/target"
"go.einride.tech/mage-tools/mglog"
"go.einride.tech/mage-tools/mgpath"
"go.einride.tech/mage-tools/mgtool"
"go.einride.tech/mage-tools/targets/mgapilinter"
"go.einride.tech/mage-tools/targets/mgbuf"

// mage:import proto
"go.einride.tech/mage-tools/targets/mgclangformat"
"go.einride.tech/mage-tools/tools/mgapilinter"
"go.einride.tech/mage-tools/tools/mgbuf"
"go.einride.tech/mage-tools/tools/mgclangformat"
)

type Proto mg.Namespace

func (Proto) All() {
cleanup := mgpath.ChangeWorkDir(mgpath.FromGitRoot("proto"))
defer cleanup()
mg.SerialDeps(
mg.F(mgclangformat.ClangFormatProto, "einride"),
Proto.ClangFormatProto,
Proto.BufLint,
Proto.ApiLinterLint,
Proto.BufGenerate,
)
}

func (Proto) BufLint() {
mg.Deps(mgbuf.BufLint)
var protoDir = mgpath.FromGitRoot("proto")

func (Proto) BufLint(ctx context.Context) error {
cmd := mgbuf.Command(ctx, "lint")
cmd.Dir = protoDir
return cmd.Run()
}

func (Proto) ClangFormatProto() error {
cmd := mgclangformat.FormatProtoCommand(filepath.Join(protoDir, "einride"))
cmd.Dir = protoDir
return cmd.Run()
}

func (Proto) ProtocGenGo(ctx context.Context) error {
Expand All @@ -49,9 +53,16 @@ func (Proto) ProtocGenGo(ctx context.Context) error {
}

func (Proto) ProtocGenGoAip() error {
logger := mglog.Logger("protoc-gen-go-aip")
logger.Info("building binary...")
return sh.Run("go", "build", "-o", filepath.Join(mgpath.Bins(), "protoc-gen-go-aip"), "../cmd/protoc-gen-go-aip")
cmd := mgtool.Command(
"go",
"build",
"-o",
filepath.Join(mgpath.Bins(), "protoc-gen-go-aip"),
"../cmd/protoc-gen-go-aip",
)
cmd.Dir = protoDir
mglog.Logger("protoc-gen-go-aip").Info("building binary...")
return cmd.Run()
}

func (Proto) ProtocGenGoGrpc(ctx context.Context) error {
Expand All @@ -60,45 +71,48 @@ func (Proto) ProtocGenGoGrpc(ctx context.Context) error {
}

func (Proto) BufGenerate(ctx context.Context) error {
logger := mglog.Logger("buf-generate")
ctx = logr.NewContext(ctx, logger)
mg.Deps(
Proto.ProtocGenGo,
Proto.ProtocGenGoGrpc,
Proto.ProtocGenGoAip,
)
logger.Info("generating protobuf stubs...")
return mgbuf.Buf(ctx, "generate", "--template", "buf.gen.yaml", "--path", "einride")
cmd := mgbuf.Command(ctx, "generate", "--template", "buf.gen.yaml", "--path", "einride")
cmd.Dir = protoDir
mglog.Logger("buf-generate").Info("generating protobuf stubs...")
return cmd.Run()
}

func (Proto) BuildDescriptor(ctx context.Context) error {
logger := mglog.Logger("build/descriptor.pb")
ctx = logr.NewContext(ctx, logger)
protoFiles, err := mgpath.FindFilesWithExtension("einride", ".proto")
protoFiles, err := mgpath.FindFilesWithExtension(filepath.Join(protoDir, "einride"), ".proto")
if err != nil {
return err
}
newer, err := target.Glob("build/descriptor.pb", protoFiles...)
newer, err := target.Glob(filepath.Join(protoDir, "build/descriptor.pb"), protoFiles...)
if err != nil {
return err
}
if !newer {
return nil
}
if err := os.MkdirAll("build", 0o755); err != nil {
if err := os.MkdirAll(filepath.Join(protoDir, "build"), 0o755); err != nil {
return err
}
logger.Info("generating proto descriptor...")
return mgbuf.Buf(ctx, "build", "-o", "build/descriptor.pb")
cmd := mgbuf.Command(ctx, "build", "-o", "build/descriptor.pb")
cmd.Dir = protoDir
mglog.Logger("build/descriptor.pb").Info("generating proto descriptor...")
return cmd.Run()
}

func (Proto) ApiLinterLint(ctx context.Context) error {
protoFiles, err := mgpath.FindFilesWithExtension("einride/example/freight", ".proto")
protoFiles, err := mgpath.FindFilesWithExtension(filepath.Join(protoDir, "einride/example/freight"), ".proto")
if err != nil {
return err
}
mg.CtxDeps(ctx, Proto.BuildDescriptor)
mg.Deps(Proto.BuildDescriptor)
args := []string{"--set-exit-status", "--config", "api-linter.yaml", "--descriptor-set-in", "build/descriptor.pb"}
args = append(args, protoFiles...)
return mgapilinter.APILinterLint(ctx, args...)
cmd := mgapilinter.Command(ctx, args...)
cmd.Dir = protoDir
mglog.Logger("api-linter-lint").Info("linting gRPC APIs...")
return cmd.Run()
}
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@ buf-generate-testdata: $(magefile)

.PHONY: convco-check
convco-check: $(magefile)
ifndef rev
$(error missing argument rev="...")
endif
@$(magefile) convcoCheck $(rev)
@$(magefile) convcoCheck

.PHONY: format-markdown
format-markdown: $(magefile)
@$(magefile) formatMarkdown

.PHONY: git-verify-no-diff
git-verify-no-diff: $(magefile)
@$(magefile) gitVerifyNoDiff

.PHONY: go-mod-tidy
go-mod-tidy: $(magefile)
@$(magefile) goModTidy
Expand Down
5 changes: 1 addition & 4 deletions proto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ build-descriptor: $(magefile)

.PHONY: clang-format-proto
clang-format-proto: $(magefile)
ifndef path
$(error missing argument path="...")
endif
@$(magefile) proto:clangFormatProto $(path)
@$(magefile) proto:clangFormatProto

.PHONY: protoc-gen-go
protoc-gen-go: $(magefile)
Expand Down

0 comments on commit bb6c911

Please sign in to comment.