2017-01-14 14:01:45 +01:00
|
|
|
# GoReleaser
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2017-01-11 22:59:59 -02:00
|
|
|
<img src="https://avatars2.githubusercontent.com/u/24697112?v=3&s=200" alt="goreleaser" align="right" />
|
2016-12-29 17:55:07 -02:00
|
|
|
|
2017-01-14 19:30:14 +01:00
|
|
|
GoReleaser builds Go binaries for several platforms, creates a Github release and then
|
2017-01-14 19:58:51 +01:00
|
|
|
pushes a Homebrew formulae to a repository. All that wrapped in your favorite CI.
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2017-01-02 13:40:15 -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. Please report unacceptable behavior to root@carlosbecker.com.
|
|
|
|
|
2017-01-14 18:52:57 -02:00
|
|
|
[](https://travis-ci.org/goreleaser/goreleaser) [](https://goreportcard.com/report/github.com/goreleaser/goreleaser) [](https://github.com/goreleaser)
|
2017-01-13 09:10:36 -02:00
|
|
|
|
2016-12-29 13:49:01 -02:00
|
|
|
## How it works?
|
|
|
|
|
|
|
|
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
|
2017-01-14 19:30:14 +01:00
|
|
|
Homebrew.
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2017-01-14 18:55:24 -02:00
|
|
|
So, the all-new GoReleaser was born.
|
2016-12-29 13:49:01 -02:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2017-01-14 19:58:51 +01:00
|
|
|
- You need to export a `GITHUB_TOKEN` environment variable with
|
|
|
|
the `repo` scope selected. You can create one [here](https://github.com/settings/tokens/new).
|
2017-01-04 10:21:46 +02:00
|
|
|
|
2017-01-14 19:58:51 +01:00
|
|
|
- GoReleaser uses the latest [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) of your repository,
|
2017-01-14 14:01:45 +01:00
|
|
|
so you need to [create a tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging#Annotated-Tags) first.
|
|
|
|
|
2017-01-14 18:55:24 -02:00
|
|
|
- Now you can run `goreleaser` at the root of your repository:
|
2017-01-14 19:30:14 +01:00
|
|
|
|
|
|
|
```sh
|
|
|
|
curl -s https://raw.githubusercontent.com/goreleaser/get/master/latest | bash
|
|
|
|
```
|
|
|
|
|
|
|
|
This will build `main.go` as binary, for `Darwin` and `Linux`
|
2017-01-11 14:59:06 -02:00
|
|
|
(`amd64` and `i386`), archive the binary and common files as `.tar.gz`,
|
2017-01-14 19:30:14 +01:00
|
|
|
and finally, publish a new Github release in the repository with
|
2017-01-11 14:59:06 -02:00
|
|
|
archives uploaded.
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2017-01-14 19:30:14 +01:00
|
|
|
|
|
|
|
For further customization create a `goreleaser.yml` file in the root of your repository.
|
|
|
|
|
2016-12-29 13:49:01 -02:00
|
|
|
### Homebrew
|
|
|
|
|
2017-01-14 14:39:02 +01:00
|
|
|
Add a `brew` section to push a formulae to a Homebrew tab repository:
|
2016-12-29 13:49:01 -02:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
brew:
|
2017-01-11 20:50:38 -02:00
|
|
|
repo: user/homebrew-tap
|
2017-01-14 11:18:48 -02:00
|
|
|
folder: optional/subfolder/inside/the/repo
|
2016-12-29 13:49:01 -02:00
|
|
|
caveats: "Optional caveats to add to the formulae"
|
|
|
|
```
|
|
|
|
|
2017-01-14 14:39:02 +01:00
|
|
|
See the [Homebrew docs](https://github.com/Homebrew/brew/blob/master/docs/How-to-Create-and-Maintain-a-Tap.md) for creating your own tap.
|
|
|
|
|
2016-12-29 13:49:01 -02:00
|
|
|
### Build customization
|
|
|
|
|
|
|
|
Just add a `build` section
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
build:
|
|
|
|
main: ./cmd/main.go
|
2017-01-11 20:25:52 -02:00
|
|
|
ldflags: -s -w
|
2016-12-29 13:49:01 -02:00
|
|
|
oses:
|
|
|
|
- darwin
|
|
|
|
- freebsd
|
|
|
|
arches:
|
|
|
|
- amd64
|
|
|
|
```
|
|
|
|
|
2017-01-11 20:25:52 -02:00
|
|
|
> - `oses` and `arches` should be in `GOOS`/`GOARCH`-compatible format.
|
|
|
|
> - `-s -w` is the default value for `ldflags`.
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2017-01-11 14:52:30 -02:00
|
|
|
### Archive customization
|
2017-01-06 11:17:59 -02:00
|
|
|
|
2017-01-11 14:52:30 -02:00
|
|
|
You can customize the name and format of the archive adding an `archive`
|
|
|
|
section:
|
2017-01-06 11:17:59 -02:00
|
|
|
|
|
|
|
```yaml
|
2017-01-11 14:52:30 -02:00
|
|
|
archive:
|
2017-01-11 14:55:16 -02:00
|
|
|
name_template: "{{.BinaryName}}_{{.Version}}_{{.Os}}_{{.Arch}}"
|
2017-01-11 19:24:17 -02:00
|
|
|
format: zip
|
|
|
|
replacements:
|
|
|
|
amd64: 64-bit
|
|
|
|
386: 32-bit
|
|
|
|
darwin: macOS
|
|
|
|
linux: Tux
|
2017-01-06 11:17:59 -02:00
|
|
|
```
|
|
|
|
|
2017-01-11 15:25:58 -02:00
|
|
|
> - Default `name_template` is `{{.BinaryName}}_{{.Os}}_{{.Arch}}`
|
|
|
|
> - Valid formats are `tar.gz` and `zip`, default is `tar.gz`
|
2017-01-11 19:24:17 -02:00
|
|
|
> - By default, `replacements` replace `GOOS` with `uname -s` values and
|
|
|
|
> `GOARCH` with `uname -m` values. They keys should always be in the `GOOS` and
|
|
|
|
> `GOARCH` form.
|
2017-01-06 11:17:59 -02:00
|
|
|
|
2016-12-29 13:49:01 -02:00
|
|
|
### Add more files
|
|
|
|
|
|
|
|
You might also want to change the files that are packaged by adding a `files`
|
|
|
|
section:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
files:
|
|
|
|
- LICENSE.txt
|
|
|
|
- README.md
|
|
|
|
- CHANGELOG.md
|
|
|
|
```
|
|
|
|
|
2017-01-11 14:52:30 -02:00
|
|
|
> By default GoReleaser adds the binary itself, `LICENCE*`, `LICENSE*`,
|
|
|
|
`README*` and `CHANGELOG*`.
|
|
|
|
|
2017-01-11 20:25:52 -02:00
|
|
|
### ldflags (main.version)
|
2017-01-11 20:10:02 -02:00
|
|
|
|
2017-01-14 19:58:51 +01:00
|
|
|
GoReleaser always sets a `main.version` ldflag. You can use it in your `main.go` file:
|
2017-01-11 20:10:02 -02:00
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
var version = "master"
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
println(version)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-01-14 19:58:51 +01:00
|
|
|
And this version will always be the name of the current tag.
|
2017-01-11 20:10:02 -02:00
|
|
|
|
2017-01-14 19:30:14 +01:00
|
|
|
|
|
|
|
### Other customizations
|
|
|
|
|
|
|
|
- By default it's assumed that the repository to release to is the same as the Git `remote origin`.
|
|
|
|
If this is not the case for your project, you can specify a `repo`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
repo: owner/custom-repo
|
|
|
|
```
|
|
|
|
|
|
|
|
- By default the binary name is the name of the project directory.
|
|
|
|
You can specify a different `binary_name`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
binary_name: my-binary
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2017-01-14 19:58:51 +01:00
|
|
|
## Wire it with Travis CI
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2017-01-14 19:58:51 +01:00
|
|
|
You may want to wire this to auto-deploy your new tags on Travis, for example:
|
2016-12-29 13:49:01 -02:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
after_success:
|
2017-01-02 13:57:36 -02:00
|
|
|
test -n "$TRAVIS_TAG" && curl -s https://raw.githubusercontent.com/goreleaser/get/master/latest | bash
|
2016-12-29 13:49:01 -02:00
|
|
|
```
|
|
|
|
|
2017-01-04 11:35:04 +02:00
|
|
|
## What the end result looks like
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2017-01-14 19:30:14 +01:00
|
|
|
The release on Github looks pretty much like this:
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2016-12-31 16:45:16 -02:00
|
|
|
[
|
2017-01-14 18:52:57 -02:00
|
|
|
](https://github.com/goreleaser/goreleaser/releases)
|
2016-12-29 13:49:01 -02:00
|
|
|
|
2017-01-14 19:30:14 +01:00
|
|
|
And the [Homebrew formulae](https://github.com/goreleaser/homebrew-tap/blob/master/release.rb) would look like:
|
2016-12-29 13:49:01 -02:00
|
|
|
|
|
|
|
```rb
|
2016-12-31 16:45:16 -02:00
|
|
|
class Release < Formula
|
2017-01-11 14:52:30 -02:00
|
|
|
desc "Deliver Go binaries as fast and easily as possible"
|
2017-01-14 18:52:57 -02:00
|
|
|
homepage "https://github.com/goreleaser/goreleaser"
|
|
|
|
url "https://github.com/goreleaser/goreleaser/releases/download/v0.2.8/release_Darwin_x86_64.tar.gz"
|
2017-01-11 14:52:30 -02:00
|
|
|
version "v0.2.8"
|
|
|
|
sha256 "9ee30fc358fae8d248a2d7538957089885da321dca3f09e3296fe2058e7fff74"
|
2016-12-29 13:49:01 -02:00
|
|
|
|
|
|
|
def install
|
2016-12-31 16:45:16 -02:00
|
|
|
bin.install "release"
|
2016-12-29 13:49:01 -02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
2016-12-29 21:49:58 -02:00
|
|
|
|
2017-01-02 18:08:49 +01:00
|
|
|
## How to contribute
|
|
|
|
|
|
|
|
Please refer to our [contributing guidelines](/CONTRIBUTING.md).
|
|
|
|
|
2016-12-29 21:49:58 -02:00
|
|
|
## Badges
|
|
|
|
|
|
|
|
Feel free to use it in your own projects:
|
|
|
|
|
|
|
|
```md
|
|
|
|
[](https://github.com/goreleaser)
|
|
|
|
```
|