Esempio n. 1
0
        public SemanticVersion NextVersion()
        {
            var versionZero         = new SemanticVersion();
            var lastRelease         = lastTaggedReleaseFinder.GetVersion().SemVer;
            var fileVersion         = nextVersionTxtFileFinder.GetNextVersion();
            var mergedBranchVersion = mergedBranchesWithVersionFinder.GetVersion();
            var otherBranchVersion  = unknownBranchFinder.FindVersion(context);

            if (otherBranchVersion != null && otherBranchVersion.PreReleaseTag != null && otherBranchVersion.PreReleaseTag.Name == "release")
            {
                otherBranchVersion.PreReleaseTag.Name = "beta";
            }

            var maxCalculated = new[] { fileVersion, otherBranchVersion, mergedBranchVersion }.Max();

            if (lastRelease == versionZero && maxCalculated == versionZero)
            {
                return(new SemanticVersion
                {
                    Minor = 1
                });
            }

            if (maxCalculated <= lastRelease)
            {
                return(new SemanticVersion
                {
                    Major = lastRelease.Major,
                    Minor = lastRelease.Minor,
                    Patch = lastRelease.Patch + 1
                });
            }

            return(maxCalculated);
        }
Esempio n. 2
0
        public VersionAndBranch GetBuildNumber(GitVersionContext context)
        {
            var commit = lastTaggedReleaseFinder.GetVersion().Commit;
            var commitsSinceLastRelease = NumberOfCommitsOnBranchSinceCommit(gitRepo.Head, commit);
            var semanticVersion         = nextSemverCalculator.NextVersion();

            semanticVersion.PreReleasePartTwo = commitsSinceLastRelease;
            if (context.CurrentBranch.IsPullRequest())
            {
                EnsurePullBranchShareACommonAncestorWithMaster(gitRepo, gitRepo.Head);
                var extractIssueNumber = ExtractIssueNumber(context);
                semanticVersion.Tag    = "unstable" + extractIssueNumber;
                semanticVersion.Suffix = extractIssueNumber;
                return(new VersionAndBranch
                {
                    BranchName = context.CurrentBranch.Name,
                    BranchType = BranchType.PullRequest,
                    Sha = context.CurrentBranch.Tip.Sha,
                    Version = semanticVersion
                });
            }

            return(new VersionAndBranch
            {
                BranchName = context.CurrentBranch.Name,
                BranchType = BranchType.Master,
                Sha = context.CurrentBranch.Tip.Sha,
                Version = semanticVersion
            });
        }
Esempio n. 3
0
        int GetCommitsSinceLastRelease(GitVersionContext context)
        {
            int commitsSinceLastRelease;
            VersionTaggedCommit versionTaggedCommit;

            if (lastTaggedReleaseFinder.GetVersion(out versionTaggedCommit))
            {
                commitsSinceLastRelease = NumberOfCommitsOnBranchSinceCommit(context, versionTaggedCommit.Commit);
            }
            else
            {
                commitsSinceLastRelease = NumberOfCommitsOnBranchSinceCommit(context, context.CurrentBranch.Commits.Last());
            }
            return(commitsSinceLastRelease);
        }
Esempio n. 4
0
        public IEnumerable <SemanticVersion> GetPossibleVersions()
        {
            VersionTaggedCommit lastTaggedRelease;

            if (lastTaggedReleaseFinder.GetVersion(out lastTaggedRelease))
            {
                //If the exact commit is tagged then just return that commit
                if (context.CurrentCommit.Sha == lastTaggedRelease.Commit.Sha)
                {
                    yield return(lastTaggedRelease.SemVer);

                    yield break;
                }
                yield return(new SemanticVersion
                {
                    Major = lastTaggedRelease.SemVer.Major,
                    Minor = lastTaggedRelease.SemVer.Minor,
                    Patch = lastTaggedRelease.SemVer.Patch + 1
                });
            }

            SemanticVersion fileVersion;

            if (nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion))
            {
                yield return(fileVersion);
            }
            SemanticVersion tryGetVersion;

            if (mergedBranchesWithVersionFinder.TryGetVersion(out tryGetVersion))
            {
                yield return(tryGetVersion);
            }

            SemanticVersion otherBranchVersion;

            if (unknownBranchFinder.FindVersion(context, out otherBranchVersion))
            {
                yield return(otherBranchVersion);
            }
        }
Esempio n. 5
0
        public SemanticVersion GetBuildNumber(GitVersionContext context)
        {
            var commit = lastTaggedReleaseFinder.GetVersion().Commit;
            var commitsSinceLastRelease = NumberOfCommitsOnBranchSinceCommit(context, commit);
            var semanticVersion         = nextSemverCalculator.NextVersion();

            var sha         = context.CurrentCommit.Sha;
            var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, semanticVersion.Patch);

            // TODO Need a way of setting this in a cross cutting way
            semanticVersion.BuildMetaData = new SemanticVersionBuildMetaData(commitsSinceLastRelease,
                                                                             context.CurrentBranch.Name, releaseDate);
            if (context.CurrentBranch.IsPullRequest())
            {
                EnsurePullBranchShareACommonAncestorWithMaster(gitRepo, gitRepo.Head);
                var extractIssueNumber = ExtractIssueNumber(context);
                semanticVersion.PreReleaseTag = "PullRequest" + extractIssueNumber;
                return(semanticVersion);
            }

            return(semanticVersion);
        }
        public IEnumerable <SemanticVersion> GetPossibleVersions()
        {
            // always provide a minimum fallback version for other strategies
            var defaultNextVersion = new SemanticVersion
            {
                Minor = 1
            };

            yield return(defaultNextVersion);

            VersionTaggedCommit lastTaggedRelease;

            if (lastTaggedReleaseFinder.GetVersion(out lastTaggedRelease))
            {
                //If the exact commit is tagged then just return that commit
                if (context.CurrentCommit.Sha == lastTaggedRelease.Commit.Sha)
                {
                    yield return(lastTaggedRelease.SemVer);

                    yield break;
                }
                defaultNextVersion = new SemanticVersion
                {
                    Major = lastTaggedRelease.SemVer.Major,
                    Minor = lastTaggedRelease.SemVer.Minor,
                    Patch = lastTaggedRelease.SemVer.Patch + 1
                };
                yield return(defaultNextVersion);
            }

            SemanticVersion fileVersion;
            var             hasNextVersionTxtVersion = nextVersionTxtFileFinder.TryGetNextVersion(out fileVersion);

            if (hasNextVersionTxtVersion && !string.IsNullOrEmpty(context.Configuration.NextVersion))
            {
                throw new Exception("You cannot specify a next version in both NextVersion.txt and GitVersionConfig.yaml. Please delete NextVersion.txt and use GitVersionConfig.yaml");
            }

            if (!string.IsNullOrEmpty(context.Configuration.NextVersion))
            {
                yield return(SemanticVersion.Parse(context.Configuration.NextVersion, context.Configuration.TagPrefix));
            }

            if (hasNextVersionTxtVersion)
            {
                yield return(fileVersion);
            }

            SemanticVersion tryGetVersion;

            if (mergedBranchesWithVersionFinder.TryGetVersion(out tryGetVersion))
            {
                yield return(tryGetVersion);
            }

            SemanticVersion otherBranchVersion;

            if (unknownBranchFinder.FindVersion(context, defaultNextVersion, out otherBranchVersion))
            {
                yield return(otherBranchVersion);
            }
        }