1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-04 03:11:55 +02:00
goreleaser/README.md

497 lines
15 KiB
Markdown
Raw Normal View History

2017-04-24 14:10:48 +02:00
<p align="center">
2017-04-24 14:17:22 +02:00
<img alt="GoReleaser Logo" src="https://avatars2.githubusercontent.com/u/24697112?v=3&s=200" height="140" />
2017-04-24 14:17:49 +02:00
<h3 align="center">GoReleaser</h3>
2017-04-24 14:10:48 +02:00
<p align="center">Deliver Go binaries as fast and easily as possible.</p>
<p align="center">
2017-05-05 00:14:55 +02:00
<a href="https://github.com/goreleaser/goreleaser/releases/latest"><img alt="Release" src="https://img.shields.io/github/release/goreleaser/goreleaser.svg?style=flat-square"></a>
2017-04-27 00:23:56 +02:00
<a href="/LICENSE.md"><img alt="Software License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>
<a href="https://travis-ci.org/goreleaser/goreleaser"><img alt="Travis" src="https://img.shields.io/travis/goreleaser/goreleaser.svg?style=flat-square"></a>
<a href="https://codecov.io/gh/goreleaser/goreleaser"><img alt="Codecov branch" src="https://img.shields.io/codecov/c/github/goreleaser/goreleaser/master.svg?style=flat-square"></a>
<a href="https://goreportcard.com/report/github.com/goreleaser/goreleaser"><img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/goreleaser/goreleaser?style=flat-square"></a>
<a href="http://godoc.org/github.com/goreleaser/goreleaser"><img alt="Go Doc" src="https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square"></a>
<a href="https://saythanks.io/to/caarlos0"><img alt="SayThanks.io" src="https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg?style=flat-square"></a>
<a href="https://github.com/goreleaser"><img alt="Powered By: GoReleaser" src="https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square"></a>
2017-04-24 14:10:48 +02:00
</p>
</p>
---
2016-12-29 17:49:01 +02:00
2016-12-29 21:55:07 +02:00
2017-01-14 23:24:25 +02:00
GoReleaser builds Go binaries for several platforms, creates a GitHub release and then
2017-01-21 22:38:53 +02:00
pushes a Homebrew formula to a repository. All that wrapped in your favorite CI.
2017-01-02 17:40:15 +02:00
2017-01-22 14:49:24 +02:00
This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
2017-04-21 21:20:48 +02:00
We appreciate your contribution. Please refer to our [contributing guidelines](CONTRIBUTING.md) for further information.
2017-01-22 14:49:24 +02:00
2017-01-24 19:33:59 +02:00
For questions join the [#goreleaser](https://gophers.slack.com/messages/goreleaser/) channel in the [Gophers Slack](https://invite.slack.golangbridge.org/).
2017-01-21 22:49:34 +02:00
# Table of contents
2017-01-21 22:38:53 +02:00
- [Introduction](#introduction)
2017-01-21 22:38:53 +02:00
- [Quick start](#quick-start)
- [Environment setup](#environment-setup)
- [Release customization](#release-customization)
- [Integration with CI](#integration-with-ci)
2016-12-29 17:49:01 +02:00
2017-01-21 22:38:53 +02:00
## Introduction
2016-12-29 17:49:01 +02:00
2017-01-21 22:38:53 +02:00
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.
2016-12-29 17:49:01 +02:00
2017-02-26 19:22:36 +02:00
GoReleaser is built for CI tools; you only need to [download and execute it](#integration-with-ci) in your build script.
2017-07-05 04:57:27 +02:00
You can [customize](#release-customization) your release process by createing a `.goreleaser.yml` file.
2017-01-22 14:49:24 +02:00
We are also working on integrating with package managers, we currently support Homebrew.
2017-01-21 16:34:40 +02:00
2017-01-21 22:38:53 +02:00
The idea started with a [simple shell script](https://github.com/goreleaser/old-go-releaser), but it quickly became more complex and I also wanted to publish binaries via Homebrew.
2017-01-21 16:34:40 +02:00
2017-01-21 22:38:53 +02:00
## Quick start
2017-01-21 22:38:53 +02:00
In this example we will build, archive and release a Golang project.
Create a GitHub repository and add a single main package:
```go
// main.go
package main
2017-01-14 15:01:45 +02:00
2017-01-21 22:38:53 +02:00
func main() {
println("Ba dum, tss!")
}
```
2017-01-21 22:49:34 +02:00
2017-06-09 14:38:00 +02:00
By default GoReleaser will build the current directory, but you can change the build package path in the GoReleaser configuration file.
2017-01-21 22:38:53 +02:00
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-01-21 22:38:53 +02:00
# Build customization
2017-07-02 02:17:25 +02:00
builds:
- binary: drum-roll
goos:
- windows
- darwin
- linux
goarch:
- amd64
2017-01-21 22:38:53 +02:00
```
2017-01-14 20:30:14 +02:00
PS: Invalid GOOS/GOARCH combinations will automatically be skipped.
2017-01-21 22:49:34 +02:00
This configuration specifies the build operating systems to Windows, Linux and MacOS using 64bit architecture, the name of the binaries is `drum-roll`.
2017-01-21 22:38:53 +02:00
2017-07-02 03:42:10 +02:00
GoReleaser will then archive the result binaries of each Os/Arch into a separate file. The default format is `{{.ProjectName}}_{{.Os}}_{{.Arch}}`.
2017-01-21 22:38:53 +02:00
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.
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-01-21 22:38:53 +02:00
# Build customization
2017-07-02 02:17:25 +02:00
builds:
- main: main.go
binary: drum-roll
goos:
- windows
- darwin
- linux
goarch:
- amd64
2017-01-21 22:38:53 +02:00
# Archive customization
archive:
format: tar.gz
replacements:
amd64: 64-bit
darwin: macOS
linux: Tux
files:
- drum-roll.licence.txt
```
2017-01-21 22:49:34 +02:00
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`
2017-01-21 22:38:53 +02:00
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](https://github.com/settings/tokens/new).
2017-01-21 22:49:34 +02:00
```console
$ export GITHUB_TOKEN=`YOUR_TOKEN`
2017-01-14 20:30:14 +02:00
```
2017-01-21 22:38:53 +02:00
GoReleaser uses the latest [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) of your repository.
2017-05-22 10:11:53 +02:00
Create a tag and push it to GitHub:
2017-01-21 22:49:34 +02:00
```console
2017-05-22 10:11:53 +02:00
$ git tag -a v0.1.0 -m "First release" && git push origin v0.1.0
2017-01-21 22:38:53 +02:00
```
2016-12-29 17:49:01 +02:00
2017-01-30 18:22:39 +02:00
**Note**: we recommend the use of [semantic versioning](http://semver.org/). We
are not enforcing it though. We do remove the `v` prefix and then enforce
that the next character is a number. So, `v0.1.0` and `0.1.0` are virtually the
same and are both accepted, while `version0.1.0` is not.
2017-04-29 12:49:22 +02:00
If you don't want to create a tag yet but instead simply create a package based on the latest commit, then you can also use the `--snapshot` flag.
2017-01-21 22:38:53 +02:00
Now you can run GoReleaser at the root of your repository:
2017-01-21 22:49:34 +02:00
```console
$ goreleaser
2017-01-21 22:38:53 +02:00
```
2017-01-15 19:58:45 +02:00
2017-02-26 19:46:21 +02:00
That's it! Check your GitHub project's release page.
The release should look like this:
2017-01-14 20:30:14 +02:00
2017-02-26 19:46:21 +02:00
[![image](https://cloud.githubusercontent.com/assets/245435/23342061/fbcbd506-fc31-11e6-9d2b-4c1b776dee9c.png)
2017-01-21 22:38:53 +02:00
](https://github.com/goreleaser/goreleaser/releases)
2017-01-14 20:30:14 +02:00
2017-01-21 22:38:53 +02:00
## Environment setup
2016-12-29 17:49:01 +02:00
2017-01-21 22:38:53 +02:00
### GitHub Token
2017-01-21 22:49:34 +02:00
2017-01-21 22:38:53 +02:00
GoReleaser requires a GitHub API token with the `repo` scope checked to deploy the artefacts to GitHub. You can create one [here](https://github.com/settings/tokens/new).
2017-01-21 22:49:34 +02:00
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](https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings).
2016-12-29 17:49:01 +02:00
2017-01-14 23:24:25 +02:00
### A note about `main.version`
2016-12-29 17:49:01 +02:00
2017-01-14 23:24:25 +02:00
GoReleaser always sets a `main.version` ldflag. You can use it in your
`main.go` file:
```go
package main
var version = "master"
func main() {
println(version)
}
```
2017-05-01 16:15:34 +02:00
`version` will be the current Git tag (with `v` prefix stripped) or the name of the snapshot if you're using the `--snapshot` flag.
## GoReleaser customization
2017-01-21 22:38:53 +02:00
2017-07-05 04:57:27 +02:00
GoReleaser provides multiple customizations via the `.goreleaser.yml` file.
2017-05-01 16:15:34 +02:00
You can generate it by running `goreleaser init` or start from scratch. The
defaults are sensible and fit for most projects.
2017-01-21 22:38:53 +02:00
2017-05-01 16:15:34 +02:00
We'll cover all customizations available bellow:
2017-01-21 22:49:34 +02:00
2017-07-02 03:42:10 +02:00
### Project name
2017-01-21 22:38:53 +02:00
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-07-02 03:42:10 +02:00
# The name of the project. It is used in the name of the brew formula, archives,
# etc. Defaults to the name of the git project.
project_name: myproject
```
2017-01-21 22:38:53 +02:00
2017-01-21 22:49:34 +02:00
### Build customization
2017-02-22 14:25:43 +02:00
2017-01-21 22:38:53 +02:00
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-07-02 02:17:25 +02:00
builds:
# You can have multiple builds, its a common yaml list
-
# Path to main.go file or main package.
# Default is `.`
main: ./cmd/main.go
# Name of the binary.
# Default is the name of the project directory.
binary: program
# Custom build tags.
# Default is empty
flags: -tags dev
# Custom ldflags template.
# This is parsed with Golang template engine and the following variables
# are available:
# - Date
# - Commit
# - Tag
# - Version (Tag with the `v` prefix stripped)
# The default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}`
# Date format is `2006-01-02_15:04:05`
ldflags: -s -w -X main.build={{.Version}}
# Custom environment variables to be set durign the builds.
# Default is empty
env:
- CGO_ENABLED=0
# 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
- arm
- arm64
# GOARM to build in when GOARCH is arm.
# For more info refer to https://golang.org/doc/install/source#environment
# Defaults are 6
goarm:
- 6
- 7
# List of combinations of GOOS + GOARCH + GOARM to ignore.
# Default is empty.
ignore:
- goos: darwin
goarch: 386
- goos: linux
goarch: arm
goarm: 7
# Hooks can be used to customize the final binary, for example, to run
# generator or whatever you want.
# Default is both hooks empty.
hooks:
pre: rice embed-go
post: ./script.sh
2017-01-21 22:49:34 +02:00
```
2017-01-21 22:38:53 +02:00
2017-01-21 22:49:34 +02:00
### Archive customization
2017-01-21 22:38:53 +02:00
2017-01-21 22:49:34 +02:00
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-01-21 22:38:53 +02:00
archive:
# You can change the name of the archive.
# This is parsed with Golang template engine and the following variables
# are available:
2017-07-02 03:42:10 +02:00
# - ProjectName
# - Tag
# - Version (Tag with the `v` prefix stripped)
2017-01-21 22:38:53 +02:00
# - Os
# - Arch
2017-04-24 19:27:21 +02:00
# - Arm (ARM version)
2017-07-02 03:42:10 +02:00
# The default is `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
2017-01-21 22:38:53 +02:00
# Archive format. Valid options are `tar.gz`, `zip` and `binary`.
# If format is `binary` no archives are created and the binaries are instead uploaded directly.
# In that case name_template the below specified files are ignored.
2017-01-21 22:38:53 +02:00
# Default is `tar.gz`
format: zip
2017-05-01 16:07:05 +02:00
# Can be used to archive on different formats for specific GOOSs.
# Most common use case is to archive as zip on Windows.
# Default is empty
format_overrides:
- goos: windows
format: zip
2017-01-21 22:38:53 +02:00
# Replacements for GOOS and GOARCH on the archive name.
# The keys should be valid GOOS or GOARCH values followed by your custom
# replacements.
replacements:
amd64: 64-bit
386: 32-bit
darwin: macOS
linux: Tux
2017-05-11 05:11:22 +02:00
# Additional files/globs you want to add to the archive.
2017-01-21 22:38:53 +02:00
# Defaults are any files matching `LICENCE*`, `LICENSE*`,
# `README*` and `CHANGELOG*` (case-insensitive)
files:
- LICENSE.txt
- README.md
- CHANGELOG.md
2017-05-11 05:11:22 +02:00
- docs/*
- design/*.png
2017-01-21 22:49:34 +02:00
```
2017-01-21 22:38:53 +02:00
2017-01-21 22:49:34 +02:00
### Release customization
2017-01-21 22:38:53 +02:00
2017-01-21 22:49:34 +02:00
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-01-21 22:38:53 +02:00
release:
# Repo in which the release will be created.
# Default is extracted from the origin remote URL.
2017-03-23 02:01:29 +02:00
github:
owner: user
name: repo
2017-04-22 00:50:09 +02:00
# If set to true, will not auto-publish the release.
# Default is false
draft: true
2017-01-21 22:49:34 +02:00
```
2017-01-21 22:38:53 +02:00
You can also specify a release notes file in markdown format using the
`--release-notes` flag.
2017-04-29 12:49:22 +02:00
### Snapshot customization
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-04-29 12:49:22 +02:00
snapshot:
# Allows you to change the name of the generated snapshot
# releases. The following variables are available:
# - Commit
# - Tag
# - Timestamp
# Default: SNAPSHOT-{{.Commit}}
name_template: SNAPSHOT-{{.Commit}}
```
2017-01-21 22:49:34 +02:00
### Homebrew tap customization
2017-01-21 22:38:53 +02:00
2017-01-21 22:49:34 +02:00
The brew section specifies how the formula should be created.
2017-01-21 23:44:39 +02:00
Check [the Homebrew documentation](https://github.com/Homebrew/brew/blob/master/docs/How-to-Create-and-Maintain-a-Tap.md) and the [formula cookbook](https://github.com/Homebrew/brew/blob/master/docs/Formula-Cookbook.md) for details.
2017-01-21 22:49:34 +02:00
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-01-21 22:38:53 +02:00
brew:
# Reporitory to push the tap to.
2017-03-23 02:01:29 +02:00
github:
owner: user
name: homebrew-tap
2017-01-21 22:38:53 +02:00
# 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"
2017-04-21 22:02:28 +02:00
# Your app's homepage
# Default is empty
homepage: "https://example.com/"
# Your app's description
# Default is empty
description: "Software to create fast and easy drum rolls."
2017-02-01 19:42:50 +02:00
# Dependencies of your package
2017-01-21 22:38:53 +02:00
dependencies:
2017-01-21 23:44:39 +02:00
- git
- zsh
2017-02-01 19:42:50 +02:00
# Packages that conflict with your package
conflicts:
- svn
- bash
2017-02-21 17:04:57 +02:00
# Packages that run as a service
2017-03-09 19:24:49 +02:00
plist:|
2017-02-21 17:04:57 +02:00
<?xml version="1.0" encoding="UTF-8"?>
...
2017-03-09 19:24:49 +02:00
# Custom install script for brew. Default: "bin.install "program"
install:|
bin.install "program"
...
2016-12-29 17:49:01 +02:00
```
2017-01-21 23:44:39 +02:00
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:
2016-12-29 17:49:01 +02:00
```rb
2017-01-21 22:38:53 +02:00
class Program < Formula
desc "How to use this binary"
2017-01-21 22:49:34 +02:00
homepage "https://github.com/user/repo"
2017-01-21 23:44:39 +02:00
url "https://github.com/user/repo/releases/download/v1.2.3/program_v1.2.3_macOs_64bit.zip"
2017-01-21 22:38:53 +02:00
version "v1.2.3"
2017-01-11 18:52:30 +02:00
sha256 "9ee30fc358fae8d248a2d7538957089885da321dca3f09e3296fe2058e7fff74"
2016-12-29 17:49:01 +02:00
2017-01-21 23:44:39 +02:00
depends_on "git"
depends_on "zsh"
2016-12-29 17:49:01 +02:00
def install
2017-01-21 22:38:53 +02:00
bin.install "program"
2016-12-29 17:49:01 +02:00
end
end
```
2016-12-30 01:49:58 +02:00
2017-01-30 11:59:49 +02:00
### FPM build customization
2017-04-25 18:40:56 +02:00
GoReleaser can be wired to [fpm]() to generate `.deb`, `.rpm` and other archives. Check its
2017-01-30 11:59:49 +02:00
[wiki](https://github.com/jordansissel/fpm/wiki) for more info.
[fpm]: https://github.com/jordansissel/fpm
```yml
2017-07-05 04:57:27 +02:00
# .goreleaser.yml
2017-01-30 11:59:49 +02:00
fpm:
2017-04-21 22:02:28 +02:00
# Your app's vendor
# Default is empty
vendor: Drum Roll Inc.
# Your app's homepage
# Default is empty
homepage: https://example.com/
# Your app's maintainer (probably you)
# Default is empty
2017-04-25 18:40:56 +02:00
maintainer: Drummer <drum-roll@example.com>
2017-04-21 22:02:28 +02:00
# Your app's description
# Default is empty
description: Software to create fast and easy drum rolls.
# Your app's license
# Default is empty
license: Apache 2.0
2017-01-30 11:59:49 +02:00
# Formats to generate as output
formats:
- deb
- rpm
# Dependencies of your package
dependencies:
- git
2017-02-01 19:42:50 +02:00
- zsh
# Packages that conflict with your package
conflicts:
- svn
- bash
2017-01-30 11:59:49 +02:00
```
2017-04-25 18:40:56 +02:00
Note that GoReleaser will not install `fpm` nor any of its dependencies for you.
2017-01-30 11:59:49 +02:00
2017-05-01 16:15:34 +02:00
### Custom release notes
You can have a markdown file previously created with the release notes, and
pass it down to goreleaser with the `--release-notes=FILE` flag.
2017-01-21 22:38:53 +02:00
## Integration with CI
2017-01-02 19:08:49 +02:00
2017-01-21 22:38:53 +02:00
You may want to wire this to auto-deploy your new tags on [Travis](https://travis-ci.org), for example:
2016-12-30 01:49:58 +02:00
2017-01-21 22:38:53 +02:00
```yaml
# .travis.yml
after_success:
- test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash
2017-01-21 22:38:53 +02:00
```
2016-12-30 01:49:58 +02:00
2017-01-21 22:38:53 +02:00
Here is how to do it with [CircleCI](https://circleci.com):
2017-01-21 22:49:34 +02:00
2017-01-21 22:38:53 +02:00
```yml
# circle.yml
deployment:
2017-01-21 22:49:34 +02:00
tag:
tag: /v[0-9]+(\.[0-9]+)*(-.*)*/
2017-01-21 23:44:39 +02:00
owner: user
2017-01-21 22:38:53 +02:00
commands:
2017-02-26 19:36:59 +02:00
- curl -sL https://git.io/goreleaser | bash
2016-12-30 01:49:58 +02:00
```
2017-01-21 22:38:53 +02:00
2017-01-24 20:58:19 +02:00
*Note that if you test multiple versions or multiple OSes you probably want to make sure GoReleaser is just run once*
2017-07-07 05:40:47 +02:00
### Star history over time
2017-01-21 22:38:53 +02:00
2017-07-08 04:55:16 +02:00
## stargazers over time
[![goreleaser/goreleaser stargazers over time](https://starcharts.herokuapp.com/goreleaser/goreleaser.svg)](https://starcharts.herokuapp.com/goreleaser/goreleaser)
2017-07-07 04:44:08 +02:00
---
2017-07-07 05:40:47 +02:00
Would you like to fix something in the documentation? Feel free to open an [issue](https://github.com/goreleaser/goreleaser/issues).