Exemplo n.º 1
0
        public static GitVersion ResolveVersion(Options options, PreviousReleases releases)
        {
            var versionJson = Read("dotnet", $"gitversion /nofetch{(options.Verbose ? " /diag" : "")}", BasePath);

            WriteVerbose(versionJson);

            var jsonOptions = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
            };

            jsonOptions.Converters.Add(new AutoNumberToStringConverter());

            var version = JsonSerializer.Deserialize <GitVersion>(versionJson, jsonOptions);

            if (version.CommitsSinceVersionSource > 0 && version.Equals(releases.Latest))
            {
                ++version.Patch;
                WriteWarning("Patch was incremented because the version was not incremented since last release.");
            }

            if (version.IsPreRelease && NoPrerelease)
            {
                WriteWarning($"Forcing pre-release version '{version.PreReleaseLabel}' to be considered stable");
                version.PreReleaseLabel = null;
            }

            WriteImportant($"Current version is {version.NuGetVersion}");

            return(version);
        }
Exemplo n.º 2
0
        public static GitVersion ResolveVersion(Options options, PreviousReleases releases)
        {
            var versionJson = Read("dotnet", $"gitversion /nofetch{(options.Verbose ? " /diag" : "")}", BasePath);

            WriteVerbose(versionJson);

            if (options.Verbose)
            {
                // Remove extra output from versionJson
                var lines = versionJson
                            .Split('\n')
                            .Select(l => l.TrimEnd('\r'))
                            .SkipWhile(l => !l.StartsWith('{'))
                            .TakeWhile(l => !l.StartsWith('}'))
                            .Append("}");

                versionJson = string.Join('\n', lines);
            }

            var jsonOptions = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
            };

            jsonOptions.Converters.Add(new AutoNumberToStringConverter());

            var version = JsonSerializer.Deserialize <GitVersion>(versionJson, jsonOptions);

            if (version.CommitsSinceVersionSource > 0 && version.Equals(releases.Latest))
            {
                ++version.Patch;
                WriteWarning("Patch was incremented because the version was not incremented since last release.");
            }

            if (version.IsPreRelease && NoPrerelease)
            {
                WriteWarning($"Forcing pre-release version '{version.PreReleaseLabel}' to be considered stable");
                version.PreReleaseLabel = null;
            }

            WriteImportant($"Current version is {version.NuGetVersion}");

            return(version);
        }