A template for building GitHub CLI extensions in Go.
-
Create a new repo from this template:
gh repo create my-org/gh-my-extension --template maxbeizer/gh-extension-template --private --clone cd gh-my-extension -
Update these files:
go.mod— change the module path to your repoMakefile— changeEXTENSION_NAMEto your extension name (withoutgh-prefix).goreleaser.yml— changeproject_nameandbinarytogh-<your-name>main.go— changeUsefield and implement your commands
-
Verify everything works:
make ci make install-local gh my-extension
make help # see all targets
make build # build binary
make test # run tests
make ci # build + vet + test-race
make install-local # install extension from checkout
make relink-local # reinstall after changesTag a version to trigger a release build:
git tag v0.1.0
git push origin v0.1.0The GitHub Actions workflow uses goreleaser to build binaries for darwin/linux (amd64/arm64) and create a GitHub release. Once released, users install with:
gh extension install my-org/gh-my-extension| File | Purpose |
|---|---|
Makefile |
Build, test, lint, install targets |
.goreleaser.yml |
Cross-platform binary releases |
.github/workflows/release.yml |
Automated releases on tag push |
.github/workflows/ci.yml |
CI on push/PR to main |
main.go |
Minimal starter with cobra + signal handling |
.gitignore |
Go/editor/OS ignores |