Publishing Your Applications with GoReleaser

Introduction⌗
GoReleaser is developed in Golang and is an automated release tool for Golang projects. With minimal configuration, you can easily achieve cross-platform compilation, packaging, and publishing to version repositories like Github and Gitlab with just a few commands.
Installation⌗
MacOS⌗
# Latest version
$ brew install goreleaser/tap/goreleaser
# May not be the latest version
$ brew install goreleaser
Running from Docker⌗
$ docker run --rm --privileged \
-v $PWD:/go/src/github.com/user/repo \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/user/repo \
-e GITHUB_TOKEN \
-e DOCKER_USERNAME \
-e DOCKER_PASSWORD \
-e DOCKER_REGISTRY \
goreleaser/goreleaser release
Compiling from Source⌗
# Clone to GOPATH
$ git clone https://github.com/goreleaser/goreleaser
$ cd goreleaser
# Requires go 1.11 or above with go module support
$ go get ./...
# Compile
$ o build -o goreleaser .
# Run
$ ./goreleaser --version
Quick Start⌗
Initialization⌗
$ goreleaser init
After executing the above command, a .goreleaser.yml configuration file will be generated in the project directory:
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# you may remove this if you don't use vgo
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
You can modify it according to your needs.
Getting a Github Token⌗
Visit Settings / Developer Settings / Personal access tokens, click the Generate new token button, generate a new Token, and save the Token to the ~/.config/goreleaser/github_token file.
Tagging Your Project⌗
$ git tag -a v0.1.0 -m "release v0.1.0"
$ git push origin v0.1.0
Executing the Automated Release Process⌗
$ goreleaser --rm-dist
If the project directory doesn’t have a dist directory, you can omit the --rm-dist parameter. After execution, the following file structure will be generated:
dist/
├── CHANGELOG.md
├── checksums.txt
├── config.yaml
├── ects_0.5.1_Darwin_i386.tar.gz
├── ects_0.5.1_Darwin_x86_64.tar.gz
├── ects_0.5.1_Linux_i386.tar.gz
├── ects_0.5.1_Linux_x86_64.tar.gz
├── ects_darwin_386
│ └── ects
├── ects_darwin_amd64
│ └── ects
├── ects_linux_386
│ └── ects
└── ects_linux_amd64
└── ects
4 directories, 11 files
And it will start automatically publishing to the Release page on Github.
George:ects George$ goreleaser --rm-dist
• releasing using goreleaser 0.117.1...
• loading config file file=.goreleaser.yml
• RUNNING BEFORE HOOKS
• running go mod tidy
• running go generate ./...
• LOADING ENVIRONMENT VARIABLES
• GETTING AND VALIDATING GIT STATE
• releasing v0.5.1, commit 6d1fc054405884ba88bbc3b8101bfb0491a5b9e2
• PARSING TAG
• SETTING DEFAULTS
• LOADING ENVIRONMENT VARIABLES
• SNAPSHOTING
• GITHUB/GITLAB/GITEA RELEASES
• PROJECT NAME
• BUILDING BINARIES
• ARCHIVES
• LINUX PACKAGES WITH NFPM
• SNAPCRAFT PACKAGES
• CALCULATING CHECKSUMS
• SIGNING ARTIFACTS
• DOCKER IMAGES
• ARTIFACTORY
• S3
• BLOB
• HOMEBREW TAP FORMULA
• optimistically guessing `brew[0].installs`, double check
• SCOOP MANIFEST
• SNAPSHOTING
• pipe skipped error=not a snapshot
• CHECKING ./DIST
• --rm-dist is set, cleaning it up
• WRITING EFFECTIVE CONFIG FILE
• writing config=dist/config.yaml
• GENERATING CHANGELOG
• writing changelog=dist/CHANGELOG.md
• BUILDING BINARIES
• building binary=dist/ects_darwin_386/ects
• building binary=dist/ects_darwin_amd64/ects
• building binary=dist/ects_linux_amd64/ects
• building binary=dist/ects_linux_386/ects
• ARCHIVES
• creating archive=dist/ects_0.5.1_Linux_x86_64.tar.gz
• creating archive=dist/ects_0.5.1_Darwin_x86_64.tar.gz
• creating archive=dist/ects_0.5.1_Darwin_i386.tar.gz
• creating archive=dist/ects_0.5.1_Linux_i386.tar.gz
• LINUX PACKAGES WITH NFPM
• pipe skipped error=no output formats configured
• SNAPCRAFT PACKAGES
• pipe skipped error=no summary nor description were provided
• CALCULATING CHECKSUMS
• checksumming file=ects_0.5.1_Darwin_x86_64.tar.gz
• checksumming file=ects_0.5.1_Darwin_i386.tar.gz
• checksumming file=ects_0.5.1_Linux_i386.tar.gz
• checksumming file=ects_0.5.1_Linux_x86_64.tar.gz
• SIGNING ARTIFACTS
• pipe skipped error=artifact signing is disabled
• DOCKER IMAGES
• pipe skipped error=docker section is not configured
• PUBLISHING
• S3
• pipe skipped error=s3 section is not configured
• BLOB
• pipe skipped error=Blob section is not configured
• HTTP PUT
• pipe skipped error=put section is not configured
• ARTIFACTORY
• pipe skipped error=artifactory section is not configured
• DOCKER IMAGES
• SNAPCRAFT PACKAGES
• GITHUB/GITLAB/GITEA RELEASES
• creating or updating release repo=betterde/ects tag=v0.5.1
• release updated url=https://github.com/betterde/ects/releases/tag/v0.5.1
• uploading to release file=dist/checksums.txt name=checksums.txt
• uploading to release file=dist/ects_0.5.1_Linux_x86_64.tar.gz name=ects_0.5.1_Linux_x86_64.tar.gz
• uploading to release file=dist/ects_0.5.1_Darwin_x86_64.tar.gz name=ects_0.5.1_Darwin_x86_64.tar.gz
• uploading to release file=dist/ects_0.5.1_Darwin_i386.tar.gz name=ects_0.5.1_Darwin_i386.tar.gz
• uploading to release file=dist/ects_0.5.1_Linux_i386.tar.gz name=ects_0.5.1_Linux_i386.tar.gz
• HOMEBREW TAP FORMULA
• pipe skipped error=brew section is not configured
• SCOOP MANIFEST
• pipe skipped error=scoop section is not configured
• release succeeded after 12.93s
When you see release succeeded after 12.93s, it means the release has been successful. You can now visit your project to check if the release was successful.

More⌗
For more detailed configuration, please refer to the official documentation
I hope this is helpful, Happy hacking…