Mage-tools is an opinionated set of mage targets to help with build automation of different projects

Requirements
Getting started
To initilize mage-tools in a repository, just run:
go run go.einride.tech/mage-tools/cmd/init@latest
Run make
Usage
Mage imports, and targets within the magefiles, can be written to Makefiles, you can generate as many Makefiles as you want, see more at Makefiles / Mage namespaces.
Magefiles
You can have as many magefiles as you want in the .mage
folder.
Targets
Any public function in the main package will be exported. Functions can have no return value but error. The following arguments are supported: Optional first argument of context.Context, string, int or bool.
func All() {
mg.Deps(
FormatYaml,
mg.F(ConvcoCheck, "origin/main..HEAD"),
)
}
func FormatYaml() error {
return mgyamlfmt.FormatYAML()
}
func ConvcoCheck(ctx context.Context, rev string) error {
mglog.Logger("convco-check").Info("checking...")
return mgconvco.Command(ctx, "check", rev).Run()
}
Makefiles / Mage namespaces
To generate makefiles, an init
method needs to exist in one of the magefiles where we call the mgmake.GenerateMakefiles
method.
func init() {
mgmake.GenerateMakefiles(
mgmake.Makefile{
Path: mgpath.FromGitRoot("Makefile"),
DefaultTarget: All,
},
)
}
If another makefile is desired, lets say one that only includes Terraform targets, we utilize the mg.Namespace
type and just add another Makefile
to the GenerateMakefiles
method and specify the namespace, path and default target.
func init() {
mgmake.GenerateMakefiles(
mgmake.Makefile{
Path: mgpath.FromGitRoot("Makefile"),
DefaultTarget: All,
},
mgmake.Makefile{
Path: mgpath.FromGitRoot("terraform/Makefile"),
Namespace: Terraform{},
},
)
}
type Terraform mg.Namespace
func (Terraform) TerraformInitDev() {
mg.SerialDeps(
Terraform.devConfig,
mgterraform.Init,
)
}
Dependencies
Dependencies can be defined just by specificing the function, or with mg.F
if the function takes arguments. Deps
runs in parallel while Serial
runs serially
mg.Deps(
mg.F(mgcommitlint.Commitlint, "main"),
mggolangcilint.GolangciLint,
mggoreview.Goreview,
)
mg.SerialDeps(
mggo.GoModTidy,
mggitverifynodiff.GitVerifyNoDiff,
)