-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add in better version formatting system
- Loading branch information
Showing
9 changed files
with
169 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Format System | ||
|
||
git-mkver includes a powerful string formatting system for creating version strings in different styles on different | ||
branches. This is required as different software often have different restrictions on what a valid version number might be. | ||
|
||
For example git is happy with the SemVer standard for tagging but docker does not support the `+` symbol in docker tags. | ||
|
||
All format strings start with a `%`. They are recursively replaced so that one may refer to another. | ||
|
||
## Built-in Formats | ||
|
||
| Format Token | Substitution | | ||
| ------------- | ------------- | | ||
| `x` | Version major number | | ||
| `z` | Version patch number | | ||
| `y` | Version minor number | | ||
| `br` | Branch name | | ||
| `sh` | Short Hash | | ||
| `hash` | Full Hash | | ||
| `dd` | Day | | ||
| `mm` | MonthValue, | | ||
| `yyyy` | Year, | | ||
| `bn` | Build No from build system | | ||
| `tag` | Full tag | | ||
| `pr` | Tag prefix | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net.cardnell.mkver | ||
|
||
object Formatter { | ||
val builtInFormats = List( | ||
Format("version", "%x.%y.%z"), | ||
Format("version-prerelease", "%version-%prerelease"), | ||
Format("version-buildmetadata", "%version+%buildmetadata"), | ||
Format("version-prerelease-buildmetadata", "%version-%prerelease+%buildmetadata"), | ||
) | ||
|
||
val defaultFormats = List( | ||
Format("prerelease", "rc-%prereleasename"), | ||
Format("buildmetadata", "%br.%sh"), | ||
) | ||
|
||
case class Formatter(formats: List[Format]) { | ||
def format(input: String): String = { | ||
val result = formats.sortBy(_.name.length * -1).foldLeft(input) { (s, v) => | ||
s.replace("%" + v.name, v.format) | ||
} | ||
if (result == input) { | ||
// no replacements made - we are done | ||
result | ||
} else { | ||
// recursively replace | ||
format(result) | ||
} | ||
} | ||
} | ||
|
||
def apply(version: VersionData, branchConfig: BranchConfig): Formatter = { | ||
Formatter(List( | ||
Format("x", version.major.toString), | ||
Format("y", version.minor.toString), | ||
Format("z", version.patch.toString), | ||
Format("br", version.branch.replace("/", "-")), | ||
Format("sh", version.commitHashShort), | ||
Format("hash", version.commitHashFull), | ||
Format("dd", version.date.getDayOfMonth.formatted("00")), | ||
Format("mm", version.date.getMonthValue.formatted("00")), | ||
Format("yyyy", version.date.getYear.toString), | ||
Format("bn", version.buildNo), | ||
Format("tag?", branchConfig.tag.toString), | ||
Format("pr", branchConfig.prefix.toString) | ||
) ++ branchConfig.formats) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.