Awesome
scripts-to-rule-them-all-go
Inspired from the 2015 repo for "Scripts to Rule Them All", this applies that same concept but with using a more modern toolchain like Go and Mage. Mage provides a Go based task runner that can replace makefiles, custom bash/python/powershell scripts, and instead provide a cross-platform common set of commands to run a project.
2022-03 ๐ง WIP - Bringing in a few more examples. It's ready to use for basics though!
Why Mage
- Mage is cross-platform.
- Mage is Go. Go is fun. Go helps write really robust safe code with the error handling.
- Easy to plug-in to CI since Mage is just Go.
Why This Template?
This project is a template to help bootstrap a new project with a few things that normally result in more setup work. I've tended to standardize on a few key things.
- If it's complicated and I do periodically, wrap up the bash script commands in Go instead if it's only a few minutes of work.
- If I can, I'll use a package, but for things that are more complicated (like Kubernetes), start with just wrapping up kubectl commands and go from there.
Normal tasks:
Included & Prebaked
- Aqua: install project tooling with aqua and run
aqua install
to get tools setup. init
: All projects bootstrap from this. It runs go mod tidy, go installs, and is extended for any other tools as well. For example, I'll addasdf:install
to theinit
task and let it also ensure all apps I want are setup.devcontainer:build
: Locally run the steps to grab the image and build a local containerized devcontainer to work in.
You Want More?
๐ Checkout magetools
I've been steadily baking automation tasks that are tested and reusable in there. Most of the tasks self-setup any tooling as well.
Custom
publish
: Focused on CI based publishing with a tool likegoreleaser
orko
.bump
: Semantic versionsdoctor
: Anytime a setup/problem in the project is experienced I try to add a diagnostic check on versions of apps, env vars, and other things and return this as a pass/fail or info table to summarize in a very clean way. This uses pterm.
Example Output
Running mage
in a brand new project.
โก Core Mage Tasks
Targets:
clean up after yourself.
gittools:init โ๏ธ Init runs all required steps to use this package.
go:doctor ๐ฅ Doctor will provide config details.
go:fix ๐ Run golangci-lint and apply any auto-fix.
go:fmt โจ Fmt runs gofumpt.
go:init โ๏ธ Init runs all required steps to use this package.
go:lint ๐ Run golangci-lint without fixing.
go:lintConfig ๐ฅ LintConfig will return output of golangci-lint config.
go:test ๐งช Run go test.
go:testSum ๐งช Run gotestsum (Params: Path just like you pass to go test, ie ./..., pkg/, etc ).
go:tidy ๐งน Tidy tidies.
go:wrap โจ Wrap runs golines powered by gofumpt.
init runs multiple tasks to initialize all the requirements for running a project for a new contributor.
precommit:commit ๐งช Commit runs pre-commit checks using pre-commit.
precommit:init โ๏ธ Init configures precommit hooks.
precommit:prepush ๐งช Push runs pre-push checks using pre-commit.
precommit:uninstall โ Uninstall removes the pre-commit hooks.
secrets:detect ๐ Detect scans for secret violations with gitleaks without git consideration.
secrets:protect ๐ Protect scans the staged artifacts for violations.
Template
You can use this as a template to get started with a project ready to run using Mage.
Setup
- Multiple options to install on Mage - Docs
- Additional options:
Using Go (won't have version info embedded)
go install github.com/magefile/mage@latest
Note
Optional: maintain //go:build mage
to avoid impacting test coverage reports.
I've added this to the tags for language server build to recognize so you can use code completion.