magetools

package module
v0.46.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2022 License: MIT Imports: 0 Imported by: 0

README

Mage-tools

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

Release

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,
)

Documentation

Overview

Package magetools provides utilities and mage targets for building Go projects.

Directories

Path Synopsis
cmd
Package mgtool provides primitives for downloading and invoking tools.
Package mgtool provides primitives for downloading and invoking tools.
tools
mghadolint
Package mghadolint is a Dockerfile linter that you can employ to check for Dockerfile best practices and common mistakes.
Package mghadolint is a Dockerfile linter that you can employ to check for Dockerfile best practices and common mistakes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL