1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-18 03:56:52 +02:00
goreleaser/README.md

185 lines
5.2 KiB
Markdown
Raw Normal View History

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
GoReleaser builds Go binaries for several platforms, creates a github release and then
push 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-13 09:10:36 -02:00
[![Build Status](https://travis-ci.org/goreleaser/releaser.svg?branch=master)](https://travis-ci.org/goreleaser/releaser) [![Go Report Card](https://goreportcard.com/badge/github.com/goreleaser/releaser)](https://goreportcard.com/report/github.com/goreleaser/releaser) [![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](https://github.com/goreleaser)
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
homebrew.
So, the all-new goreleaser was born.
## Usage
2017-01-12 19:51:57 -02:00
Create a `goreleaser.yml` file in the root of your repository. A minimal config
would look like this:
2016-12-29 13:49:01 -02:00
```yaml
repo: user/repo
binary_name: my-binary
```
2017-01-04 11:35:04 +02:00
You may then run releaser at the root of your repository:
```sh
2017-01-04 11:35:04 +02:00
curl -s https://raw.githubusercontent.com/goreleaser/get/master/latest | bash
```
2017-01-12 19:51:57 -02:00
For that to work, 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-14 14:01:45 +01:00
GoReleaser uses the latest [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) of your repository,
so you need to [create a tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging#Annotated-Tags) first.
2017-01-11 14:59:06 -02:00
This will build `main.go` as `my-binary`, for `Darwin` and `Linux`
(`amd64` and `i386`), archive the binary and common files as `.tar.gz`,
and finally, publish a new github release in the `user/repo` repository with
archives uploaded.
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
repo: user/repo
binary_name: my-binary
brew:
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
repo: user/repo
binary_name: my-binary
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
repo: user/repo
binary_name: my-binary
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
repo: user/repo
binary_name: my-binary
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)
GoReleaser already sets a `main.version` ldflag, so, in you `main.go` program,
you can:
```go
package main
var version = "master"
func main() {
println(version)
}
```
And this version will always be the tag name.
2016-12-29 13:49:01 -02:00
## Wire it with travis-ci
2017-01-02 10:11:35 +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
The release on github looks pretty much like this:
2016-12-31 16:45:16 -02:00
[![image](https://cloud.githubusercontent.com/assets/245435/21578845/09404c8a-cf78-11e6-92d7-165ddc03ca6c.png)
](https://github.com/goreleaser/releaser/releases)
2016-12-29 13:49:01 -02: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"
2016-12-31 16:45:31 -02:00
homepage "https://github.com/goreleaser/releaser"
2017-01-11 14:52:30 -02:00
url "https://github.com/goreleaser/releaser/releases/download/v0.2.8/release_Darwin_x86_64.tar.gz"
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
[![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](https://github.com/goreleaser)
```