github.com/goreleaser/goreleaser@v1.25.1/www/docs/customization/archive.md (about)

     1  # Archives
     2  
     3  The binaries built will be archived together with the `README` and `LICENSE` files into a
     4  `tar.gz` file. In the `archives` section you can customize the archive name,
     5  additional files, and format.
     6  
     7  Here is a commented `archives` section with all fields specified:
     8  
     9  ```yaml
    10  # .goreleaser.yaml
    11  archives:
    12    - #
    13      # ID of this archive.
    14      #
    15      # Default: 'default'
    16      id: my-archive
    17  
    18      # Builds reference which build instances should be archived in this archive.
    19      builds:
    20        - default
    21  
    22      # Archive format.
    23      #
    24      # If format is `binary`, no archives are created and the binaries are instead
    25      # uploaded directly.
    26      #
    27      # Valid options are `tar.gz`, `tgz`, `tar.xz`, `txz`, tar`, `gz`, `zip`, and `binary`.
    28      # Default: 'tar.gz'
    29      format: zip
    30  
    31      # This will create an archive without any binaries, only the files are there.
    32      # The name template must not contain any references to `Os`, `Arch` and etc, since the archive will be meta.
    33      #
    34      # Since: v1.9
    35      # Templates: allowed
    36      meta: true
    37  
    38      # Archive name.
    39      #
    40      # Default:
    41      # - if format is `binary`:
    42      #   - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
    43      # - if format is anything else:
    44      #   - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
    45      # Templates: allowed
    46      name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
    47  
    48      # Sets the given file info to all the binaries included from the `builds`.
    49      #
    50      # Default: copied from the source binary.
    51      # Since: v1.14
    52      builds_info:
    53        group: root
    54        owner: root
    55        mode: 0644
    56        # format is `time.RFC3339Nano`
    57        mtime: 2008-01-02T15:04:05Z
    58  
    59      # Set this to true if you want all files in the archive to be in a single directory.
    60      # If set to true and you extract the archive 'goreleaser_Linux_arm64.tar.gz',
    61      # you'll get a directory 'goreleaser_Linux_arm64'.
    62      # If set to false, all files are extracted separately.
    63      # You can also set it to a custom directory name (templating is supported).
    64      wrap_in_directory: true
    65  
    66      # If set to true, will strip the parent directories away from binary files.
    67      #
    68      # This might be useful if you have your binary be built with a sub-directory
    69      # for some reason, but do no want that sub-directory inside the archive.
    70      #
    71      # Since: v1.11
    72      strip_binary_directory: true
    73  
    74      # This will make the destination paths be relative to the longest common
    75      # path prefix between all the files matched and the source glob.
    76      # Enabling this essentially mimic the behavior of nfpm's contents section.
    77      # It will be the default by June 2023.
    78      #
    79      # Since: v1.14
    80      rlcp: true
    81  
    82      # Can be used to change the archive formats for specific GOOSs.
    83      # Most common use case is to archive as zip on Windows.
    84      format_overrides:
    85        - # Which GOOS to override the format for.
    86          goos: windows
    87  
    88          # The format to use for the given GOOS.
    89          #
    90          # Valid options are `tar.gz`, `tgz`, `tar.xz`, `txz`, tar`, `gz`, `zip`, `binary`, and `none`.
    91          format: zip
    92  
    93      # Additional files/globs you want to add to the archive.
    94      #
    95      # Default: [ 'LICENSE*', 'README*', 'CHANGELOG', 'license*', 'readme*', 'changelog']
    96      # Templates: allowed
    97      files:
    98        - LICENSE.txt
    99        - README_{{.Os}}.md
   100        - CHANGELOG.md
   101        - docs/*
   102        - design/*.png
   103        - templates/**/*
   104        # a more complete example, check the globbing deep dive below
   105        - src: "*.md"
   106          dst: docs
   107  
   108          # Strip parent directories when adding files to the archive.
   109          strip_parent: true
   110  
   111          # File info.
   112          # Not all fields are supported by all formats available formats.
   113          #
   114          # Default: copied from the source file
   115          info:
   116            # Templates: allowed (since v1.14)
   117            owner: root
   118  
   119            # Templates: allowed (since v1.14)
   120            group: root
   121  
   122            # Must be in time.RFC3339Nano format.
   123            #
   124            # Templates: allowed (since v1.14)
   125            mtime: "{{ .CommitDate }}"
   126  
   127            # File mode.
   128            mode: 0644
   129  
   130      # Additional templated files to add to the archive.
   131      # Those files will have their contents pass through the template engine,
   132      # and its results will be added to the archive.
   133      #
   134      # This feature is only available in GoReleaser Pro.
   135      # Since: v1.17 (pro)
   136      # Templates: allowed
   137      templated_files:
   138        # a more complete example, check the globbing deep dive below
   139        - src: "LICENSE.md.tpl"
   140          dst: LICENSE.md
   141  
   142          # File info.
   143          # Not all fields are supported by all formats available formats.
   144          #
   145          # Default: copied from the source file
   146          info:
   147            # Templateable (since v1.14)
   148            owner: root
   149  
   150            # Templateable (since v1.14)
   151            group: root
   152  
   153            # Must be in time.RFC3339Nano format.
   154            # Templateable (since v1.14)
   155            mtime: "{{ .CommitDate }}"
   156  
   157            # File mode.
   158            mode: 0644
   159  
   160      # Before and after hooks for each archive.
   161      # Skipped if archive format is binary.
   162      # This feature is only available in GoReleaser Pro.
   163      hooks:
   164        before:
   165          - make clean # simple string
   166          - cmd: go generate ./... # specify cmd
   167          - cmd: go mod tidy
   168            output: true # always prints command output
   169            dir: ./submodule # specify command working directory
   170          - cmd: touch {{ .Env.FILE_TO_TOUCH }}
   171            env:
   172              - "FILE_TO_TOUCH=something-{{ .ProjectName }}" # specify hook level environment variables
   173  
   174        after:
   175          - make clean
   176          - cmd: cat *.yaml
   177            dir: ./submodule
   178          - cmd: touch {{ .Env.RELEASE_DONE }}
   179            env:
   180              - "RELEASE_DONE=something-{{ .ProjectName }}" # specify hook level environment variables
   181  
   182      # Disables the binary count check.
   183      allow_different_binary_count: true
   184  ```
   185  
   186  !!! success "GoReleaser Pro"
   187  
   188      Archive hooks is a [GoReleaser Pro feature](/pro/).
   189  
   190  !!! tip
   191  
   192      Learn more about the [name template engine](/customization/templates/).
   193  
   194  !!! tip
   195  
   196      You can add entire directories, its sub-directories and files by using the
   197      glob notation, for example: `mydirectory/**/*`.
   198  
   199  !!! warning
   200  
   201      The `files` and `wrap_in_directory` options are ignored if `format` is `binary`.
   202  
   203  !!! warning
   204  
   205      The `name_template` option will not reflect the filenames under the `dist`
   206      directory if `format` is `binary`.
   207      The template will be applied only where the binaries are uploaded (e.g.
   208      GitHub releases).
   209  
   210  ## Deep diving into the globbing options
   211  
   212  We'll walk through what happens in each case using some examples.
   213  
   214  ```yaml
   215  # ...
   216  files:
   217    # Adds `README.md` at the root of the archive:
   218    - README.md
   219  
   220    # Adds all `md` files to the root of the archive:
   221    - "*.md"
   222  
   223    # Adds all `md` files to the root of the archive:
   224    - src: "*.md"
   225  
   226    # Adds all `md` files in the current directory to a `docs` directory in the
   227    # archive:
   228    - src: "*.md"
   229      dst: docs
   230  
   231    # Recursively adds all `go` files to a `source` directory in the archive.
   232    # in this case, `cmd/myapp/main.go` will be added as `source/cmd/myapp/main.go`
   233    - src: "**/*.go"
   234      dst: source
   235  
   236    # Recursively adds all `go` files to a `source` directory in the archive,
   237    # stripping their parent directory.
   238    # In this case, `cmd/myapp/main.go` will be added as `source/main.go`:
   239    - src: "**/*.go"
   240      dst: source
   241      strip_parent: true
   242  # ...
   243  ```
   244  
   245  ## Packaging only the binaries
   246  
   247  Since GoReleaser will always add the `README` and `LICENSE` files to the
   248  archive if the file list is empty, you'll need to provide a filled `files`
   249  on the archive section.
   250  
   251  A working hack is to use something like this:
   252  
   253  ```yaml
   254  # .goreleaser.yaml
   255  archives:
   256    - files:
   257        - none*
   258  ```
   259  
   260  This would add all files matching the glob `none*`, provide that you don't
   261  have any files matching that glob, only the binary will be added to the
   262  archive.
   263  
   264  For more information, check [#602](https://github.com/goreleaser/goreleaser/issues/602)
   265  
   266  ## A note about Gzip
   267  
   268  Gzip is a compression-only format, therefore, it couldn't have more than one
   269  file inside.
   270  
   271  Presumably, you'll want that file to be the binary, so, your archive section
   272  will probably look like this:
   273  
   274  ```yaml
   275  # .goreleaser.yaml
   276  archives:
   277    - format: gz
   278      files:
   279        - none*
   280  ```
   281  
   282  This should create `.gz` files with the binaries only, which should be
   283  extracted with something like `gzip -d file.gz`.
   284  
   285  !!! warning
   286  
   287      You won't be able to package multiple builds in a single archive either.
   288      The alternative is to declare multiple archives filtering by build ID.
   289  
   290  ## Disable archiving
   291  
   292  You can do that by setting `format` to `binary`:
   293  
   294  ```yaml
   295  # .goreleaser.yaml
   296  archives:
   297    - format: binary
   298  ```
   299  
   300  Make sure to check the rest of the documentation above, as doing this has some
   301  implications.
   302  
   303  If you have customization that might rely on archives, for instance,
   304  `brews.install`, make sure to fix them too.