Skip to content

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.

License

Notifications You must be signed in to change notification settings

sheldonhull/scripts-to-rule-them-all-go

Repository files navigation

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 add asdf:install to the init 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 like goreleaser or ko.
  • bump: Semantic versions
  • doctor: 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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks