diff --git a/release-version-sane/UpstreamRelease.cs b/release-version-sane/UpstreamRelease.cs deleted file mode 100644 index 71e516d..0000000 --- a/release-version-sane/UpstreamRelease.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; -using Newtonsoft.Json; - -namespace ReleaseVersionSane -{ - public class UpstreamRelease - { - private readonly Uri RELEASE_INDEX = new Uri("https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases-index.json"); - - public async Task<(List sdks, string runtime)> GetLatestRelease(HttpClient client, string majorMinor) - { - var releaseIndexRawJson = await client.GetStringAsync(RELEASE_INDEX); - var releaseInfoChannelJsonUrl = GetReleaseInfoChannelUrl(releaseIndexRawJson, majorMinor); - if (releaseInfoChannelJsonUrl == null) - { - return (null, null); - } - - var releaseInfoChannelRawJson = await client.GetStringAsync(releaseInfoChannelJsonUrl); - return GetLatestVersion(releaseInfoChannelRawJson); - } - - private (List sdks, string runtime) GetLatestVersion(string releaseRawJson) - { - dynamic releaseChannel = JsonConvert.DeserializeObject(releaseRawJson); - - string runtime = null; - var sdks = new List(); - var latestDate = new DateTime(2000, 1, 1); - - foreach (var release in releaseChannel["releases"]) - { - if (!DateTime.TryParse((string)release["release-date"], out DateTime releaseDate)) - { - continue; - } - - if (releaseDate > latestDate) - { - latestDate = releaseDate; - runtime = release["runtime"]["version"]; - sdks = new List(); - foreach (var sdk in release["sdks"]) - { - sdks.Add((string)sdk["version"]); - } - } - } - - return (sdks, runtime); - } - - private Uri GetReleaseInfoChannelUrl(string releaseIndexRawJson, string majorMinor) - { - dynamic releaseIndex = JsonConvert.DeserializeObject(releaseIndexRawJson); - - string releaseChannelJsonUrl = null; - foreach (var release in releaseIndex["releases-index"]) - { - if (release["channel-version"] == majorMinor) - { - releaseChannelJsonUrl = release["releases.json"]; - break; - } - } - - return new Uri(releaseChannelJsonUrl); - } - - } -} diff --git a/release-version-sane/VersionTest.cs b/release-version-sane/VersionTest.cs deleted file mode 100644 index cca0875..0000000 --- a/release-version-sane/VersionTest.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net.Http; -using System.Linq; -using System.Threading.Tasks; -using System.Diagnostics; -using Xunit; - -namespace ReleaseVersionSane -{ - public class VersionTest - { - [Fact] - public async Task VersionIsSane() - { - // This test is meant for release pipelines and verifies the version being built - // either matches the upstream 'major.minor.patch' or 'major.minor.(patch + 1)'. - - string runtimeVersionRaw = GetRuntimeVersion(); - string sdkVersionRaw = GetSdkVersion(); - Version runtimeVersion = Normalize(runtimeVersionRaw); - Version sdkVersion = Normalize(sdkVersionRaw); - - string majorMinor = $"{runtimeVersion.Major}.{runtimeVersion.Minor}"; - var upstream = new UpstreamRelease(); - (List publicSdkVersionsRaw, string publicRuntimeVersionRaw) = await upstream.GetLatestRelease(new HttpClient(), majorMinor); - List publicSdkVersions = publicSdkVersionsRaw.Select(v => Normalize(v)).ToList(); - Version publicRuntimeVersion = Normalize(publicRuntimeVersionRaw); - - Version publicRuntimeVersionNextPatch = new Version(publicRuntimeVersion.Major, - publicRuntimeVersion.Minor, - publicRuntimeVersion.Build + 1); - bool matchesUpstream = runtimeVersion.Equals(publicRuntimeVersion); - bool matchesUpstreamNext = runtimeVersion.Equals(publicRuntimeVersionNextPatch); - Version expectedPublicSdkVersion = null; - if (matchesUpstream) - { - expectedPublicSdkVersion = sdkVersion; - } - else if (matchesUpstreamNext) - { - expectedPublicSdkVersion = new Version(sdkVersion.Major, - sdkVersion.Minor, - sdkVersion.Build - 1); - } - - Assert.True(matchesUpstream || matchesUpstreamNext, $"{runtimeVersionRaw} is not expected with public version {publicRuntimeVersionRaw}"); - Assert.NotNull(expectedPublicSdkVersion); - Assert.Contains(expectedPublicSdkVersion, publicSdkVersions); - } - - private string GetRuntimeVersion() - { - int exitCode = RunProcessAndGetOutput(new string[] { "dotnet" , "--list-runtimes" }, out string result); - if (exitCode != 0) - { - return null; - } - - return result.Split(Environment.NewLine) - .Where(line => line.StartsWith("Microsoft.NETCore.App ")) - .Select(line => line.Split(' ')[1]) - .First(); - } - - private string GetSdkVersion() - { - int exitCode = RunProcessAndGetOutput(new string[] { "dotnet" , "--list-sdks" }, out string result); - if (exitCode != 0) - { - return null; - } - - return result - .Split(Environment.NewLine) - .Select(line => line.Split(' ')[0]) - .First(); - } - - - private static int RunProcessAndGetOutput(string[] processAndArguments, out string standardOutput) - { - ProcessStartInfo startInfo = new ProcessStartInfo(); - startInfo.FileName = processAndArguments[0]; - startInfo.Arguments = string.Join(" ", processAndArguments.Skip(1)); - startInfo.RedirectStandardOutput = true; - - using (Process p = Process.Start(startInfo)) - { - p.WaitForExit(); - using (StreamReader r = p.StandardOutput) - { - standardOutput = r.ReadToEnd(); - } - return p.ExitCode; - } - } - - /// Normalize a version and remove parts that make it invalid. This includes 'preview' and 'rc' tags - public static Version Normalize(string version) - { - return new Version(version.Split('-')[0]); - } - } -} diff --git a/release-version-sane/release-version-sane.csproj b/release-version-sane/release-version-sane.csproj deleted file mode 100644 index e29d18a..0000000 --- a/release-version-sane/release-version-sane.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - true - $(TestTargetFramework) - - false - - - - - - - - - diff --git a/release-version-sane/test.json b/release-version-sane/test.json deleted file mode 100644 index c4ab724..0000000 --- a/release-version-sane/test.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "release-version-sane", - "enabled": true, - "requiresSdk": true, - "version": "3.1", - "versionSpecific": false, - "type": "xunit", - "cleanup": true, - "skipWhen": [ - "github-ci", // Making our CI fail because distro .NET versions are out of date doesn't sound nice - "vmr-ci" // see https://github.com/redhat-developer/dotnet-regular-tests/issues/282 - ] -}