2018-07-09 08:57:46 +02:00
|
|
|
---
|
|
|
|
title: Name Templates
|
|
|
|
---
|
|
|
|
|
|
|
|
Several fields in GoReleaser's config file support templating.
|
|
|
|
|
|
|
|
Those fields are often suffixed with `_template`, but sometimes they may not
|
2021-02-11 23:31:46 +02:00
|
|
|
be. The documentation of each section should be explicit about which fields
|
|
|
|
support templating.
|
2018-07-09 08:57:46 +02:00
|
|
|
|
2020-08-25 21:25:06 +02:00
|
|
|
On fields that support templating, these fields are always available:
|
2018-07-09 08:57:46 +02:00
|
|
|
|
2020-07-06 22:09:22 +02:00
|
|
|
| Key | Description |
|
|
|
|
|--------------------|------------------------------------------------------------------------------------------------------------------------------|
|
|
|
|
| `.ProjectName` | the project name |
|
|
|
|
| `.Version` | the version being released (`v` prefix stripped),<br>or `{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}` in case of snapshot release |
|
2020-11-18 20:50:31 +02:00
|
|
|
| `.Branch` | the current git branch |
|
2021-05-27 00:08:46 +02:00
|
|
|
| `.PrefixedTag` | the current git tag prefixed with the monorepo config tag prefix (if any) |
|
2020-07-06 22:09:22 +02:00
|
|
|
| `.Tag` | the current git tag |
|
|
|
|
| `.ShortCommit` | the git commit short hash |
|
|
|
|
| `.FullCommit` | the git commit full hash |
|
|
|
|
| `.Commit` | the git commit hash (deprecated) |
|
|
|
|
| `.CommitDate` | the UTC commit date in RFC 3339 format |
|
|
|
|
| `.CommitTimestamp` | the UTC commit date in Unix format |
|
|
|
|
| `.GitURL` | the git remote url |
|
|
|
|
| `.Major` | the major part of the version (assuming `Tag` is a valid semver, else `0`) |
|
|
|
|
| `.Minor` | the minor part of the version (assuming `Tag` is a valid semver, else `0`) |
|
|
|
|
| `.Patch` | the patch part of the version (assuming `Tag` is a valid semver, else `0`) |
|
|
|
|
| `.Prerelease` | the prerelease part of the version, e.g. `beta` (assuming `Tag` is a valid semver) |
|
|
|
|
| `.RawVersion` | Major.Minor.Patch (assuming `Tag` is a valid semver, else `0.0.0`) |
|
|
|
|
| `.IsSnapshot` | `true` if a snapshot is being released, `false` otherwise |
|
|
|
|
| `.Env` | a map with system's environment variables |
|
|
|
|
| `.Date` | current UTC date in RFC 3339 format |
|
|
|
|
| `.Timestamp` | current UTC time in Unix format |
|
2021-03-22 13:55:01 +02:00
|
|
|
| `.ModulePath` | the go module path, as reported by `go list -m` |
|
2018-07-09 08:57:46 +02:00
|
|
|
|
|
|
|
On fields that are related to a single artifact (e.g., the binary name), you
|
|
|
|
may have some extra fields:
|
|
|
|
|
2020-05-26 18:24:59 +02:00
|
|
|
| Key | Description |
|
|
|
|
|-----------------|---------------------------------------|
|
|
|
|
| `.Os` | `GOOS` (usually allow replacements) |
|
|
|
|
| `.Arch` | `GOARCH` (usually allow replacements) |
|
|
|
|
| `.Arm` | `GOARM` (usually allow replacements) |
|
|
|
|
| `.Mips` | `GOMIPS` (usually allow replacements) |
|
|
|
|
| `.Binary` | Binary name |
|
|
|
|
| `.ArtifactName` | Archive name |
|
2020-10-27 14:31:04 +02:00
|
|
|
| `.ArtifactPath` | Absolute path to artifact |
|
2018-07-09 08:57:46 +02:00
|
|
|
|
2020-03-22 18:54:47 +02:00
|
|
|
On the NFPM name template field, you can use those extra fields as well:
|
|
|
|
|
2021-03-09 12:57:43 +02:00
|
|
|
| Key | Description |
|
|
|
|
|----------------|------------------------------------------------------------|
|
|
|
|
| `.Release` | Release from the nfpm config |
|
|
|
|
| `.Epoch` | Epoch from the nfpm config |
|
|
|
|
| `.PackageName` | Package the name. Same as `ProjectName` if not overridden. |
|
2020-03-22 18:54:47 +02:00
|
|
|
|
2018-07-09 08:57:46 +02:00
|
|
|
On all fields, you have these available functions:
|
|
|
|
|
2020-05-26 18:24:59 +02:00
|
|
|
| Usage | Description |
|
|
|
|
|-------------------------|--------------------------------------------------------------------------------------------------------------------------------|
|
|
|
|
| `replace "v1.2" "v" ""` | replaces all matches. See [ReplaceAll](https://golang.org/pkg/strings/#ReplaceAll) |
|
2020-07-06 22:09:22 +02:00
|
|
|
| `time "01/02/2006"` | current UTC time in the specified format (this is not deterministic, a new time for every call) |
|
2020-05-26 18:24:59 +02:00
|
|
|
| `tolower "V1.2"` | makes input string lowercase. See [ToLower](https://golang.org/pkg/strings/#ToLower) |
|
|
|
|
| `toupper "v1.2"` | makes input string uppercase. See [ToUpper](https://golang.org/pkg/strings/#ToUpper) |
|
|
|
|
| `trim " v1.2 "` | removes all leading and trailing white space. See [TrimSpace](https://golang.org/pkg/strings/#TrimSpace) |
|
2021-03-19 13:50:12 +02:00
|
|
|
| `trimprefix "v1.2" "v"` | removes provided leading prefix string, if present. See [TrimPrefix](https://golang.org/pkg/strings/#TrimPrefix) |
|
2020-05-10 18:03:49 +02:00
|
|
|
| `dir .Path` | returns all but the last element of path, typically the path's directory. See [Dir](https://golang.org/pkg/path/filepath/#Dir) |
|
2020-05-26 18:24:59 +02:00
|
|
|
| `abs .ArtifactPath` | returns an absolute representation of path. See [Abs](https://golang.org/pkg/path/filepath/#Abs) |
|
2018-07-09 08:57:46 +02:00
|
|
|
|
|
|
|
With all those fields, you may be able to compose the name of your artifacts
|
|
|
|
pretty much the way you want:
|
|
|
|
|
|
|
|
```yaml
|
2019-11-07 19:49:36 +02:00
|
|
|
example_template: '{{ tolower .ProjectName }}_{{ .Env.USER }}_{{ time "2006" }}'
|
2018-07-09 08:57:46 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
For example, if you want to add the go version to some artifact:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
foo_template: 'foo_{{ .Env.GOVERSION }}'
|
|
|
|
```
|
|
|
|
|
|
|
|
And then you can run:
|
|
|
|
|
2019-03-25 01:10:30 +02:00
|
|
|
```sh
|
2018-07-09 08:57:46 +02:00
|
|
|
GOVERSION_NR=$(go version | awk '{print $3;}') goreleaser
|
|
|
|
```
|
|
|
|
|
2020-05-11 00:47:55 +02:00
|
|
|
!!! warning
|
2020-05-11 00:37:28 +02:00
|
|
|
Note that those are hypothetical examples and the fields `foo_template` and
|
|
|
|
`example_template` are not valid GoReleaser configurations.
|
2021-05-30 19:59:10 +02:00
|
|
|
|
|
|
|
## Custom variables
|
|
|
|
|
|
|
|
On [GoReleaser Pro](/pro) you can also declare custom variables.
|
|
|
|
This feature is specially useful with [includes](/customization/includes), so you can have more generic config files.
|
|
|
|
|
|
|
|
Usage is as simple as you would expect:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# .goreleaser.yml
|
|
|
|
variables:
|
|
|
|
description: my project description
|
|
|
|
somethingElse: yada yada yada
|
|
|
|
```
|
|
|
|
|
|
|
|
And then you can use those fields as `{{ .description }}`, for example.
|
|
|
|
|
|
|
|
!!! warning
|
|
|
|
You won't be allowed to override GoReleaser "native" fields.
|
|
|
|
|
|
|
|
!!! info
|
|
|
|
Custom variables is a [GoReleaser Pro feature](/pro).
|