2021-10-30 09:50:23 -03:00
# Archives
2017-09-10 17:07:28 -03: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 10:19:15 -03: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 17:07:28 -03:00
2019-04-16 10:19:15 -03:00
Here is a commented `archives` section with all fields specified:
2017-09-10 17:07:28 -03:00
2020-05-10 18:59:21 -03:00
```yaml
2021-12-23 01:52:01 +01:00
# .goreleaser.yaml
2019-04-16 10:19:15 -03:00
archives:
2023-07-06 16:51:23 +00:00
- #
2019-04-16 10:19:15 -03:00
# ID of this archive.
2023-04-02 17:16:21 -03:00
#
# Default: 'default'
2019-04-16 10:19:15 -03:00
id: my-archive
# Builds reference which build instances should be archived in this archive.
builds:
2023-07-06 16:51:23 +00:00
- default
2019-04-16 10:19:15 -03:00
2024-03-29 16:20:05 -03:00
# Archive format.
#
2020-10-05 22:54:41 -03:00
# If format is `binary` , no archives are created and the binaries are instead
# uploaded directly.
2023-04-02 17:16:21 -03:00
#
2024-05-03 10:29:55 -03:00
# Valid options are:
# - `tar.gz`
# - `tgz`
# - `tar.xz`
# - `txz`
# - `tar.zst` (Since v1.26)
# - `tar`
# - `gz`
# - `zip`
# - `binary`
#
2023-04-02 17:16:21 -03:00
# Default: 'tar.gz'
2020-10-05 22:54:41 -03:00
format: zip
2022-05-10 09:17:30 -03: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-09-11 16:54:51 -03:00
#
2023-04-02 17:16:21 -03:00
# Since: v1.9
# Templates: allowed
2022-05-10 09:17:30 -03:00
meta: true
2023-04-02 17:16:21 -03:00
# Archive name.
#
# Default:
2019-04-16 10:19:15 -03:00
# - if format is `binary` :
2022-04-13 21:29:39 -03:00
# - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
2023-04-08 02:40:49 +00:00
# - if format is anything else:
# - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
2023-04-02 17:16:21 -03:00
# Templates: allowed
2019-04-16 10:19:15 -03:00
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
2022-12-14 12:16:03 -03:00
# Sets the given file info to all the binaries included from the `builds` .
#
2023-04-02 17:16:21 -03:00
# Default: copied from the source binary.
# Since: v1.14
2022-12-14 12:16:03 -03:00
builds_info:
group: root
owner: root
mode: 0644
# format is `time.RFC3339Nano`
mtime: 2008-01-02T15:04:05Z
2022-08-07 12:24:11 -03:00
# Set this to true if you want all files in the archive to be in a single directory.
2019-04-16 10:19:15 -03:00
# If set to true and you extract the archive 'goreleaser_Linux_arm64.tar.gz',
2024-04-01 10:01:56 -03:00
# you'll get a directory 'goreleaser_Linux_arm64'.
2019-04-16 10:19:15 -03:00
# If set to false, all files are extracted separately.
2024-04-01 10:01:56 -03:00
# You can also set it to a custom directory name (templating is supported).
2019-04-16 10:19:15 -03:00
wrap_in_directory: true
2022-08-15 22:53:36 -03:00
# If set to true, will strip the parent directories away from binary files.
2022-08-16 02:05:10 -03:00
#
2024-04-01 10:01:56 -03:00
# This might be useful if you have your binary be built with a sub-directory
# for some reason, but do no want that sub-directory inside the archive.
2022-08-16 02:05:10 -03:00
#
2023-04-02 17:16:21 -03:00
# Since: v1.11
2024-04-01 10:01:56 -03:00
strip_binary_directory: true
2022-08-15 22:53:36 -03:00
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
# This will make the destination paths be relative to the longest common
# path prefix between all the files matched and the source glob.
# Enabling this essentially mimic the behavior of nfpm's contents section.
# It will be the default by June 2023.
#
2023-04-02 17:16:21 -03:00
# Since: v1.14
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
rlcp: true
2019-04-16 10:19:15 -03:00
# Can be used to change the archive formats for specific GOOSs.
# Most common use case is to archive as zip on Windows.
format_overrides:
2024-03-29 16:20:05 -03:00
- # Which GOOS to override the format for.
goos: windows
# The format to use for the given GOOS.
#
# Valid options are `tar.gz` , `tgz` , `tar.xz` , `txz` , tar`, ` gz`, ` zip`, ` binary`, and ` none`.
2019-04-16 10:19:15 -03:00
format: zip
2023-04-02 17:16:21 -03:00
# Additional files/globs you want to add to the archive.
#
# Default: [ 'LICENSE*', 'README*', 'CHANGELOG', 'license*', 'readme*', 'changelog']
# Templates: allowed
2019-04-16 10:19:15 -03:00
files:
- LICENSE.txt
2020-03-04 00:52:43 -03:00
- README_{{.Os}}.md
2019-04-16 10:19:15 -03:00
- CHANGELOG.md
- docs/*
- design/*.png
- templates/**/*
2021-09-16 14:31:57 -03:00
# a more complete example, check the globbing deep dive below
2023-07-06 16:51:23 +00:00
- src: "*.md"
2021-07-21 22:09:02 -03:00
dst: docs
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
2024-04-01 10:01:56 -03:00
# Strip parent directories when adding files to the archive.
2021-07-21 22:09:02 -03:00
strip_parent: true
feat: better archives relative paths (#3656)
with this patch, a config like:
```yaml
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
rlcp: true
files:
- src: "build/**/*"
dst: .
nfpms:
- package_name: foo
contents:
- src: "build/**/*"
dst: usr/share/foo
formats:
- apk
```
will eval this:
<img width="1384" alt="CleanShot 2022-12-21 at 22 21 00@2x"
src="https://user-images.githubusercontent.com/245435/209034244-7c31b5f7-cfcd-4825-bb2f-7dd463c5286a.png">
as much as I would like to make this the default, it would be a breaking
change, so we really can't do it.
If `dst` is empty, it'll have the same behavior as before (no rlcp), and
if `strip_parent` is set, it will also still have the same behavior.
Finally, if the format is binary, `rlcp` is ignored too (as it doesn't
make sense).
So, this only changes if:
- your format is not binary; and
- you have files with `src` and `dst` set
Then, goreleaser will warn you to set `rlcp: true`.
## todo
- [x] docs
- [x] more tests probably
- [x] any ideas for a better name for the new config option?
fixes #3655
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-27 17:42:55 -03:00
2021-07-21 22:09:02 -03:00
# File info.
# Not all fields are supported by all formats available formats.
2023-04-02 17:16:21 -03:00
#
# Default: copied from the source file
2021-07-21 22:09:02 -03:00
info:
2023-04-02 17:16:21 -03:00
# Templates: allowed (since v1.14)
2021-07-21 22:09:02 -03:00
owner: root
2022-12-14 12:16:43 -03:00
2023-04-02 17:16:21 -03:00
# Templates: allowed (since v1.14)
2021-07-21 22:09:02 -03:00
group: root
2022-12-14 12:16:43 -03:00
# Must be in time.RFC3339Nano format.
2023-04-02 17:16:21 -03:00
#
# Templates: allowed (since v1.14)
2023-07-06 16:51:23 +00:00
mtime: "{{ .CommitDate }}"
2022-12-14 12:16:43 -03:00
# File mode.
2021-07-21 22:09:02 -03:00
mode: 0644
2020-10-13 17:57:08 -03:00
2023-03-29 22:23:53 -03:00
# Additional templated files to add to the archive.
# Those files will have their contents pass through the template engine,
# and its results will be added to the archive.
#
2023-03-30 13:26:03 -03:00
# This feature is only available in GoReleaser Pro.
2024-02-27 13:56:24 +01:00
# Since: v1.17 (pro)
2023-04-02 17:16:21 -03:00
# Templates: allowed
2023-07-06 16:51:23 +00:00
templated_files:
2023-03-29 22:23:53 -03:00
# a more complete example, check the globbing deep dive below
2023-07-06 16:51:23 +00:00
- src: "LICENSE.md.tpl"
2023-03-29 22:23:53 -03:00
dst: LICENSE.md
# File info.
# Not all fields are supported by all formats available formats.
2023-04-02 17:16:21 -03:00
#
# Default: copied from the source file
2023-03-29 22:23:53 -03:00
info:
2023-09-04 14:12:01 +00:00
# Templateable (since v1.14)
2023-03-29 22:23:53 -03:00
owner: root
2023-04-07 22:53:15 -03:00
2023-09-04 14:12:01 +00:00
# Templateable (since v1.14)
2023-03-29 22:23:53 -03:00
group: root
2023-04-07 22:53:15 -03:00
2023-03-29 22:23:53 -03:00
# Must be in time.RFC3339Nano format.
2023-09-04 14:12:01 +00:00
# Templateable (since v1.14)
2023-07-06 16:51:23 +00:00
mtime: "{{ .CommitDate }}"
2023-04-07 22:53:15 -03:00
# File mode.
2023-03-29 22:23:53 -03:00
mode: 0644
2022-08-03 15:07:38 -03:00
# Before and after hooks for each archive.
# Skipped if archive format is binary.
2023-03-30 13:26:03 -03:00
# This feature is only available in GoReleaser Pro.
2022-08-03 15:07:38 -03:00
hooks:
before:
2023-07-06 16:51:23 +00:00
- 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
2022-08-03 15:07:38 -03:00
after:
2023-07-06 16:51:23 +00:00
- make clean
- cmd: cat *.yaml
dir: ./submodule
- cmd: touch {{ .Env.RELEASE_DONE }}
env:
- "RELEASE_DONE=something-{{ .ProjectName }}" # specify hook level environment variables
2022-08-03 15:07:38 -03:00
2020-10-13 17:57:08 -03:00
# Disables the binary count check.
allow_different_binary_count: true
2017-09-10 17:07:28 -03:00
```
2017-12-07 23:21:36 +01:00
2022-08-03 15:07:38 -03:00
!!! success "GoReleaser Pro"
2023-07-06 16:51:23 +00:00
2022-08-03 15:07:38 -03:00
Archive hooks is a [GoReleaser Pro feature ](/pro/ ).
2020-05-10 18:59:21 -03:00
!!! tip
2023-07-06 16:51:23 +00:00
2020-11-19 12:31:26 -08:00
Learn more about the [name template engine ](/customization/templates/ ).
2018-03-11 21:07:03 -03:00
2020-10-05 22:54:41 -03:00
!!! tip
2023-07-06 16:51:23 +00:00
2024-04-01 10:01:56 -03:00
You can add entire directories, its sub-directories and files by using the
glob notation, for example: `mydirectory/**/*` .
2020-10-05 22:54:41 -03:00
!!! warning
2023-07-06 16:51:23 +00:00
2020-10-05 22:54:41 -03:00
The `files` and `wrap_in_directory` options are ignored if `format` is `binary` .
!!! warning
2023-07-06 16:51:23 +00:00
2024-04-01 10:01:56 -03:00
The `name_template` option will not reflect the filenames under the `dist`
directory if `format` is `binary` .
The template will be applied only where the binaries are uploaded (e.g.
GitHub releases).
2018-07-19 20:32:28 -03:00
2021-07-21 22:09:02 -03:00
## Deep diving into the globbing options
We'll walk through what happens in each case using some examples.
```yaml
# ...
files:
2023-07-06 16:51:23 +00:00
# Adds `README.md` at the root of the archive:
- README.md
2021-07-21 22:09:02 -03:00
2023-07-06 16:51:23 +00:00
# Adds all `md` files to the root of the archive:
- "*.md"
2021-07-21 22:09:02 -03:00
2023-07-06 16:51:23 +00:00
# Adds all `md` files to the root of the archive:
- src: "*.md"
2021-07-21 22:09:02 -03:00
2024-04-01 10:01:56 -03:00
# Adds all `md` files in the current directory to a `docs` directory in the
# archive:
2023-07-06 16:51:23 +00:00
- src: "*.md"
dst: docs
2021-07-21 22:09:02 -03:00
2024-04-01 10:01:56 -03:00
# Recursively adds all `go` files to a `source` directory in the archive.
2023-07-06 16:51:23 +00:00
# in this case, `cmd/myapp/main.go` will be added as `source/cmd/myapp/main.go`
- src: "**/*.go"
dst: source
2021-07-21 22:09:02 -03:00
2024-04-01 10:01:56 -03:00
# Recursively adds all `go` files to a `source` directory in the archive,
# stripping their parent directory.
2023-07-06 16:51:23 +00:00
# In this case, `cmd/myapp/main.go` will be added as `source/main.go` :
- src: "**/*.go"
dst: source
strip_parent: true
2021-07-21 22:09:02 -03:00
# ...
```
2018-03-11 21:07:03 -03: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 01:52:01 +01:00
# .goreleaser.yaml
2019-04-16 10:19:15 -03:00
archives:
2023-07-06 16:51:23 +00:00
- files:
- none*
2018-03-11 21:07:03 -03:00
```
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 12: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 01:52:01 +01:00
# .goreleaser.yaml
2019-10-17 16:17:24 -03:00
archives:
2023-07-06 16:51:23 +00:00
- format: gz
files:
- none*
2019-02-07 12:12:20 -02:00
```
This should create `.gz` files with the binaries only, which should be
extracted with something like `gzip -d file.gz` .
2020-10-05 22:54:41 -03:00
!!! warning
2023-07-06 16:51:23 +00:00
2020-10-05 22:54:41 -03:00
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 12:50:07 -03:00
## Disable archiving
You can do that by setting `format` to `binary` :
```yaml
2021-12-23 01:52:01 +01:00
# .goreleaser.yaml
2020-05-10 12:50:07 -03:00
archives:
2023-07-06 16:51:23 +00:00
- format: binary
2020-05-10 12:50:07 -03:00
```
2020-10-05 22:54:41 -03:00
Make sure to check the rest of the documentation above, as doing this has some
implications.
2023-03-13 09:39:41 -03:00
If you have customization that might rely on archives, for instance,
`brews.install` , make sure to fix them too.