Beispiel #1
0
        private static void MaybeShowLagging(Repository repo, List <Tag> allTags, ApiMetadata api)
        {
            var currentVersion = api.StructuredVersion;

            // Skip anything that is naturally pre-release (in the API), or where the current release is GA already.
            if (!api.CanHaveGaRelease || currentVersion.Prerelease is null)
            {
                return;
            }

            // Find all the existing prereleases for the expected "next GA" release.
            var    expectedGa          = StructuredVersion.FromMajorMinorPatch(currentVersion.Major, currentVersion.Minor, currentVersion.Patch, prerelease: null);
            string expectedGaPrefix    = $"{api.Id}-{expectedGa}";
            var    matchingReleaseTags = allTags.Where(tag => tag.FriendlyName.StartsWith(expectedGaPrefix, StringComparison.Ordinal)).ToList();

            // Skip if we haven't even released the current prerelease.
            if (matchingReleaseTags.Count == 0)
            {
                return;
            }

            var latest   = GitHelpers.GetDate(matchingReleaseTags.First());
            var earliest = GitHelpers.GetDate(matchingReleaseTags.Last());

            string dateRange = latest == earliest
                ? $"{latest:yyyy-MM-dd}"
                : $"{earliest:yyyy-MM-dd} - {latest:yyyy-MM-dd}";

            Console.WriteLine($"{api.Id,-50}{api.Version,-20}{dateRange}");
        }
Beispiel #2
0
 /// <summary>
 /// Returns the previous version that the given new version *must* be compatible with,
 /// and the required level of compatibility. The version part is null if no compatibility
 /// check is required.
 /// </summary>
 private static (StructuredVersion version, Level level) GetRequiredCompatibility(StructuredVersion newVersion)
 {
     if (newVersion.Patch != 0)
     {
         // A patch version must be identical to major.minor.0.
         var oldVersion = StructuredVersion.FromMajorMinorPatch(newVersion.Major, newVersion.Minor, 0, null);
         return(oldVersion, Level.Identical);
     }
     else if (newVersion.Minor == 0)
     {
         // A new major version doesn't need to check anything.
         return(null, Level.Identical);
     }
     else
     {
         // A new minor version must be compatible with the previous minor version
         var oldVersion = StructuredVersion.FromMajorMinorPatch(newVersion.Major, newVersion.Minor - 1, 0, null);
         return(oldVersion, Level.Minor);
     }
 }
        protected override void ExecuteImpl(string[] args)
        {
            string id = args[0];

            // It's slightly inefficient that we load the API catalog once here and once later on, and the code duplication
            // is annoying too, but it's insignficant really - and at least the code is simple.
            var catalog = ApiCatalog.Load();
            var api     = catalog[id];
            var version = IncrementStructuredVersion(api.StructuredVersion).ToString();

            new SetVersionCommand().Execute(new[] { id, version });

            StructuredVersion IncrementStructuredVersion(StructuredVersion originalVersion)
            {
                // Any GA version just increments the minor version.
                if (originalVersion.Prerelease is null)
                {
                    return(StructuredVersion.FromMajorMinorPatch(originalVersion.Major, originalVersion.Minor + 1, 0, null));
                }

                // For prereleases, expect something like "beta01" which should be incremented to "beta02".
                var prereleasePattern = new Regex(@"^([^\d]*)(\d+)$");
                var match             = prereleasePattern.Match(originalVersion.Prerelease);

                if (!match.Success)
                {
                    throw new UserErrorException($"Don't know how to auto-increment version '{originalVersion}'");
                }
                var prefix = match.Groups[1].Value;
                var suffix = match.Groups[2].Value;

                if (!int.TryParse(suffix, out var counter))
                {
                    throw new UserErrorException($"Don't know how to auto-increment version '{originalVersion}'");
                }
                counter++;
                var newSuffix = counter.ToString().PadLeft(suffix.Length, '0');

                return(StructuredVersion.FromMajorMinorPatch(originalVersion.Major, originalVersion.Minor, originalVersion.Patch, $"{prefix}{newSuffix}"));
            }
        }