Build Releases with GoReleaser
Intermediate15 minTrending
Automate Go binary releases across platforms with GoReleaser, including changelogs, checksums, and GitHub releases.
Prerequisites
- -Go 1.21+ installed
- -GoReleaser installed
- -Git repository with tags
Steps
1
Install GoReleaser
Install GoReleaser using Go install or your package manager.
$ go install github.com/goreleaser/goreleaser/v2@latest
On macOS you can also use: brew install goreleaser
2
Initialize GoReleaser configuration
Generate a default .goreleaser.yaml configuration file.
$ goreleaser init
3
Customize the configuration
Edit .goreleaser.yaml to define build targets, archives, and changelog settings.
$ cat > .goreleaser.yaml << 'EOF'
version: 2
builds:
- main: ./cmd/myapp
binary: myapp
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
ldflags:
- -s -w -X main.version={{.Version}}
archives:
- format: tar.gz
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
checksum:
name_template: checksums.txt
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^chore:'
EOF
4
Test the release locally
Run a snapshot build without publishing to verify everything works.
$ goreleaser release --snapshot --clean
Check the dist/ directory for the generated artifacts.
5
Create a tag and publish the release
Tag a version in Git and run GoReleaser to publish to GitHub.
$ git tag -a v1.0.0 -m 'Release v1.0.0' && git push origin v1.0.0 && goreleaser release --clean
Make sure your GITHUB_TOKEN environment variable is set with repo permissions.
Full Script
FAQ
Discussion
Loading comments...