Skip to content

Commit

Permalink
Allow versions of the same patch to work together
Browse files Browse the repository at this point in the history
Sleet versions with the same major and minor version will work together. These will no longer require recreating and upgrading the feed.

Patch versions from now on will only contain bug fixes. New features or any breaking changes will require the minor or major version numbers to be increased.
  • Loading branch information
emgarten committed Oct 13, 2017
1 parent dbf8ad8 commit 6973dc7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
2 changes: 2 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Release Notes

## 2.2.0
* Fix for multiple catalog pages
* Sleet versions of the same semantic version patch will no longer require upgrading the feed to work together.

## 2.1.0
* Fix for race condition when reading symbols files
Expand Down
41 changes: 33 additions & 8 deletions src/SleetLib/Utility/UpgradeUtility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
Expand Down Expand Up @@ -50,18 +50,43 @@ public static async Task<bool> EnsureFeedVersionMatchesTool(ISleetFileSystem fil
{
var sourceVersion = await GetSleetVersionAsync(fileSystem, log, token);

var assemblyVersion = AssemblyVersionHelper.GetVersion();
var originalVersion = AssemblyVersionHelper.GetVersion();
var assemblyVersion = new NuGetVersion(originalVersion.Major, originalVersion.Minor, originalVersion.Patch);

if (!allowNewer && sourceVersion < assemblyVersion)
{
throw new InvalidOperationException($"{fileSystem.BaseURI} uses an older version of Sleet: {sourceVersion}. Upgrade the feed to {assemblyVersion} by running 'Sleet recreate' against this feed.");
}
else if (sourceVersion > assemblyVersion)
// Allow all X.Y.* versions to be used, patches should only contain bug fixes
// no breaking changes or new features.
var allowedRange = GetAllowedRange(sourceVersion, allowNewer);

if (!allowedRange.Satisfies(assemblyVersion))
{
throw new InvalidOperationException($"{fileSystem.BaseURI} was created using a newer version of Sleet: {sourceVersion}. Use the same or higher version to make changes.");
if (sourceVersion < assemblyVersion)
{
throw new InvalidOperationException($"{fileSystem.BaseURI} uses an older version of Sleet: {sourceVersion}. Upgrade the feed to {assemblyVersion} by running 'Sleet recreate' against this feed.");
}
else if (sourceVersion > assemblyVersion)
{
throw new InvalidOperationException($"{fileSystem.BaseURI} was created using a newer version of Sleet: {sourceVersion}. Use the same or higher version to make changes.");
}
}

return true;
}

/// <summary>
/// Get the range of tool versions that can work with the source.
/// </summary>
public static VersionRange GetAllowedRange(SemanticVersion sourceVersion, bool allowNewer)
{
var minVersion = new NuGetVersion(sourceVersion.Major, sourceVersion.Minor, 0);
var maxVersion = allowNewer ? null : new NuGetVersion(sourceVersion.Major, sourceVersion.Minor + 1, 0);

// Create a range that allows any patch version to be used.
// If allowNewer is set then allow an open range.
return new VersionRange(
minVersion: minVersion,
includeMinVersion: true,
maxVersion: maxVersion,
includeMaxVersion: false);
}
}
}
28 changes: 28 additions & 0 deletions test/SleetLib.Tests/UpgradeUtilityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FluentAssertions;
using NuGet.Versioning;
using Sleet;
using Xunit;

namespace SleetLib.Tests
{
public class UpgradeUtilityTests
{
[Fact]
public void GivenAVersionVerifyAllowedRange()
{
UpgradeUtility.GetAllowedRange(new SemanticVersion(1, 2, 3), allowNewer: false)
.ToNormalizedString()
.Should()
.Be("[1.2.0, 1.3.0)");
}

[Fact]
public void GivenAVersionVerifyAllowedRangeHasNoUpperBound()
{
UpgradeUtility.GetAllowedRange(new SemanticVersion(1, 2, 3), allowNewer: true)
.ToNormalizedString()
.Should()
.Be("[1.2.0, )");
}
}
}

0 comments on commit 6973dc7

Please sign in to comment.