gobake is a Go-native build orchestrator. It allows you to write your build logic in Go, benefiting from type safety, autocomplete, and the full power of the Go standard library, without needing a separate build language like Make or CMake.
go install github.com/fezcode/gobake/cmd/gobake@latestA typical gobake project looks like this:
my-project/
├── go.mod
├── main.go
├── recipe.piml <-- Metadata (Version, Tools, Name)
└── Recipe.go <-- Build Logic
This file acts as the "Manifest" for your project. It stores metadata that doesn't belong in code.
(name) my-app
(version) 1.0.0
(description) A sample application
(authors)
> John Doe
(license) MIT
(tools)
> golang.org/x/tools/cmd/stringer@latest
> github.com/golangci/golangci-lint/cmd/golangci-lint@latest
This is where you define your tasks.
//go:build gobake
package bake_recipe
import "github.com/fezcode/gobake"
func Run(bake *gobake.Engine) error {
if err := bake.LoadRecipeInfo("recipe.piml"); err != nil {
return err
}
bake.Task("build", "Build the binary", func(ctx *gobake.Context) error {
return ctx.Run("go", "build", "-o", "bin/app", ".")
})
return nil
}You might wonder about //go:build gobake and package bake_recipe. Here is what happens under the hood when you run gobake build:
- Isolation: The
//go:build gobakebuild tag tells the standard Go compiler (when you rungo buildon your project) to ignore this file. This prevents your build logic from being compiled into your actual application binary. - Package Separation: The file uses
package bake_recipeto keep it in a separate namespace from your project'smainpackage. - Generation & Execution:
gobakereads yourRecipe.go.- It creates a hidden temporary directory
.gobake/. - It copies your code there, changes the package to
main, and removes the build tag. - It generates a small runner file that initializes the
gobake.Engine, calls yourRun()function, and executes the requested task. - Finally, it executes this generated program using
go run.
This process allows you to write "script-like" Go code that is fully compiled and type-checked on the fly.
gobake init: Scaffolds a new project.- Creates
recipe.pimlandRecipe.go. - Runs
go mod init(if missing) andgo mod tidy. - Adds
github.com/fezcode/gobakeas a dependency.
- Creates
gobake template <git-url>: Clones a git repo and initializes it as a gobake project.
gobake add-tool <url>: Adds a Go tool torecipe.piml(e.g.,gobake add-tool github.com/swaggo/swag/cmd/swag@latest).gobake remove-tool <url>: Removes a tool.gobake add-dep <url>: Adds a library dependency (go get).gobake remove-dep <url>: Removes a library dependency.
gobake bump [patch|minor|major]: Automatically increments the version inrecipe.piml.patch: 1.0.0 -> 1.0.1minor: 1.0.1 -> 1.1.0major: 1.1.0 -> 2.0.0
gobake <task>: Runs a single defined task.gobake <task1> <task2> ...: Runs multiple tasks in the order given. Each leading argument that matches a registered task name is executed; the first non-task argument (and everything after) is passed to the last task asctx.Args.gobake test build→ runstest, thenbuild.gobake build foo.txt→ runsbuildwithctx.Args = ["foo.txt"].gobake test build x y→ runstest, thenbuildwithctx.Args = ["x", "y"].
gobake help: Lists all available commands AND the tasks defined in yourRecipe.go(alphabetically sorted).gobake version: Shows the gobake CLI version.