跳到主要内容

Templates

Several fields in Kmdo's config file support templating.

Those fields are often suffixed with _template, but sometimes they may not be. The documentation of each section should be explicit about which fields support templating.

Common Fields

In fields that support templates, these fields are always available:

KeyDescription
.ProjectNamethe project name
.Versionthe version being released[^version-prefix]
.Branchthe current git branch
.Tagthe current git tag
.PreviousTagthe previous git tag, or empty if no previous tags
.ShortCommitthe git commit short hash
.FullCommitthe git commit full hash
.Committhe git commit hash (deprecated)
.CommitDatethe UTC commit date in RFC 3339 format
.CommitTimestampthe UTC commit date in Unix format
.GitURLthe git remote url
.GitTreeStateeither 'clean' or 'dirty'
.IsGitCleanwhether or not current git state is clean
.IsGitDirtywhether or not current git state is dirty
.Majorthe major part of the version[^tag-is-semver]
.Minorthe minor part of the version[^tag-is-semver]
.Patchthe patch part of the version[^tag-is-semver]
.Prereleasethe prerelease part of the version, e.g. beta[^tag-is-semver]
.RawVersioncomposed of {Major}.{Minor}.{Patch} [^tag-is-semver]
.ReleaseNotesthe generated release notes, available after the changelog step has been executed
.IsDrafttrue if release.draft is set in the configuration, false otherwise
.IsSnapshottrue if --snapshot is set, false otherwise
.IsNightlytrue if --nightly is set, false otherwise
.IsSingleTargettrue if --single-target is set, false otherwise (since v2.3)
.Enva map with system's environment variables
.Datecurrent UTC date in RFC 3339 format
.Nowcurrent UTC date as time.Time struct, allows all time.Time functions (e.g. {{ .Now.Format "2006" }})
.Timestampcurrent UTC time in Unix format
.ModulePaththe go module path, as reported by go list -m
.ReleaseURLthe current release download url[^scm-release-url]
.Summarythe git summary, e.g. v1.0.0-10-g34f56g3[^git-summary]
.TagSubjectthe annotated tag message subject, or the message subject of the commit it points out[^git-tag-subject]
.TagContentsthe annotated tag message, or the message of the commit it points out[^git-tag-body]
.TagBodythe annotated tag message's body, or the message's body of the commit it points out[^git-tag-body]
.Runtime.Goosequivalent to runtime.GOOS
.Runtime.Goarchequivalent to runtime.GOARCH
.Outputscustom outputs (since v2.11)

Single-artifact extra fields

On fields that are related to a single artifact (e.g., the binary name), you may have some extra fields:

KeyDescription
.OsGOOS
.ArchGOARCH
.ArmGOARM
.MipsGOMIPS
.Amd64GOAMD64
.Arm64GOARM64 (since v2.4)
.Mips64GOMIPS64 (since v2.4)
.Ppc64GOPPC64 (since v2.4)
.Riscv64GORISCV64 (since v2.4)
.I386GO386 (since v2.4)
.Targetthe whole target (since v2.5)
.Binaryartifact name
.ArtifactNameartifact name
.ArtifactPathabsolute path to artifact
.ArtifactExtartifact extension (e.g. .exe, .dmg, etc)

nFPM extra fields

In the nFPM name template field, you can use those extra fields:

KeyDescription
.Releaserelease from the nfpm config
.Epochepoch from the nfpm config
.PackageNamepackage the name. Same as ProjectName if not overridden.
.ConventionalFileNameconventional package file name as provided by nFPM.[^arm-names]
.ConventionalExtensionconventional package extension as provided by nFPM
.Formatpackage format

Release body extra fields

In the release.body field, you can use these extra fields:

KeyDescription
.Checksumsthe current checksum file contents, or a map of filename/checksum contents if checksum.split is set. Only available in the release body

Functions

On all fields, you have these available functions:

UsageDescription
replace "v1.2" "v" ""replaces all matches. See ReplaceAll
split "1.2" "."split string at separator. See Split
time "01/02/2006"current UTC time in the specified format (this is not deterministic, a new time for every call)
contains "foobar" "foo"checks whether the first string contains the second. See Contains
tolower "V1.2"makes input string lowercase. See ToLower
toupper "v1.2"makes input string uppercase. See ToUpper
trim " v1.2 "removes all leading and trailing white space. See TrimSpace
trimprefix "v1.2" "v"removes provided leading prefix string, if present. See TrimPrefix
trimsuffix "1.2v" "v"removes provided trailing suffix string, if present. See TrimSuffix
dir .Pathreturns all but the last element of path, typically the path's directory. See Dir
base .Pathreturns the last element of path. See Base
abs .ArtifactPathreturns an absolute representation of path. See Abs
filter "text" "regex"keeps only the lines matching the given regex, analogous to grep -E
reverseFilter "text" "regex"keeps only the lines not matching the given regex, analogous to grep -vE
title "foo""titlenize" the string using english as language. See Title
mdv2escape "foo"escape characters according to MarkdownV2, especially useful in the Telegram integration
envOrDefault "NAME" "value"either gets the value of the given environment variable, or the given default
isEnvSet "NAME"returns true if the env is set and not empty, false otherwise
$m := map "KEY" "VALUE"creates a map from a list of key and value pairs. Both keys and values must be of type string
indexOrDefault $m "KEY" "value"either gets the value of the given key or the given default value from the given map
incpatch "v1.2.4"increments the patch of the given version[^panic-if-not-semver]
incminor "v1.2.4"increments the minor of the given version[^panic-if-not-semver]
incmajor "v1.2.4"increments the major of the given version[^panic-if-not-semver]
urlPathEscape "foo/bar"escapes URL paths. See PathEscape (since v2.5)
blake2b .ArtifactPathblake2b checksum of the artifact. See Blake2b (since v2.9)
blake2s .ArtifactPathblake2s checksum of the artifact. See Blake2s (since v2.9)
crc32 .ArtifactPathcrc32 checksum of the artifact. See CRC32 (since v2.9)
md5 .ArtifactPathmd5 checksum of the artifact. See MD5 (since v2.9)
sha224 .ArtifactPathsha224 checksum of the artifact. See SHA224 (since v2.9)
sha384 .ArtifactPathsha384 checksum of the artifact. See SHA384 (since v2.9)
sha256 .ArtifactPathsha256 checksum of the artifact. See SHA256 (since v2.9)
sha1 .ArtifactPathsha1 checksum of the artifact. See SHA1 (since v2.9)
sha512 .ArtifactPathsha512 checksum of the artifact. See SHA512 (since v2.9)
sha3_224 .ArtifactPathsha3_224 checksum of the artifact. See SHA3-224 (since v2.9)
sha3_384 .ArtifactPathsha3_384 checksum of the artifact. See SHA3-384 (since v2.9)
sha3_256 .ArtifactPathsha3_256 checksum of the artifact. See SHA3-256 (since v2.9)
sha3_512 .ArtifactPathsha3_512 checksum of the artifact. See SHA3-512 (since v2.9)
mustReadFile "/foo/bar.txt"reads the file contents or fails if it can't be read (since v2.12)
readFile "/foo/bar.txt"reads the file contents if it it can be read, or return empty string (since v2.12)