2021-10-30 14:50:23 +02:00
# Archives
2017-09-10 22:07:28 +02:00
2017-10-01 18:57:52 +02:00
The binaries built will be archived together with the `README` and `LICENSE` files into a
2019-04-16 15:19:15 +02:00
`tar.gz` file. In the `archives` section you can customize the archive name,
2017-10-01 18:57:52 +02:00
additional files, and format.
2017-09-10 22:07:28 +02:00
2019-04-16 15:19:15 +02:00
Here is a commented `archives` section with all fields specified:
2017-09-10 22:07:28 +02:00
2020-05-10 23:59:21 +02:00
```yaml
2021-12-23 02:52:01 +02:00
# .goreleaser.yaml
2019-04-16 15:19:15 +02:00
archives:
-
# ID of this archive.
# Defaults to `default` .
id: my-archive
# Builds reference which build instances should be archived in this archive.
2022-05-10 14:17:30 +02:00
# Default is empty, which includes all builds.
2019-04-16 15:19:15 +02:00
builds:
- default
2021-09-01 04:09:18 +02:00
# Archive format. Valid options are `tar.gz` , `tar.xz` , `tar` , `gz` , `zip` and `binary` .
2020-10-06 03:54:41 +02:00
# If format is `binary` , no archives are created and the binaries are instead
# uploaded directly.
# Default is `tar.gz` .
format: zip
2022-05-10 14:17:30 +02:00
# This will create an archive without any binaries, only the files are there.
# The name template must not contain any references to `Os` , `Arch` and etc, since the archive will be meta.
2022-06-24 03:40:25 +02:00
# Default is false.
2022-05-10 14:17:30 +02:00
meta: true
2019-04-16 15:19:15 +02:00
# Archive name template.
# Defaults:
2020-04-13 17:01:14 +02:00
# - if format is `tar.gz` , `tar.xz` , `gz` or `zip` :
2022-04-14 02:29:39 +02:00
# - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
2019-04-16 15:19:15 +02:00
# - if format is `binary` :
2022-04-14 02:29:39 +02:00
# - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
2019-04-16 15:19:15 +02:00
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
# Replacements for GOOS and GOARCH in the archive name.
# Keys should be valid GOOSs or GOARCHs.
# Values are the respective replacements.
# Default is empty.
replacements:
amd64: 64-bit
386: 32-bit
darwin: macOS
linux: Tux
2022-08-07 17:24:11 +02:00
# Set this to true if you want all files in the archive to be in a single directory.
2019-04-16 15:19:15 +02:00
# If set to true and you extract the archive 'goreleaser_Linux_arm64.tar.gz',
2022-08-07 17:24:11 +02:00
# you'll get a folder 'goreleaser_Linux_arm64'.
2019-04-16 15:19:15 +02:00
# If set to false, all files are extracted separately.
# You can also set it to a custom folder name (templating is supported).
# Default is false.
wrap_in_directory: true
2022-08-16 03:53:36 +02:00
# If set to true, will strip the parent directories away from binary files.
2022-08-16 07:05:10 +02:00
#
2022-08-16 03:53:36 +02:00
# This might be useful if you have your binary be built with a subdir for some reason, but do no want that subdir inside the archive.
2022-08-16 07:05:10 +02:00
#
2022-08-16 03:53:36 +02:00
# Default is false.
strip_parent_binary_folder: true
2019-04-16 15:19:15 +02:00
# Can be used to change the archive formats for specific GOOSs.
# Most common use case is to archive as zip on Windows.
# Default is empty.
format_overrides:
- goos: windows
format: zip
2020-03-04 05:52:43 +02:00
# Additional files/template/globs you want to add to the archive.
2021-07-22 03:09:02 +02:00
# Defaults are any files matching `LICENSE*` , `README*` , `CHANGELOG*` ,
# `license*` , `readme*` and `changelog*` .
2019-04-16 15:19:15 +02:00
files:
- LICENSE.txt
2020-03-04 05:52:43 +02:00
- README_{{.Os}}.md
2019-04-16 15:19:15 +02:00
- CHANGELOG.md
- docs/*
- design/*.png
- templates/**/*
2021-09-16 19:31:57 +02:00
# a more complete example, check the globbing deep dive below
2021-07-22 03:09:02 +02:00
- src: '*.md'
dst: docs
# Strip parent folders when adding files to the archive.
# Default: false
strip_parent: true
# File info.
# Not all fields are supported by all formats available formats.
# Defaults to the file info of the actual file if not provided.
info:
owner: root
group: root
mode: 0644
# format is `time.RFC3339Nano`
mtime: 2008-01-02T15:04:05Z
2020-10-13 22:57:08 +02:00
2022-08-03 20:07:38 +02:00
# Before and after hooks for each archive.
# Skipped if archive format is binary.
# This feature is available in [GoReleaser Pro ](/pro ) only.
hooks:
before:
- make clean # simple string
- cmd: go generate ./... # specify cmd
- cmd: go mod tidy
output: true # always prints command output
dir: ./submodule # specify command working directory
- cmd: touch {{ .Env.FILE_TO_TOUCH }}
env:
- 'FILE_TO_TOUCH=something-{{ .ProjectName }}' # specify hook level environment variables
after:
- make clean
- cmd: cat *.yaml
dir: ./submodule
- cmd: touch {{ .Env.RELEASE_DONE }}
env:
- 'RELEASE_DONE=something-{{ .ProjectName }}' # specify hook level environment variables
2020-10-13 22:57:08 +02:00
# Disables the binary count check.
# Default: false
allow_different_binary_count: true
2017-09-10 22:07:28 +02:00
```
2017-12-08 00:21:36 +02:00
2022-08-03 20:07:38 +02:00
!!! success "GoReleaser Pro"
Archive hooks is a [GoReleaser Pro feature ](/pro/ ).
2020-05-10 23:59:21 +02:00
!!! tip
2020-11-19 22:31:26 +02:00
Learn more about the [name template engine ](/customization/templates/ ).
2018-03-12 02:07:03 +02:00
2020-10-06 03:54:41 +02:00
!!! tip
You can add entire folders, its subfolders and files by using the glob notation,
for example: `myfolder/**/*` .
!!! warning
The `files` and `wrap_in_directory` options are ignored if `format` is `binary` .
!!! warning
The `name_template` option will not reflect the filenames under the `dist` folder if `format` is `binary` .
The template will be applied only where the binaries are uploaded (e.g. GitHub releases).
2018-07-20 01:32:28 +02:00
2021-07-22 03:09:02 +02:00
## Deep diving into the globbing options
We'll walk through what happens in each case using some examples.
```yaml
# ...
files:
# Adds `README.md` at the root of the archive:
- README.md
# Adds all `md` files to the root of the archive:
- '*.md'
# Adds all `md` files to the root of the archive:
- src: '*.md'
# Adds all `md` files in the current folder to a `docs` folder in the archive:
- src: '*.md'
dst: docs
# Recursively adds all `go` files to a `source` folder in the archive.
# in this case, `cmd/myapp/main.go` will be added as `source/cmd/myapp/main.go`
- src: '**/*.go'
dst: source
# Recursively adds all `go` files to a `source` folder in the archive, stripping their parent folder.
# In this case, `cmd/myapp/main.go` will be added as `source/main.go`:
- src: '**/*.go'
dst: source
strip_parent: true
# ...
```
2018-03-12 02:07:03 +02:00
## Packaging only the binaries
Since GoReleaser will always add the `README` and `LICENSE` files to the
archive if the file list is empty, you'll need to provide a filled `files`
on the archive section.
A working hack is to use something like this:
```yaml
2021-12-23 02:52:01 +02:00
# .goreleaser.yaml
2019-04-16 15:19:15 +02:00
archives:
- files:
2018-03-12 02:07:03 +02:00
- none*
```
This would add all files matching the glob `none*` , provide that you don't
have any files matching that glob, only the binary will be added to the
archive.
For more information, check [#602 ](https://github.com/goreleaser/goreleaser/issues/602 )
2019-02-07 16:12:20 +02:00
## A note about Gzip
Gzip is a compression-only format, therefore, it couldn't have more than one
file inside.
Presumably, you'll want that file to be the binary, so, your archive section
will probably look like this:
```yaml
2021-12-23 02:52:01 +02:00
# .goreleaser.yaml
2019-10-17 21:17:24 +02:00
archives:
- format: gz
2019-02-07 16:12:20 +02:00
files:
- none*
```
This should create `.gz` files with the binaries only, which should be
extracted with something like `gzip -d file.gz` .
2020-10-06 03:54:41 +02:00
!!! warning
You won't be able to package multiple builds in a single archive either.
The alternative is to declare multiple archives filtering by build ID.
2020-05-10 17:50:07 +02:00
## Disable archiving
You can do that by setting `format` to `binary` :
```yaml
2021-12-23 02:52:01 +02:00
# .goreleaser.yaml
2020-05-10 17:50:07 +02:00
archives:
- format: binary
```
2020-10-06 03:54:41 +02:00
Make sure to check the rest of the documentation above, as doing this has some
implications.