Skip to content

Commit

Permalink
Emit a warning when SemVer 2.0 format version is used with explicit S…
Browse files Browse the repository at this point in the history
…emVer 1.0

Should the user explicitly set `nugetPackageVersion.semVer` to `1` but
use a SemVer 2 prerelease in their `version` (such as: `1.0.0-preview.{height})
a warning will now be displayed telling the user they are probably not
getting what they expected.

Fixes dotnet#318
  • Loading branch information
robmen committed Apr 22, 2019
1 parent 7551e58 commit 00a9b3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/NerdBank.GitVersioning/VersionOracle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,22 @@ public IDictionary<string, string> CloudBuildVersionVars
/// </summary>
public int SemVer1NumericIdentifierPadding => this.VersionOptions?.SemVer1NumericIdentifierPaddingOrDefault ?? 4;

/// <summary>
/// Gets the SemVer 1 format without padding or the build metadata.
/// </summary>
public string SemVer1WithoutPaddingOrBuildMetadata =>
$"{this.Version.ToStringSafe(3)}{MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, 0)}";

/// <summary>
/// Determines if it was likely the user misconfigured their the prerelease version options and
/// their semver setting.
/// </summary>
/// <returns>False when NuGet SemVer 1 explicitly set but the prerelease does not match.</returns>
public bool MisconfiguredPrereleaseAndSemVer1()
{
return this.VersionOptions != null && this.VersionOptions.NuGetPackageVersion != null && this.VersionOptions.NuGetPackageVersion.SemVer == 1 && this.PrereleaseVersion != MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, 0);
}

/// <summary>
/// Gets the build metadata, compliant to the NuGet-compatible subset of SemVer 1.0.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Nerdbank.GitVersioning.Tasks/GetBuildVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ protected override bool ExecuteInner()
oracle.BuildMetadata.AddRange(this.BuildMetadata);
}

if (oracle.MisconfiguredPrereleaseAndSemVer1())
{
this.Log.LogWarning("The 'nugetPackageVersion' is explicitly set to 'semVer': 1 but the prerelease version '{0}' is not SemVer1 compliant. Change the 'nugetPackageVersion'.'semVer' value to 2 or chagne the 'version' member to follow SemVer1 (like: '{1}').", oracle.PrereleaseVersion, oracle.SemVer1WithoutPaddingOrBuildMetadata);
}

this.PublicRelease = oracle.PublicRelease;
this.Version = oracle.Version.ToString();
this.AssemblyVersion = oracle.AssemblyVersion.ToString();
Expand Down

0 comments on commit 00a9b3c

Please # to comment.