You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-13 01:30:50 +02:00
@ -11,7 +11,7 @@ Here is a commented `builds` section with all fields specified:
|
|||||||
# .goreleaser.yaml
|
# .goreleaser.yaml
|
||||||
builds:
|
builds:
|
||||||
# You can have multiple builds defined as a yaml list
|
# You can have multiple builds defined as a yaml list
|
||||||
-
|
- #
|
||||||
# ID of the build.
|
# ID of the build.
|
||||||
#
|
#
|
||||||
# Default: Binary name
|
# Default: Binary name
|
||||||
@ -183,7 +183,7 @@ builds:
|
|||||||
# Set the modified timestamp on the output binary, typically
|
# Set the modified timestamp on the output binary, typically
|
||||||
# you would do this to ensure a build was reproducible. Pass
|
# you would do this to ensure a build was reproducible. Pass
|
||||||
# empty string to skip modifying the output.
|
# empty string to skip modifying the output.
|
||||||
mod_timestamp: '{{ .CommitTimestamp }}'
|
mod_timestamp: "{{ .CommitTimestamp }}"
|
||||||
|
|
||||||
# Hooks can be used to customize the final binary,
|
# Hooks can be used to customize the final binary,
|
||||||
# for example, to run generators.
|
# for example, to run generators.
|
||||||
@ -241,8 +241,8 @@ builds:
|
|||||||
- goos: darwin
|
- goos: darwin
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
goamd64: v1
|
goamd64: v1
|
||||||
goarm: ''
|
goarm: ""
|
||||||
gomips: ''
|
gomips: ""
|
||||||
ldflags:
|
ldflags:
|
||||||
- foo
|
- foo
|
||||||
tags:
|
tags:
|
||||||
@ -256,9 +256,11 @@ builds:
|
|||||||
```
|
```
|
||||||
|
|
||||||
!!! tip
|
!!! tip
|
||||||
|
|
||||||
Learn more about the [name template engine](/customization/templates/).
|
Learn more about the [name template engine](/customization/templates/).
|
||||||
|
|
||||||
!!! info
|
!!! info
|
||||||
|
|
||||||
First-class build targets are gathered by running:
|
First-class build targets are gathered by running:
|
||||||
```sh
|
```sh
|
||||||
go tool dist list -json | jq -r '.[] | select(.FirstClass) | [.GOOS, .GOARCH] | @tsv'
|
go tool dist list -json | jq -r '.[] | select(.FirstClass) | [.GOOS, .GOARCH] | @tsv'
|
||||||
@ -300,13 +302,13 @@ following build details are exposed:
|
|||||||
|
|
||||||
<!-- to format the tables, use: https://tabletomarkdown.com/format-markdown-table/ -->
|
<!-- to format the tables, use: https://tabletomarkdown.com/format-markdown-table/ -->
|
||||||
|
|
||||||
Key |Description
|
| Key | Description |
|
||||||
-------|---------------------------------
|
| ------- | --------------------------------- |
|
||||||
.Os |`GOOS`
|
| .Os | `GOOS` |
|
||||||
.Arch |`GOARCH`
|
| .Arch | `GOARCH` |
|
||||||
.Arm |`GOARM`
|
| .Arm | `GOARM` |
|
||||||
.Ext |Extension, e.g. `.exe`
|
| .Ext | Extension, e.g. `.exe` |
|
||||||
.Target|Build target, e.g. `darwin_amd64`
|
| .Target | Build target, e.g. `darwin_amd64` |
|
||||||
|
|
||||||
## Passing environment variables to ldflags
|
## Passing environment variables to ldflags
|
||||||
|
|
||||||
@ -339,8 +341,7 @@ environments.
|
|||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yaml
|
# .goreleaser.yaml
|
||||||
builds:
|
builds:
|
||||||
-
|
- id: "with-hooks"
|
||||||
id: "with-hooks"
|
|
||||||
targets:
|
targets:
|
||||||
- "darwin_amd64"
|
- "darwin_amd64"
|
||||||
- "windows_amd64"
|
- "windows_amd64"
|
||||||
@ -358,15 +359,15 @@ Each hook can also have its own work directory and environment variables:
|
|||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yaml
|
# .goreleaser.yaml
|
||||||
builds:
|
builds:
|
||||||
-
|
- id: "with-hooks"
|
||||||
id: "with-hooks"
|
|
||||||
targets:
|
targets:
|
||||||
- "darwin_amd64"
|
- "darwin_amd64"
|
||||||
- "windows_amd64"
|
- "windows_amd64"
|
||||||
hooks:
|
hooks:
|
||||||
pre:
|
pre:
|
||||||
- cmd: first-script.sh
|
- cmd: first-script.sh
|
||||||
dir: "{{ dir .Dist}}"
|
dir:
|
||||||
|
"{{ dir .Dist}}"
|
||||||
# Always print command output, otherwise only visible in debug mode.
|
# Always print command output, otherwise only visible in debug mode.
|
||||||
# Since: v1.5
|
# Since: v1.5
|
||||||
output: true
|
output: true
|
||||||
@ -381,40 +382,39 @@ available (as these run _after_ the build).
|
|||||||
Additionally the following build details are exposed to both `pre` and `post`
|
Additionally the following build details are exposed to both `pre` and `post`
|
||||||
hooks:
|
hooks:
|
||||||
|
|
||||||
|
|
||||||
<!-- to format the tables, use: https://tabletomarkdown.com/format-markdown-table/ -->
|
<!-- to format the tables, use: https://tabletomarkdown.com/format-markdown-table/ -->
|
||||||
|
|
||||||
Key |Description
|
| Key | Description |
|
||||||
-------|--------------------------------------
|
| ------- | -------------------------------------- |
|
||||||
.Name |Filename of the binary, e.g. `bin.exe`
|
| .Name | Filename of the binary, e.g. `bin.exe` |
|
||||||
.Ext |Extension, e.g. `.exe`
|
| .Ext | Extension, e.g. `.exe` |
|
||||||
.Path |Absolute path to the binary
|
| .Path | Absolute path to the binary |
|
||||||
.Target|Build target, e.g. `darwin_amd64`
|
| .Target | Build target, e.g. `darwin_amd64` |
|
||||||
|
|
||||||
Environment variables are inherited and overridden in the following order:
|
Environment variables are inherited and overridden in the following order:
|
||||||
|
|
||||||
- global (`env`)
|
- global (`env`)
|
||||||
- build (`builds[].env`)
|
- build (`builds[].env`)
|
||||||
- hook (`builds[].hooks.pre[].env` and `builds[].hooks.post[].env`)
|
- hook (`builds[].hooks.pre[].env` and `builds[].hooks.post[].env`)
|
||||||
|
|
||||||
## Go Modules
|
## Go Modules
|
||||||
|
|
||||||
If you use Go 1.11+ with go modules or vgo, when GoReleaser runs it may try to
|
If you use Go 1.11+ with go modules or vgo, when GoReleaser runs it may try to
|
||||||
download the dependencies. Since several builds run in parallel, it is very
|
download the dependencies. Since several builds run in parallel, it is very
|
||||||
likely to fail.
|
likely to fail.
|
||||||
|
|
||||||
You can solve this by running `go mod tidy` before calling `goreleaser` or
|
You can solve this by running `go mod tidy` before calling `goreleaser` or
|
||||||
by adding a [hook][] doing that on your `.goreleaser.yaml` file:
|
by adding a [hook][] doing that on your `.goreleaser.yaml` file:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yaml
|
# .goreleaser.yaml
|
||||||
before:
|
before:
|
||||||
hooks:
|
hooks:
|
||||||
- go mod tidy
|
- go mod tidy
|
||||||
# rest of the file...
|
# rest of the file...
|
||||||
```
|
```
|
||||||
|
|
||||||
[hook]: /customization/hooks
|
[hook]: /customization/hooks
|
||||||
|
|
||||||
## Define Build Tag
|
## Define Build Tag
|
||||||
|
|
||||||
@ -428,20 +428,21 @@ To make your releases, checksums and signatures reproducible, you will need to
|
|||||||
make some (if not all) of the following modifications to the build defaults in
|
make some (if not all) of the following modifications to the build defaults in
|
||||||
GoReleaser:
|
GoReleaser:
|
||||||
|
|
||||||
* Modify `ldflags`: by default `main.Date` is set to the time GoReleaser is run
|
- Modify `ldflags`: by default `main.Date` is set to the time GoReleaser is run
|
||||||
(`{{.Date}}`), you can set this to `{{.CommitDate}}` or just not pass the
|
(`{{.Date}}`), you can set this to `{{.CommitDate}}` or just not pass the
|
||||||
variable.
|
variable.
|
||||||
* Modify `mod_timestamp`: by default this is empty string — which means it'll be
|
- Modify `mod_timestamp`: by default this is empty string — which means it'll be
|
||||||
the compilation time, set to `{{.CommitTimestamp}}` or a constant value
|
the compilation time, set to `{{.CommitTimestamp}}` or a constant value
|
||||||
instead.
|
instead.
|
||||||
* If you do not run your builds from a consistent directory structure, pass
|
- If you do not run your builds from a consistent directory structure, pass
|
||||||
`-trimpath` to `flags`.
|
`-trimpath` to `flags`.
|
||||||
* Remove uses of the `time` template function. This function returns a new value
|
- Remove uses of the `time` template function. This function returns a new value
|
||||||
on every call and is not deterministic.
|
on every call and is not deterministic.
|
||||||
|
|
||||||
## Import pre-built binaries
|
## Import pre-built binaries
|
||||||
|
|
||||||
!!! success "GoReleaser Pro"
|
!!! success "GoReleaser Pro"
|
||||||
|
|
||||||
The prebuilt builder is a [GoReleaser Pro feature](/pro/).
|
The prebuilt builder is a [GoReleaser Pro feature](/pro/).
|
||||||
|
|
||||||
It is also possible to import pre-built binaries into the GoReleaser lifecycle.
|
It is also possible to import pre-built binaries into the GoReleaser lifecycle.
|
||||||
@ -458,8 +459,7 @@ In any case, its pretty easy to do that now:
|
|||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yaml
|
# .goreleaser.yaml
|
||||||
builds:
|
builds:
|
||||||
-
|
- # Set the builder to prebuilt
|
||||||
# Set the builder to prebuilt
|
|
||||||
builder: prebuilt
|
builder: prebuilt
|
||||||
|
|
||||||
# When builder is `prebuilt` there are no defaults for goos, goarch,
|
# When builder is `prebuilt` there are no defaults for goos, goarch,
|
||||||
@ -480,8 +480,17 @@ builds:
|
|||||||
# want to put the binaries elsewhere.
|
# want to put the binaries elsewhere.
|
||||||
# This field is required when using the `prebuilt` builder.
|
# This field is required when using the `prebuilt` builder.
|
||||||
path: output/mybin_{{ .Os }}_{{ .Arch }}{{ with .Amd64 }}_{{ . }}{{ end }}/mybin
|
path: output/mybin_{{ .Os }}_{{ .Arch }}{{ with .Amd64 }}_{{ . }}{{ end }}/mybin
|
||||||
|
|
||||||
|
# Use 'binary' to set the final name of your binary.
|
||||||
|
# This is the name that will be used in archives et al.
|
||||||
|
binary: bin/mybin
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
|
||||||
|
You can think of `prebuilt.path` as being the "external path" and the
|
||||||
|
`binary` as being the "internal path to binary".
|
||||||
|
|
||||||
This example config will import into your release pipeline the following
|
This example config will import into your release pipeline the following
|
||||||
binaries:
|
binaries:
|
||||||
|
|
||||||
@ -495,6 +504,7 @@ itself.
|
|||||||
There is no difference in how the binaries are handled.
|
There is no difference in how the binaries are handled.
|
||||||
|
|
||||||
!!! tip
|
!!! tip
|
||||||
|
|
||||||
A cool tip here, specially when using CGO, is that you can have one
|
A cool tip here, specially when using CGO, is that you can have one
|
||||||
`.goreleaser.yaml` file just for the builds, build each in its own machine
|
`.goreleaser.yaml` file just for the builds, build each in its own machine
|
||||||
with [`goreleaser build --single-target`](/cmd/goreleaser_build/) and
|
with [`goreleaser build --single-target`](/cmd/goreleaser_build/) and
|
||||||
@ -504,11 +514,13 @@ There is no difference in how the binaries are handled.
|
|||||||
builds in different machines in parallel.
|
builds in different machines in parallel.
|
||||||
|
|
||||||
!!! warning
|
!!! warning
|
||||||
|
|
||||||
GoReleaser will try to stat the final path, if any error happens while
|
GoReleaser will try to stat the final path, if any error happens while
|
||||||
doing that (e.g. file does not exist or permission issues),
|
doing that (e.g. file does not exist or permission issues),
|
||||||
GoReleaser will fail.
|
GoReleaser will fail.
|
||||||
|
|
||||||
!!! warning
|
!!! warning
|
||||||
|
|
||||||
When using the `prebuilt` binary, there are no defaults for `goos`,
|
When using the `prebuilt` binary, there are no defaults for `goos`,
|
||||||
`goarch`, `goarm`, `gomips` and `goamd64`.
|
`goarch`, `goarm`, `gomips` and `goamd64`.
|
||||||
You'll need to either provide them or the final `targets` matrix.
|
You'll need to either provide them or the final `targets` matrix.
|
||||||
@ -560,16 +572,15 @@ attempt to configure any additional logic.
|
|||||||
|
|
||||||
GoReleaser will:
|
GoReleaser will:
|
||||||
|
|
||||||
* set the correct file extension for the target OS.
|
- set the correct file extension for the target OS.
|
||||||
* package the generated header file (`.h`) in the release bundle.
|
- package the generated header file (`.h`) in the release bundle.
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yaml
|
# .goreleaser.yaml
|
||||||
builds:
|
builds:
|
||||||
-
|
- id: "my-library"
|
||||||
id: "my-library"
|
|
||||||
|
|
||||||
# Configure the buildmode flag to output a shared library
|
# Configure the buildmode flag to output a shared library
|
||||||
buildmode: "c-shared" # or "c-archive" for a static library
|
buildmode: "c-shared" # or "c-archive" for a static library
|
||||||
@ -596,7 +607,7 @@ set `CC` and `CCX` to the right one:
|
|||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yml
|
# .goreleaser.yml
|
||||||
builds:
|
builds:
|
||||||
- id: mybin
|
- id: mybin
|
||||||
binary: mybin
|
binary: mybin
|
||||||
main: .
|
main: .
|
||||||
goos:
|
goos:
|
||||||
@ -625,7 +636,7 @@ This example uses `if` statements to set `CC` and `CCX`:
|
|||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yml
|
# .goreleaser.yml
|
||||||
builds:
|
builds:
|
||||||
- id: mybin
|
- id: mybin
|
||||||
binary: mybin
|
binary: mybin
|
||||||
main: .
|
main: .
|
||||||
goos:
|
goos:
|
||||||
|
Reference in New Issue
Block a user