All jobs

Add GoReleaser to a Cobra CLI

Yes. An agent adds GoReleaser and a release workflow on tags to your Cobra CLI, injects the version via ldflags, proves it with a snapshot build and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how the binary is built and versioned today before it adds a release pipeline. In a CLI like spf13/cobra-cli, main.go calls cmd.Execute(), and cmd/root.go defines rootCmd with Use: "cobra-cli", persistent flags for --config, --author, --license and --viper, and no Version field, so cobra-cli --version does not exist. go.mod is module github.com/spf13/cobra-cli on go 1.15 with cobra v1.6.1 and viper v1.12.0. The Makefile builds with gox for linux darwin and amd64 into bin/{{.Dir}}_{{.OS}}_{{.Arch}}, tests with richgo and lints with golangci-lint; .github/workflows/test.yml runs golangci-lint, a Go matrix on Ubuntu and macOS and an MSYS2 job on Windows; .gitignore already excludes bin. There is no release workflow, no dist ignore and no changelog config.

The change starts in the code: a cmd/version.go with package-level version, commit and date strings defaulting to dev, and rootCmd.Version = version in init, which makes Cobra add the --version flag and cobra-cli version output for free. Then .goreleaser.yaml at version: 2: one build with main: ., binary: cobra-cli, env: [CGO_ENABLED=0], goos of linux, darwin and windows, goarch of amd64 and arm64, ldflags of -s -w -X github.com/spf13/cobra-cli/cmd.version={{.Version}} -X github.com/spf13/cobra-cli/cmd.commit={{.Commit}} -X github.com/spf13/cobra-cli/cmd.date={{.Date}} and mod_timestamp: '{{ .CommitTimestamp }}' for reproducible archives; archives as tar.gz with a zip override for Windows and the LICENSE.txt and README.md included; a checksum file; and a changelog sorted ascending that excludes ^docs: and ^test: commits. dist/ joins .gitignore.

.github/workflows/release.yml triggers on push to tags matching v*, grants contents: write, checks out with fetch-depth: 0 so GoReleaser can read the previous tag for the changelog, sets up Go, and runs goreleaser/goreleaser-action with args: release --clean and GITHUB_TOKEN. The existing test.yml is untouched. The Makefile keeps its gox target so nothing a contributor runs today breaks, and gains a snapshot target that runs goreleaser release --snapshot --clean --skip=publish for the same artefacts locally; the description suggests retiring gox as a follow-up.

The proof is a snapshot release in the sandbox. The agent installs GoReleaser, runs goreleaser check on the config, then goreleaser release --snapshot --clean --skip=publish, lists dist/ to show one archive per platform and the checksums file, and runs dist/cobra-cli_linux_amd64_v1/cobra-cli --version to show the injected version string. go build ./... and go test ./... run as well, since the version file is new code. Every command and its output go into the pull request.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add GoReleaser to this Cobra CLI. Read main.go, cmd/root.go, go.mod, the Makefile and the GitHub workflows first. Add version, commit and date variables in the cmd package, set rootCmd.Version so --version works, and write a .goreleaser.yaml version 2 that builds a static binary for linux, darwin and windows on amd64 and arm64 with those variables injected through ldflags, reproducible timestamps, tar.gz archives with zip for Windows, a checksums file and a changelog that skips docs and test commits. Add a release workflow triggered by v* tags with contents write permission and a full-depth checkout, and add dist to .gitignore. Leave the existing test workflow and Makefile build target in place and add a snapshot target. Run goreleaser check and a snapshot release in the sandbox, list the artefacts, run the built binary with --version, run go build and go test, and include the output. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that adds .goreleaser.yaml, .github/workflows/release.yml and cmd/version.go, changes cmd/root.go (rootCmd.Version), .gitignore (dist/) and the Makefile (a snapshot target), and adds a release section to the README. The gox build, the tests and the lint workflow are unchanged.

The description quotes goreleaser check, the dist/ listing from the snapshot run with one archive per platform and the checksums file, the --version output showing the injected snapshot version, and the go build and go test results. The commands and full output are in the transcript at GET /o/{org}/sessions/{id}/messages.

Before merging, a reviewer decides on the first tag to cut, checks the platform list against what users actually download, and confirms the repository allows the workflow's contents: write permission. Pushing a v* tag after merge makes the first real release; a follow-up message to the same session can add a Homebrew tap or signing once the token for it exists.

Run it on every Go CLI repository without a release pipeline

A team with several Go CLIs starts one run per repository with one POST /o/{org}/sessions each, the repository in resources and this prompt as input. Each run reads its own main package path, module name and existing build flags, so a CLI whose version already lives in a version package gets the ldflags pointed there instead of a new file.

Send a request_id, a UUID v5 of the repository's full name, so a retried call returns the run it already started. The key's webhook_url reports when each run the key starts finishes, with the run's final answer in result.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A GoReleaser config is mostly names that have to agree: the module path in the ldflags, the binary name, the main package, the tag pattern in the workflow, the archive layout. The way to know they agree is a snapshot release, which the agent runs in a sandbox of its own and keeps the dist/ listing and the --version output as proof.

The pull request carries the config, the workflow and that output, so the review is about platforms and permissions rather than whether the first tag will build. Several CLIs can be done at once, each in its own sandbox with its own pull request and its own snapshot.

Frequently asked questions

Why add a version variable to the code?

GoReleaser injects values with -X only into variables that exist, and Cobra only shows --version when rootCmd.Version is set. The new cmd/version.go provides version, commit and date with a dev default so a plain go build still works, and the snapshot run proves the injection by printing the built binary's version.

Does the first release need a tag?

Yes. The workflow runs on pushes of tags matching v*, and GoReleaser reads the version from the tag. The snapshot in the sandbox uses a generated version to show the pipeline works without publishing anything; nothing is released until you push a tag.

What about Homebrew, Scoop or signing?

Each needs something outside the repository: a tap repository and a token, a bucket, or a signing key. The agent adds none by default and lists them in the description with the config block each would need, so you can request one in a follow-up once the credential exists.

Will it break the existing Makefile build?

No. The gox target stays as it is, and snapshot is added beside it. The description suggests replacing gox with goreleaser build later, since both now describe the same platforms, but that is a separate decision.

More Cobra jobs

The same job on other stacks

More jobs like this: Hand off a long task

Keep reading