github.com/joselitofilho/goreleaser@v0.155.1-0.20210123221854-e4891856c593/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 explicit in which fields
     9  templating is available.
    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),<br>or `{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}` in case of snapshot release |
    17  | `.Branch`          | the current git branch                                                                                                       |
    18  | `.Tag`             | the current git tag                                                                                                          |
    19  | `.ShortCommit`     | the git commit short hash                                                                                                    |
    20  | `.FullCommit`      | the git commit full hash                                                                                                     |
    21  | `.Commit`          | the git commit hash (deprecated)                                                                                             |
    22  | `.CommitDate`      | the UTC commit date in RFC 3339 format                                                                                       |
    23  | `.CommitTimestamp` | the UTC commit date in Unix format                                                                                           |
    24  | `.GitURL`          | the git remote url                                                                                                           |
    25  | `.Major`           | the major part of the version (assuming `Tag` is a valid semver, else `0`)                                                   |
    26  | `.Minor`           | the minor part of the version (assuming `Tag` is a valid semver, else `0`)                                                   |
    27  | `.Patch`           | the patch part of the version (assuming `Tag` is a valid semver, else `0`)                                                   |
    28  | `.Prerelease`      | the prerelease part of the version, e.g. `beta` (assuming `Tag` is a valid semver)                                           |
    29  | `.RawVersion`      | Major.Minor.Patch (assuming `Tag` is a valid semver, else `0.0.0`)                                                           |
    30  | `.IsSnapshot`      | `true` if a snapshot is being released, `false` otherwise                                                                    |
    31  | `.Env`             | a map with system's environment variables                                                                                    |
    32  | `.Date`            | current UTC date in RFC 3339 format                                                                                          |
    33  | `.Timestamp`       | current UTC time in Unix format                                                                                              |
    34  
    35  On fields that are related to a single artifact (e.g., the binary name), you
    36  may have some extra fields:
    37  
    38  | Key             | Description                           |
    39  |-----------------|---------------------------------------|
    40  | `.Os`           | `GOOS` (usually allow replacements)   |
    41  | `.Arch`         | `GOARCH` (usually allow replacements) |
    42  | `.Arm`          | `GOARM` (usually allow replacements)  |
    43  | `.Mips`         | `GOMIPS` (usually allow replacements) |
    44  | `.Binary`       | Binary name                           |
    45  | `.ArtifactName` | Archive name                          |
    46  | `.ArtifactPath` | Absolute path to artifact             |
    47  
    48  On the NFPM name template field, you can use those extra fields as well:
    49  
    50  | Key        | Description                  |
    51  |------------|------------------------------|
    52  | `.Release` | Release from the nfpm config |
    53  | `.Epoch`   | Epoch from the nfpm config   |
    54  
    55  On all fields, you have these available functions:
    56  
    57  | Usage                   | Description                                                                                                                    |
    58  |-------------------------|--------------------------------------------------------------------------------------------------------------------------------|
    59  | `replace "v1.2" "v" ""` | replaces all matches. See [ReplaceAll](https://golang.org/pkg/strings/#ReplaceAll)                                             |
    60  | `time "01/02/2006"`     | current UTC time in the specified format (this is not deterministic, a new time for every call)                                |
    61  | `tolower "V1.2"`        | makes input string lowercase. See [ToLower](https://golang.org/pkg/strings/#ToLower)                                           |
    62  | `toupper "v1.2"`        | makes input string uppercase. See [ToUpper](https://golang.org/pkg/strings/#ToUpper)                                           |
    63  | `trim " v1.2  "`        | removes all leading and trailing white space. See [TrimSpace](https://golang.org/pkg/strings/#TrimSpace)                       |
    64  | `dir .Path`             | returns all but the last element of path, typically the path's directory. See [Dir](https://golang.org/pkg/path/filepath/#Dir) |
    65  | `abs .ArtifactPath`     | returns an absolute representation of path. See [Abs](https://golang.org/pkg/path/filepath/#Abs)                               |
    66  
    67  With all those fields, you may be able to compose the name of your artifacts
    68  pretty much the way you want:
    69  
    70  ```yaml
    71  example_template: '{{ tolower .ProjectName }}_{{ .Env.USER }}_{{ time "2006" }}'
    72  ```
    73  
    74  For example, if you want to add the go version to some artifact:
    75  
    76  ```yaml
    77  foo_template: 'foo_{{ .Env.GOVERSION }}'
    78  ```
    79  
    80  And then you can run:
    81  
    82  ```sh
    83  GOVERSION_NR=$(go version | awk '{print $3;}') goreleaser
    84  ```
    85  
    86  !!! warning
    87      Note that those are hypothetical examples and the fields `foo_template` and
    88      `example_template` are not valid GoReleaser configurations.