github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/www/docs/customization/templates.md (about) 1 --- 2 title: Name Templates 3 --- 4 5 Several fields in GoReleaser's config file support templating. 6 7 Those fields are often suffixed with `_template`, but sometimes they may not 8 be. The documentation of each section should be explicit about which fields 9 support templating. 10 11 On fields that support templating, these fields are always available: 12 13 | Key | Description | 14 |---------------------|--------------------------------------------------------------------------------------------------------| 15 | `.ProjectName` | the project name | 16 | `.Version` | the version being released (`v` prefix stripped) - might be changed in `snapshot` and `nightly` builds | 17 | `.Branch` | the current git branch | 18 | `.PrefixedTag` | the current git tag prefixed with the monorepo config tag prefix (if any) | 19 | `.Tag` | the current git tag | 20 | `.ShortCommit` | the git commit short hash | 21 | `.FullCommit` | the git commit full hash | 22 | `.Commit` | the git commit hash (deprecated) | 23 | `.CommitDate` | the UTC commit date in RFC 3339 format | 24 | `.CommitTimestamp` | the UTC commit date in Unix format | 25 | `.GitURL` | the git remote url | 26 | `.Major` | the major part of the version (assuming `Tag` is a valid semver, else `0`) | 27 | `.Minor` | the minor part of the version (assuming `Tag` is a valid semver, else `0`) | 28 | `.Patch` | the patch part of the version (assuming `Tag` is a valid semver, else `0`) | 29 | `.Prerelease` | the prerelease part of the version, e.g. `beta` (assuming `Tag` is a valid semver) | 30 | `.RawVersion` | Major.Minor.Patch (assuming `Tag` is a valid semver, else `0.0.0`) | 31 | `.IsSnapshot` | `true` if `--snapshot` is set, `false` otherwise | 32 | `.IsNightly` | `true` if `--nightly` is set, `false` otherwise | 33 | `.Env` | a map with system's environment variables | 34 | `.Date` | current UTC date in RFC 3339 format | 35 | `.Timestamp` | current UTC time in Unix format | 36 | `.ModulePath` | the go module path, as reported by `go list -m` | 37 | `incpatch "v1.2.4"` | increments the patch of the given version; will panic if not a semantic version | 38 | `incminor "v1.2.4"` | increments the minor of the given version; will panic if not a semantic version | 39 | `incmajor "v1.2.4"` | increments the major of the given version; will panic if not a semantic version | 40 41 On fields that are related to a single artifact (e.g., the binary name), you 42 may have some extra fields: 43 44 | Key | Description | 45 |-----------------|---------------------------------------| 46 | `.Os` | `GOOS` (usually allow replacements) | 47 | `.Arch` | `GOARCH` (usually allow replacements) | 48 | `.Arm` | `GOARM` (usually allow replacements) | 49 | `.Mips` | `GOMIPS` (usually allow replacements) | 50 | `.Binary` | Binary name | 51 | `.ArtifactName` | Archive name | 52 | `.ArtifactPath` | Absolute path to artifact | 53 54 On the NFPM name template field, you can use those extra fields as well: 55 56 | Key | Description | 57 |----------------|------------------------------------------------------------| 58 | `.Release` | Release from the nfpm config | 59 | `.Epoch` | Epoch from the nfpm config | 60 | `.PackageName` | Package the name. Same as `ProjectName` if not overridden. | 61 62 On all fields, you have these available functions: 63 64 | Usage | Description | 65 |-------------------------|--------------------------------------------------------------------------------------------------------------------------------| 66 | `replace "v1.2" "v" ""` | replaces all matches. See [ReplaceAll](https://golang.org/pkg/strings/#ReplaceAll) | 67 | `time "01/02/2006"` | current UTC time in the specified format (this is not deterministic, a new time for every call) | 68 | `tolower "V1.2"` | makes input string lowercase. See [ToLower](https://golang.org/pkg/strings/#ToLower) | 69 | `toupper "v1.2"` | makes input string uppercase. See [ToUpper](https://golang.org/pkg/strings/#ToUpper) | 70 | `trim " v1.2 "` | removes all leading and trailing white space. See [TrimSpace](https://golang.org/pkg/strings/#TrimSpace) | 71 | `trimprefix "v1.2" "v"` | removes provided leading prefix string, if present. See [TrimPrefix](https://golang.org/pkg/strings/#TrimPrefix) | 72 | `dir .Path` | returns all but the last element of path, typically the path's directory. See [Dir](https://golang.org/pkg/path/filepath/#Dir) | 73 | `abs .ArtifactPath` | returns an absolute representation of path. See [Abs](https://golang.org/pkg/path/filepath/#Abs) | 74 75 With all those fields, you may be able to compose the name of your artifacts 76 pretty much the way you want: 77 78 ```yaml 79 example_template: '{{ tolower .ProjectName }}_{{ .Env.USER }}_{{ time "2006" }}' 80 ``` 81 82 For example, if you want to add the go version to some artifact: 83 84 ```yaml 85 foo_template: 'foo_{{ .Env.GOVERSION }}' 86 ``` 87 88 And then you can run: 89 90 ```sh 91 GOVERSION_NR=$(go version | awk '{print $3;}') goreleaser 92 ``` 93 94 !!! warning 95 Note that those are hypothetical examples and the fields `foo_template` and 96 `example_template` are not valid GoReleaser configurations. 97 98 ## Custom variables 99 100 !!! success "GoReleaser Pro" 101 Custom template variables support is a [GoReleaser Pro feature](/pro/). 102 103 You can also declare custom variables. 104 This feature is specially useful with [includes](/customization/includes/), so you can have more generic config files. 105 106 Usage is as simple as you would expect: 107 108 ```yaml 109 # .goreleaser.yml 110 variables: 111 description: my project description 112 somethingElse: yada yada yada 113 empty: "" 114 ``` 115 116 And then you can use those fields as `{{ .description }}`, for example. 117 118 !!! warning 119 You won't be allowed to override GoReleaser "native" fields.