Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Deliver Go binaries as fast and easily as possible

License

NotificationsYou must be signed in to change notification settings

justwatchcom/goreleaser

 
 

Repository files navigation

GoReleaser Logo

GoReleaser

Deliver Go binaries as fast and easily as possible.

ReleaseSoftware LicenseTravisCodecov branchGo Report CardGo DocSayThanks.ioPowered By: GoReleaser


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

This project adheres to the Contributor Covenantcode of conduct. By participating, you are expected to uphold this code.We appreciate your contribution. Please refer to ourcontributing guidelines for further information.

For questions join the#goreleaser channel in theGophers Slack.

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 todownload and execute it in your build script.You cancustomize your release process by createing agoreleaser.yml file.We are also working on integrating with package managers, we currently support Homebrew.

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

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.gopackage mainfuncmain() {println("Ba dum, tss!")}

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

# goreleaser.yml# Build customizationbuild:binary:drum-rollgoos:    -windows    -darwin    -linuxgoarch:    -amd64

PS: Invalid GOOS/GOARCH combinations will automatically be skipped.

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

GoReleaser will then archive the result binaries of each Os/Arch into a separate file. The default format is{{.Binary}}_{{.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 customizationbuild:main:main.gobinary:drum-rollgoos:    -windows    -darwin    -linuxgoarch:    -amd64# Archive customizationarchive:format:tar.gzreplacements:amd64:64-bitdarwin:macOSlinux:Tuxfiles:    -drum-roll.licence.txt

This configuration will generate tar archives, contains an additional filedrum-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 aGITHUB_TOKEN environment variable with therepo scope selected. This will be used to deploy releases to your GitHub repository. Create yourshere.

$export GITHUB_TOKEN=`YOUR_TOKEN`

GoReleaser uses the latestGit tag of your repository.Create a tag and push it to GitHub:

$git tag -a v0.1.0 -m"First release"&& git push origin v0.1.0

Note: we recommend the use ofsemantic versioning. Weare not enforcing it though. We do remove thev prefix and then enforcethat the next character is a number. So,v0.1.0 and0.1.0 are virtually thesame and are both accepted, whileversion0.1.0 is not.

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.

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

$goreleaser

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

image

Environment setup

GitHub Token

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

A note aboutmain.version

GoReleaser always sets amain.version ldflag. You can use it in yourmain.go file:

package mainvarversion="master"funcmain() {println(version)}

version will be the current Git tag (withv prefix stripped) or the name of the snapshot if you're using the--snapshot flag.

GoReleaser customization

GoReleaser provides multiple customizations via thegoreleaser.yml file.You can generate it by runninggoreleaser init or start from scratch. Thedefaults are sensible and fit for most projects.

We'll cover all customizations available bellow:

Build customization

# goreleaser.ymlbuild:# 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 emptyflags:-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 emptyenv:   -CGO_ENABLED=0# GOOS list to build in.# For more info refer to https://golang.org/doc/install/source#environment# Defaults are darwin and linuxgoos:    -freebsd    -windows# GOARCH to build in.# For more info refer to https://golang.org/doc/install/source#environment# Defaults are 386 and amd64goarch:    -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 6goarm:    -6    -7# List of combinations of GOOS + GOARCH + GOARM to ignore.# Default is empty.ignore:    -goos:darwingoarch:386    -goos:linuxgoarch:armgoarm: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-gopost:./script.sh

Archive customization

# goreleaser.ymlarchive:# You can change the name of the archive.# This is parsed with Golang template engine and the following variables# are available:# - Binary# - Tag# - Version (Tag with the `v` prefix stripped)# - Os# - Arch# - Arm (ARM version)# The default is `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`name_template:"{{.Binary}}_{{.Version}}_{{.Os}}_{{.Arch}}"# Archive format. Valid options are `tar.gz` and `zip`.# Default is `tar.gz`format:zip# Can be used to archive on different formats for specific GOOSs.# Most common use case is to archive as zip on Windows.# Default is emptyformat_overrides:    -goos:windowsformat:zip# 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-bit386:32-bitdarwin:macOSlinux:Tux# Additional files/globs 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    -docs/*    -design/*.png

Release customization

# goreleaser.ymlrelease:# Repo in which the release will be created.# Default is extracted from the origin remote URL.github:owner:username:repo# If set to true, will not auto-publish the release.# Default is falsedraft:true

You can also specify a release notes file in markdown format using the--release-notes flag.

Snapshot customization

# goreleaser.ymlsnapshot:# 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}}

Homebrew tap customization

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

# goreleaser.ymlbrew:# Reporitory to push the tap to.github:owner:username: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"# Your app's homepage# Default is emptyhomepage:"https://example.com/"# Your app's description# Default is emptydescription:"Software to create fast and easy drum rolls."# Dependencies of your packagedependencies:    -git    -zsh# Packages that conflict with your packageconflicts:    -svn    -bash# Packages that run as a serviceplist:|<?xml version="1.0" encoding="UTF-8"?>...# Custom install script for brew. Default: "bin.install "program"install:|bin.install "program"...

By defining thebrew section, GoReleaser will take care of publishing the Homebrew tap.Assuming that the current tag isv1.2.3, the above config will generate aprogram.rb formula in theFormula folder ofuser/homebrew-tap repository:

classProgram <Formuladesc"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"definstallbin.install"program"endend

FPM build customization

GoReleaser can be wired tofpm to generate.deb,.rpm and other archives. Check itswiki for more info.

# goreleaser.ymlfpm:# Your app's vendor# Default is emptyvendor:Drum Roll Inc.# Your app's homepage# Default is emptyhomepage:https://example.com/# Your app's maintainer (probably you)# Default is emptymaintainer:Drummer <drum-roll@example.com># Your app's description# Default is emptydescription:Software to create fast and easy drum rolls.# Your app's license# Default is emptylicense:Apache 2.0# Formats to generate as outputformats:    -deb    -rpm# Dependencies of your packagedependencies:    -git    -zsh# Packages that conflict with your packageconflicts:    -svn    -bash

Note that GoReleaser will not installfpm nor any of its dependencies for you.

Custom release notes

You can have a markdown file previously created with the release notes, andpass it down to goreleaser with the--release-notes=FILE flag.

Integration with CI

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

# .travis.ymlafter_success:  -test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash

Here is how to do it withCircleCI:

# circle.ymldeployment:tag:tag:/v[0-9]+(\.[0-9]+)*(-.*)*/owner:usercommands:      -curl -sL https://git.io/goreleaser | bash

Note that if you test multiple versions or multiple OSes you probably want to make sure GoReleaser is just run once


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

About

Deliver Go binaries as fast and easily as possible

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go98.4%
  • Makefile1.6%

[8]ページ先頭

©2009-2025 Movatter.jp