Skip to content

sheldonhull/magetools

Repository files navigation

magetools

Codecov

General tooling helpers for simplifying cross-repository automation using Mage.

The test coverage shown is informal, as these aren't setup always with full standard tests. Primarily the tests just import and run to confirm no errors. When possible, I do test the functionality.

Mage is a good case of a little magic making things faster and easier to adopt, while making it a bit trickier to test functions IMO.

Getting Bootstrapped On A New Repo

Jump start a new repo with the GitHub - sheldonhull/scripts-to-rule-them-all-go

Other Go Focused Tools for Task Automation

Worth an honorable mention is Goyek which has a similar goal to Mage, but approaches with less magic and a similar design to writing tests. I opted not to use after a few months of working with it due to the alpha level changes occuring in project, and more effort required on adding tasks and remote imports[remote-imports-with-goyek].

If you don't have any desire to use remote imports, then Goyek can be a good option if you want to write in a style like Go testing.

Lastly, another worthy mention is Gosh.

Remote Packages

How to Use Importing

Mage

Install with Go 1.16+

go install github.com/magefile/mage@latest

Mage-Select

Nice little interactive prompt.

Alias: mage-select as mages

go install github.com/iwittkau/mage-select@latest

Getting Started With Mage

I need a way to bootstrap projects quickly with some tasks, so these directories give two different templates.

  1. simple-single-file: The simpliest for small projects, contains all tasks in single file.
  2. root-imports-with-tasks-in-subdirectory: Organized for normal projects, this provides a zero-install run (using go run mage.go taskname) and also organizes tasks into subdirectory. This allows the root of the project to remain clean. Tasks can then be easily split into files in the tasks directory such as: mage.git.go, mage.js.go, etc.

Why [dot] prefix in directory?

Go commands that run like go test ./... automatically ignore dot or underscore prefixed files.

I prefer to the dot prefix and underscore isn't very common from what I've observed in the Go echo system.

Tip

Include mage_output_file.go in your gitignore file to avoid it causing consternation in your git diff monitoring tooling.

Examples

The examples directory contains random mage examples I've used that don't fit yet into a package, or I haven't had the need to add any tests to reuse this in multiple places.

How To Use

// mage:import
_ "github.com/sheldonhull/magetools/ci"

Namespaced

// mage:import ci
"github.com/sheldonhull/magetools/ci"

Update

Quickly refresh library by running this on caller. This should bypass the cached public version and call directly to quickly update if the cached go pkg version isn't registering an update.

GOPRIVATE=github.com/sheldonhull/* go get -u
GOPRIVATE=github.com/sheldonhull/* go get -u github.com/sheldonhull/magetools/gotools@latest
$ENV:GOPRIVATE='github.com/sheldonhull/*'

Allow Zero Install Run

From the Mage Docs. Run this using: go run main.go and it should work just like using mage directly.

About

General tooling helpers for simplifying cross repository automation using Mage

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages