コード例 #1
0
        public static IEnumerable <object[]> GetShouldCompareSemanticVersionsParams()
        {
            var versions = new[]
            {
                "1.0-alpha",
                "1.0-alpha.2",
                "1.0-alpha.11",
                "1.0-alpha.beta",
                "1.0-beta",
                "1.0",
                "2.0-alpha",
                "2.0-alpha.2",
                "2.0-alpha.11",
                "2.0-alpha.beta",
                "2.0-beta",
                "2.0"
            };

            for (var x = 0; x < versions.Length; x++)
            {
                for (var y = 0; y < versions.Length; y++)
                {
                    SemanticVersionParser.TryParse(versions[x], out var semanticVersionX);
                    SemanticVersionParser.TryParse(versions[y], out var semanticVersionY);
                    var expectedResult = x.CompareTo(y);

                    yield return(new object[] { semanticVersionX, semanticVersionY, expectedResult });
                }
            }
        }
コード例 #2
0
        private VersionTaggedCommit GetVersion(IRepository gitRepo)
        {
            var branch = gitRepo.FindBranch("master");
            var tags   = gitRepo.Tags.Select(t =>
            {
                SemanticVersion version;
                if (SemanticVersionParser.TryParse(t.Name.TrimStart('v'), out version))
                {
                    return(new VersionTaggedCommit((Commit)t.Target, version));
                }
                return(null);
            })
                         .Where(a => a != null)
                         .ToArray();
            var olderThan        = branch.Tip.Committer.When;
            var lastTaggedCommit =
                branch.Commits.FirstOrDefault(c => c.Committer.When <= olderThan && tags.Any(a => a.Commit == c));

            if (lastTaggedCommit != null)
            {
                return(tags.Last(a => a.Commit.Sha == lastTaggedCommit.Sha));
            }

            // Create a next version txt as 0.1.0
            var filePath = Path.Combine(workingDirectory, "NextVersion.txt");

            if (!File.Exists(filePath))
            {
                File.WriteAllText(filePath, "0.1.0");
            }

            var commit = branch.Commits.Last();

            return(new VersionTaggedCommit(commit, new SemanticVersion()));
        }
コード例 #3
0
        public bool IsODataLegacy(CodeGenerationContext context)
        {
            Version version;
            string  packageVersion = base.Repository.GetPackageVersion(context, NuGetPackages.ODataNuGetPackageId);

            SemanticVersionParser.TryParse(packageVersion, out version);
            return(version < new Version(5, 2, 0));
        }
コード例 #4
0
        public void ShouldTryParse(string s, long major, long minor, string preRelease)
        {
            SemanticVersionParser.TryParse(s, out var semanticVersion)
            .ShouldBeTrue();

            semanticVersion.Major.ShouldBe(major);
            semanticVersion.Minor.ShouldBe(minor);
            semanticVersion.PreRelease.ShouldBe(preRelease);
        }
コード例 #5
0
        public void CanParseFourPartVersionNumber()
        {
            SemanticVersion semanticVersion;

            SemanticVersionParser.TryParse("1.2.3.4", out semanticVersion);

            Assert.Equal(1, semanticVersion.Major);
            Assert.Equal(2, semanticVersion.Minor);
            Assert.Equal(3, semanticVersion.Patch);
            Assert.Equal(4, semanticVersion.BuildMetaData);
        }
コード例 #6
0
        public bool Validate(ValidationContext validationContext)
        {
            var parserResult = SemanticVersionParser.Parse(validationContext.ValidVersions);

            if (string.IsNullOrEmpty(validationContext.Version))
            {
                if (validationContext.Optional)
                {
                    return(true);
                }

                validationContext.ErrorMessage = parserResult.ValidationErrorMessage;
                return(false);
            }

            if (!SemanticVersionParser.TryParse(validationContext.Version, out var semanticVersion))
            {
                validationContext.ErrorMessage = parserResult.ValidationErrorMessage;
                return(false);
            }

            foreach (var declaredVersion in parserResult.DeclaredVersions)
            {
                if (semanticVersion.Major != declaredVersion.SemanticVersion.Major)
                {
                    continue;
                }

                var comparison =
                    SemanticVersionComparer.Default.Compare(semanticVersion, declaredVersion.SemanticVersion);

                if (comparison > 0)
                {
                    continue;
                }

                validationContext.MatchedVersion = declaredVersion.String;
                return(true);
            }

            validationContext.ErrorMessage = parserResult.ValidationErrorMessage;
            return(false);
        }
コード例 #7
0
        public SemanticVersion GetNextVersion()
        {
            var filePath = Path.Combine(repositoryDirectory, "NextVersion.txt");

            if (!File.Exists(filePath))
            {
                return(new SemanticVersion());
            }
            var version = File.ReadAllText(filePath);

            if (string.IsNullOrEmpty(version))
            {
                return(new SemanticVersion());
            }

            SemanticVersion semanticVersion;

            if (!SemanticVersionParser.TryParse(version, out semanticVersion))
            {
                throw new ArgumentException("Make sure you have a valid semantic version in NextVersion.txt");
            }

            return(semanticVersion);
        }