Under our old versioning system, when we started a new point release, we'd tag the HEAD commit of master with a tag like `v0.16.6-dev` and our scripts would use this to generate a new version number. This required a great deal of gymnastics when producing a release and caused us to litter these -dev tags everywhere. To improve this, we change version number generation to the following strategy: 1. If the commit we are building has a tag applied to it, use that tag as the version (appending the dirty bit metadata to the version, if needed). 2. If the commit we are bulding does not have a tag applied to it, take the version from the next reachable tag, increment the patch version and then append the `-dev` pre-release tag. As part of this, we also make a slight tweek to our semver generation such that instead of `-dev<TIMESTAMP>` we use `-dev.<TIMESTAMP>` which is more in line with what semver recommends.
46 lines
1.2 KiB
PowerShell
46 lines
1.2 KiB
PowerShell
Set-StrictMode -Version 2.0
|
|
$ErrorActionPreference="Stop"
|
|
|
|
git update-index -q --refresh
|
|
git diff-files --quiet | Out-Null
|
|
|
|
$dirty=($LASTEXITCODE -ne 0)
|
|
|
|
try {
|
|
git describe --tags --exact-match >$null 2>$null
|
|
# If we get here the above did not throw, so we can use the exact tag
|
|
if ($dirty) {
|
|
Write-Output "$(git describe --tags --exact-match)"
|
|
} else {
|
|
Write-Output "$(git describe --tags --exact-match)+dirty"
|
|
}
|
|
} catch {
|
|
# Otherwise, take the existing tag, increment the patch version and append the timestamp of the commit and hash
|
|
$tag=""
|
|
|
|
try {
|
|
git describe --tags --abbrev=0 >$null 2>$null
|
|
$tag="$(git describe --tags --abbrev=0)"
|
|
} catch {
|
|
$tag="v0.0.0"
|
|
}
|
|
|
|
# Remove any pre-release tag
|
|
if ($tag.LastIndexOf("-") -ne -1) {
|
|
$tag=$tag.Substring(0, $tag.LastIndexOf("-"))
|
|
}
|
|
|
|
$tagParts = $tag.Split('.');
|
|
$major = $tagParts[0];
|
|
$minor = $tagParts[1];
|
|
$patch = $tagParts[2];
|
|
|
|
$patch = ([int]$patch + 1);
|
|
if ($dirty) {
|
|
Write-Output "$major.$minor.$patch-dev.$(git show -s --format='%ct+g%h').dirty"
|
|
} else {
|
|
Write-Output "$major.$minor.$patch-dev.$(git show -s --format='%ct+g%h')"
|
|
}
|
|
}
|
|
|