1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-04 03:11:55 +02:00
Deliver Go binaries as fast and easily as possible https://goreleaser.com/
Go to file
Carlos Alexandro Becker 1ebd956637 Update README.md
closes #13
2017-01-22 10:49:24 -02:00
clients Merge branch 'master' into goreleaser.example.yml 2017-01-15 08:49:49 -02:00
config added brew dependencies support 2017-01-17 08:33:43 -02:00
context removed unneeded pointers from context 2017-01-18 15:08:48 -02:00
pipeline added doc 2017-01-21 19:33:30 -02:00
sha256sum golint comments 2017-01-15 08:48:27 -02:00
.editorconfig added replacements support 2017-01-11 19:24:17 -02:00
.gitignore gitignore .glide 2017-01-21 19:23:32 -02:00
.travis.yml debug 2017-01-21 19:21:42 -02:00
CODE_OF_CONDUCT.md added code of conduct 2017-01-02 13:36:39 -02:00
CONTRIBUTING.md Update CONTRIBUTING.md 2017-01-17 10:47:34 -02:00
glide.lock renamed package 2017-01-14 20:01:32 -02:00
glide.yaml renamed package 2017-01-14 20:01:32 -02:00
goreleaser.yml mv docs/readme -> readme 2017-01-21 18:38:53 -02:00
LICENSE.md readme, license and shit 2016-12-28 22:55:23 -02:00
main.go dont git stash or checkout, just fail 2017-01-21 19:11:54 -02:00
Makefile added fmt task to makefile, improved the rest 2017-01-15 09:11:37 -02:00
README.md Update README.md 2017-01-22 10:49:24 -02:00

GoReleaser

goreleaser

GoReleaser builds Go binaries for several platforms, creates a GitHub release and then pushes a Homebrew formula to a repository. All that wrapped in your favorite CI.

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. We appreciate your contribution. Please refer to our contributing guidelines.

Release Software License Travis Go Report Card Powered By: GoReleaser

Table of contents

Introduction

GoReleaser is a release automation tool for Golang projects, the goal is to simplify the build, release and publish steps while providing variant customization options for all steps.

GoReleaser is built for CI tools; you only need to go get and execute it in your build script. You can customize your release process by createing a goreleaser.yml file. We are also working on integrating with package managers, we currently support Homebrew.

The idea started with a simple shell script, but it quickly became more complex and I also wanted to publish binaries via Homebrew.

So, the all-new GoReleaser was born.

Quick start

In this example we will build, archive and release a Golang project. Create a GitHub repository and add a single main package:

// main.go
package main

func main() {
  println("Ba dum, tss!")
}

By default GoReleaser will build the main.go file located in your current directory, but you can change the build package path in the GoReleaser configuration file.

# goreleaser.yml
# Build customization
build:
  binary_name: drum-roll
  goos:
    - windows
    - darwin
    - linux
  goarch:
    - amd64

This configuration specifies the build operating systems to Windows, Linux and MacOS using 64bit architecture, the name of the binaries is drum-roll.

GoReleaser will then archive the result binaries of each Os/Arch into a separate file. The default format is {{.BinaryName}}_{{.Os}}_{{.Arch}}. You can change the archives name and format. You can also replace the OS and the Architecture with your own. Another useful feature is to add files to archives, this is very useful for integrating assets like resource files.

# goreleaser.yml
# Build customization
build:
  main: main.go
  binary_name: drum-roll
  goos:
    - windows
    - darwin
    - linux
  goarch:
    - amd64
# Archive customization
archive:
  format: tar.gz
  replacements:
    amd64: 64-bit
    darwin: macOS
    linux: Tux
  files:
    - drum-roll.licence.txt

This configuration will generate tar archives, contains an additional file drum-roll.licence.txt, the archives will be located in:

  • ./dist/drum-roll_windows_64-bit.tar.gz
  • ./dist/drum-roll_macOS_64-bit.tar.gz
  • ./dist/drum-roll_Tux_64-bit.tar.gz

Next export a GITHUB_TOKEN environment variable with the repo scope selected. This will be used to deploy releases to your GitHub repository. Create yours here.

$ export GITHUB_TOKEN=`YOUR_TOKEN`

GoReleaser uses the latest Git tag of your repository. Create a tag:

$ git tag -a v0.1 -m "First release"

Now you can run GoReleaser at the root of your repository:

$ go get github.com/goreleaser/goreleaser
$ goreleaser

That's it! Check your GitHub release page. The release on will look like this:

image

Environment setup

GitHub Token

GoReleaser requires a GitHub API token with the repo scope checked to deploy the artefacts to GitHub. You can create one here. This token should be added to the environment variables as GITHUB_TOKEN. Here is how to do it with Travis CI: Defining Variables in Repository Settings.

A note about main.version

GoReleaser always sets a main.version ldflag. You can use it in your main.go file:

package main

var version = "master"

func main() {
  println(version)
}

version will always be the name of the current Git tag.

Release customization

GoReleaser provides multiple customizations. We will cover them with the help of goreleaser.yml:

Build customization

# goreleaser.yml
build:
  # Path to main.go file.
  # Default is `main.go`
  main: ./cmd/main.go

  # Name of the binary. Default is the name of the project directory.
  binary_name: program

  # Custom ldflags.
  # Default is `-s -w`
  ldflags: -s -w

  # GOOS list to build in.
  # For more info refer to https://golang.org/doc/install/source#environment
  # Defaults are darwin and linux
  goos:
    - freebsd
    - windows

  # GOARCH to build in.
  # For more info refer to https://golang.org/doc/install/source#environment
  # Defaults are 386 and amd64
  goarch:
    - amd64

Archive customization

# goreleaser.yml
archive:
  # You can change the name of the archive.
  # This is parsed with Golang template engine and the following variables
  # are available:
  # - BinaryName
  # - Version
  # - Os
  # - Arch
  # The default is `{{.BinaryName}}_{{.Os}}_{{.Arch}}`
  name_template: "{{.BinaryName}}_{{.Version}}_{{.Os}}_{{.Arch}}"

  # Archive format. Valid options are `tar.gz` and `zip`.
  # Default is `tar.gz`
  format: zip

  # Replacements for GOOS and GOARCH on the archive name.
  # The keys should be valid GOOS or GOARCH values followed by your custom
  # replacements.
  # By default, `replacements` replace GOOS and GOARCH values with valid outputs
  # of `uname -s` and `uname -m` respectively.
  replacements:
    amd64: 64-bit
    386: 32-bit
    darwin: macOS
    linux: Tux

  # Additional files you want to add to the archive.
  # Defaults are any files matching `LICENCE*`, `LICENSE*`,
  # `README*` and `CHANGELOG*` (case-insensitive)
  files:
    - LICENSE.txt
    - README.md
    - CHANGELOG.md

Release customization

# goreleaser.yml
release:
  # Repo in which the release will be created.
  # Default is extracted from the origin remote URL.
  repo: user/repo

Homebrew tap customization

The brew section specifies how the formula should be created. Check the Homebrew documentation and the formula cookbook for details.

# goreleaser.yml
brew:
  # Reporitory to push the tap to.
  repo: user/homebrew-tap

  # Folder inside the repository to put the formula.
  # Default is the root folder.
  folder: Formula

  # Caveats for the user of your binary.
  # Default is empty.
  caveats: "How to use this binary"

  # Dependencies of your formula
  dependencies:
    - git
    - zsh

By defining the brew section, GoReleaser will take care of publishing the Homebrew tap. Assuming that the current tag is v1.2.3, the above config will generate a program.rb formula in the Formula folder of user/homebrew-tap repository:

class Program < Formula
  desc "How to use this binary"
  homepage "https://github.com/user/repo"
  url "https://github.com/user/repo/releases/download/v1.2.3/program_v1.2.3_macOs_64bit.zip"
  version "v1.2.3"
  sha256 "9ee30fc358fae8d248a2d7538957089885da321dca3f09e3296fe2058e7fff74"

  depends_on "git"
  depends_on "zsh"

  def install
    bin.install "program"
  end
end

Integration with CI

You may want to wire this to auto-deploy your new tags on Travis, for example:

# .travis.yml
after_success:
  test -n "$TRAVIS_TAG" && go get github.com/goreleaser/goreleaser && goreleaser

Here is how to do it with CircleCI:

# circle.yml
deployment:
  tag:
    tag: /v[0-9]+(\.[0-9]+)*(-.*)*/
    owner: user
    commands:
      - go get github.com/goreleaser/goreleaser
      - goreleaser

Would you like to fix something in the documentation? Feel free to open an issue.