Files
Alphaeus Mote 2e00b8df83 build(version)!: semantic versions from release tags
Releases are X.Y.Z from git tags vX.Y.Z; builds between releases are
X.Y.Z.N, N commits after the last release (git describe, 1-3 digit majors
only, so the calendar-era tags never count); with no release tag reachable
a build is 0.0.0.<commits>. Every version is 3-4 numeric fields, refused
when it does not fit an MSI ProductVersion or has a calendar-era major.

scripts/Get-Version.ps1 computes it (Get-UnifiedVersion.ps1 stays as the
old entry point). scripts/Get-NextRelease.ps1 runs semantic-release in
dry-run mode (pinned in build/release, conventionalcommits preset, main
only) for the version a release publishes, or for nothing when the commits
since the last release call for none. Directory.Build.props stamps
four-field assembly/file versions and InformationalVersion
X.Y.Z[.N]+<short commit>; a build not handed a version reads it from git
(build/Version.targets), otherwise 0.0.0.0.

BREAKING CHANGE: versions are no longer yyyy.MM.dd.HHmm. The first release
after the seed tag v0.1.0 is 1.0.0, which every comparison orders after
every calendar-era version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 20:49:46 -04:00

76 lines
6.0 KiB
XML

<Project>
<!-- The version rules of scripts/Get-Version.ps1 (README, Versioning) for MSBuild: a handed-in UnifiedVersion is checked, and a build
that was not handed one reads it from git. Both run before the assembly attributes are generated. -->
<!-- A handed-in version: 3 or 4 numbers (no -label), fitting an MSI ProductVersion (major and minor up to 255, the rest up to
65535) and not of the calendar era (major 2000 or more). -->
<Target Name="CheckUnifiedVersion" BeforeTargets="GetAssemblyVersion;GenerateAssemblyInfo" Condition="'$(VersionFromGit)' != 'true'">
<PropertyGroup>
<_VersionPattern>^(\d{1,9})\.(\d{1,9})\.(\d{1,9})(\.(\d{1,9}))?$</_VersionPattern>
<_VersionWellFormed>$([System.Text.RegularExpressions.Regex]::IsMatch('$(UnifiedVersion)', '$(_VersionPattern)'))</_VersionWellFormed>
</PropertyGroup>
<Error Condition="'$(_VersionWellFormed)' != 'True'"
Text="UnifiedVersion '$(UnifiedVersion)' is not major.minor.patch or major.minor.patch.build (numbers only, no -label)." />
<PropertyGroup>
<_VersionMajor>$([System.Text.RegularExpressions.Regex]::Replace('$(UnifiedVersion)', '$(_VersionPattern)', '$1'))</_VersionMajor>
<_VersionMinor>$([System.Text.RegularExpressions.Regex]::Replace('$(UnifiedVersion)', '$(_VersionPattern)', '$2'))</_VersionMinor>
<_VersionPatch>$([System.Text.RegularExpressions.Regex]::Replace('$(UnifiedVersion)', '$(_VersionPattern)', '$3'))</_VersionPatch>
<_VersionBuild>$([System.Text.RegularExpressions.Regex]::Replace('$(UnifiedVersion)', '$(_VersionPattern)', '$5'))</_VersionBuild>
<_VersionBuild Condition="'$(_VersionBuild)' == ''">0</_VersionBuild>
</PropertyGroup>
<Error Condition="$(_VersionMajor) &gt;= 2000"
Text="UnifiedVersion '$(UnifiedVersion)' is a calendar-era version (major $(_VersionMajor)), not a semantic one." />
<Error Condition="$(_VersionMajor) &gt; 255 Or $(_VersionMinor) &gt; 255 Or $(_VersionPatch) &gt; 65535 Or $(_VersionBuild) &gt; 65535"
Text="UnifiedVersion '$(UnifiedVersion)' does not fit an MSI ProductVersion (major and minor up to 255, the rest up to 65535)." />
</Target>
<!-- No version handed in: the newest release tag vX.Y.Z behind HEAD and the commits since it (1.4.0.7; the release itself on the
tagged commit), and the short hash, ".dirty" when tracked files differ. Without a release tag the base is 0.0.0 and the
build the number of commits; without git, Directory.Build.props' 0.0.0.0 stands. -->
<Target Name="StampVersionFromGit" BeforeTargets="GetAssemblyVersion;GenerateAssemblyInfo" Condition="'$(VersionFromGit)' == 'true'">
<!-- One to three digits of major: the calendar-era tags (v2026.10.10.0140) never match. -->
<Exec Command="git describe --tags --long --match &quot;v[0-9].[0-9]*.[0-9]*&quot; --match &quot;v[0-9][0-9].[0-9]*.[0-9]*&quot; --match &quot;v[0-9][0-9][0-9].[0-9]*.[0-9]*&quot;"
WorkingDirectory="$(MSBuildThisFileDirectory).." ConsoleToMSBuild="true" IgnoreExitCode="true" EchoOff="true"
StandardOutputImportance="low" StandardErrorImportance="low" ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="_Describe" />
</Exec>
<PropertyGroup>
<_DescribePattern>^v(\d{1,3}\.\d{1,9}\.\d{1,9})-(\d+)-g([0-9a-f]+)$</_DescribePattern>
<_Described>$([System.Text.RegularExpressions.Regex]::IsMatch('$(_Describe)', '$(_DescribePattern)'))</_Described>
</PropertyGroup>
<Exec Command="git rev-parse --short HEAD" Condition="'$(_Described)' != 'True'" WorkingDirectory="$(MSBuildThisFileDirectory).."
ConsoleToMSBuild="true" IgnoreExitCode="true" EchoOff="true" StandardOutputImportance="low" StandardErrorImportance="low" ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="_HeadShort" />
</Exec>
<Exec Command="git rev-list --count HEAD" Condition="'$(_Described)' != 'True'" WorkingDirectory="$(MSBuildThisFileDirectory).."
ConsoleToMSBuild="true" IgnoreExitCode="true" EchoOff="true" StandardOutputImportance="low" StandardErrorImportance="low" ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="_Count" />
</Exec>
<PropertyGroup Condition="'$(_Described)' == 'True'">
<_Base>$([System.Text.RegularExpressions.Regex]::Replace('$(_Describe)', '$(_DescribePattern)', '$1'))</_Base>
<_Since>$([System.Text.RegularExpressions.Regex]::Replace('$(_Describe)', '$(_DescribePattern)', '$2'))</_Since>
<_Short>$([System.Text.RegularExpressions.Regex]::Replace('$(_Describe)', '$(_DescribePattern)', '$3'))</_Short>
</PropertyGroup>
<PropertyGroup Condition="'$(_Described)' != 'True' And $([System.Text.RegularExpressions.Regex]::IsMatch('$(_Count)', '^\d+$')) And $([System.Text.RegularExpressions.Regex]::IsMatch('$(_HeadShort)', '^[0-9a-f]+$'))">
<_Base>0.0.0</_Base>
<_Since>$(_Count)</_Since>
<_Short>$(_HeadShort)</_Short>
</PropertyGroup>
<Exec Command="git status --porcelain --untracked-files=no" Condition="'$(_Base)' != ''" WorkingDirectory="$(MSBuildThisFileDirectory).."
ConsoleToMSBuild="true" IgnoreExitCode="true" EchoOff="true" StandardOutputImportance="low" StandardErrorImportance="low" ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="_Status" />
</Exec>
<PropertyGroup Condition="'$(_Base)' != ''">
<UnifiedVersion>$(_Base)</UnifiedVersion>
<UnifiedVersion Condition="'$(_Since)' != '0'">$(_Base).$(_Since)</UnifiedVersion>
<UnifiedFileVersion>$(_Base).$(_Since)</UnifiedFileVersion>
<GitCommitShort>$(_Short)</GitCommitShort>
<GitCommitShort Condition="'$(_Status)' != ''">$(GitCommitShort).dirty</GitCommitShort>
<Version>$(UnifiedVersion)</Version>
<AssemblyVersion>$(UnifiedFileVersion)</AssemblyVersion>
<FileVersion>$(UnifiedFileVersion)</FileVersion>
<InformationalVersion>$(UnifiedVersion)+$(GitCommitShort)</InformationalVersion>
</PropertyGroup>
</Target>
</Project>