Skip to content

Use version comparison function #41102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 20, 2024

Conversation

Forgind
Copy link
Contributor

@Forgind Forgind commented May 23, 2024

Creates a version comparison function that permits comparing four-part versions or versions with semantic parts on the end. Uses that function to find the 'max' version of all available workload sets.

I'm planning to try to write a test tomorrow.

@ghost ghost added Area-Workloads untriaged Request triage from a team member labels May 23, 2024
@Forgind Forgind marked this pull request as ready for review May 23, 2024 16:18
@Forgind
Copy link
Contributor Author

Forgind commented May 23, 2024

I looked at the first two failures. The first was where it wasn't throwing for 8.0.203.1, which seems like a valid version (now) to me, so I'm planning to just delete that test.

The second was this:

ManifestReaderTests.SdkDirectoryWorkloadManifestProviderTests.ItReturnsLatestManifestVersion(first: "8.0.203.1", second: "8.0.203", third: "8.0.200-rc.1", answer: "8.0.203.1") [FAIL]
      Expected root[0] to be "ios: 8.0.203.1/5.0.100" with a length of 22, but "ios: 8.0.203/5.0.100" has a length of 20, differs near "/5." (index 12).

So when it tried to sort 8.0.203.1, 8.0.203, and 8.0.200-rc.1, it decided 8.0.203 was the max? I don't see how that makes sense...

Will look into it

firstDash = firstDash < 0 ? first.Length : firstDash;
secondDash = secondDash < 0 ? second.Length : secondDash;

var firstVersion = new Version(first.Substring(0, firstDash));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you pass in the string without removing the - part first? The dash is supported in versions but I recall there being a reason you needed to do it this way (comment)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I tried a fairly standard version with a - in a console project I use for testing, and it threw an exception. The dash is supported in ReleaseVersions, I think, but not Version? Or perhaps there are some strings with dashes that can be parsed into a Version while others can't?

var modifiedFirst = "1.1.1" + (firstDash == first.Length ? string.Empty : first.Substring(firstDash));
var modifiedSecond = "1.1.1" + (secondDash == second.Length ? string.Empty : second.Substring(secondDash));

return new ReleaseVersion(modifiedFirst).CompareTo(new ReleaseVersion(modifiedSecond));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does release version have any limitations? Curious why you can't just compare the part after the dash directly rather than making it into a release version first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it needed some digits before the dash to make a ReleaseVersion, but it couldn't support four '.'-separated numbers. I originally proposed doing a simpler comparison like a string comparison, since my current understanding is that the part after the dash is just compared alphanumerically, but dsplaisted was concerned that there might be more complexity and suggested doing it with a ReleaseVersion.

Copy link
Member

@marcpopMSFT marcpopMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The important thing for me was the list of tests and I think you covered every key scenario there so if that works, let's proceed.

@Forgind Forgind merged commit 94aa16c into dotnet:release/8.0.4xx Jun 20, 2024
17 checks passed
@Forgind Forgind deleted the fix-version-cast branch June 20, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Workloads untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants