protected SemanticVersion FindVersion( GitVersionContext context, BranchType branchType) { var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType); if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch)) { var developVersionFinder = new DevelopVersionFinder(); return(developVersionFinder.FindVersion(context)); } var versionOnMasterFinder = new VersionOnMasterFinder(); var versionFromMaster = versionOnMasterFinder.Execute(context, context.CurrentBranch.Tip.Committer.When); var numberOfCommitsOnBranchSinceCommit = NumberOfCommitsOnBranchSinceCommit(context, ancestor); var sha = context.CurrentBranch.Tip.Sha; var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, 0); var semanticVersion = new SemanticVersion { Major = versionFromMaster.Major, Minor = versionFromMaster.Minor + 1, Patch = 0, PreReleaseTag = "unstable0", BuildMetaData = new SemanticVersionBuildMetaData( numberOfCommitsOnBranchSinceCommit, context.CurrentBranch.Name, releaseDate) }; return(semanticVersion); }
public SemanticVersion FindVersion(GitVersionContext context) { var versionOnMasterFinder = new VersionOnMasterFinder(); var tip = context.CurrentBranch.Tip; var versionFromMaster = versionOnMasterFinder.Execute(context, tip.When()); var f = new CommitFilter { Since = tip, Until = context.Repository.FindBranch("master").Tip, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; var c = context.Repository.Commits.QueryBy(f); var numberOfCommitsSinceRelease = c.Count(); var releaseDate = ReleaseDateFinder.Execute(context.Repository, tip.Sha, 0); var semanticVersion = new SemanticVersion { Major = versionFromMaster.Major, Minor = versionFromMaster.Minor + 1, Patch = 0, PreReleaseTag = "unstable" + numberOfCommitsSinceRelease, BuildMetaData = new SemanticVersionBuildMetaData(numberOfCommitsSinceRelease, context.CurrentBranch.Name, releaseDate), }; return(semanticVersion); }
protected SemanticVersion FindVersion( GitVersionContext context, BranchType branchType, string baseBranchName) { var nbHotfixCommits = NumberOfCommitsInBranchNotKnownFromBaseBranch(context.Repository, context.CurrentBranch, branchType, baseBranchName); var versionString = context.CurrentBranch.GetSuffix(branchType); if (!versionString.Contains(".")) { return(new SemanticVersion()); } var version = SemanticVersion.Parse(versionString); EnsureVersionIsValid(version, context.CurrentBranch, branchType); if (branchType == BranchType.Hotfix) { version.PreReleaseTag = "beta.1"; } if (branchType == BranchType.Release) { version.PreReleaseTag = "beta.1"; } if (branchType == BranchType.Unknown) { version.PreReleaseTag = context.CurrentBranch.Name.Replace("-" + versionString, string.Empty) + ".1"; } var tagVersion = RetrieveMostRecentOptionalTagVersion(context.Repository, version, context.CurrentBranch.Commits.Take(nbHotfixCommits + 1)); var sha = context.CurrentCommit.Sha; var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, version.Patch); var semanticVersion = new SemanticVersion { Major = version.Major, Minor = version.Minor, Patch = version.Patch, PreReleaseTag = version.PreReleaseTag, BuildMetaData = new SemanticVersionBuildMetaData( nbHotfixCommits, context.CurrentBranch.Name, releaseDate) }; if (tagVersion != null) { //If the tag is on the eact commit then dont bump the PreReleaseTag if (context.CurrentCommit.Sha != tagVersion.Commit.Sha) { tagVersion.SemVer.PreReleaseTag.Number++; } semanticVersion.PreReleaseTag = tagVersion.SemVer.PreReleaseTag; } return(semanticVersion); }
SemanticVersion BuildVersion(IRepository repository, Commit tip, int major, int minor, int patch) { var releaseDate = ReleaseDateFinder.Execute(repository, tip.Sha, patch); return(new SemanticVersion { Major = major, Minor = minor, Patch = patch, BuildMetaData = new SemanticVersionBuildMetaData(null, "master", releaseDate) }); }
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); }
protected SemanticVersion FindVersion( GitVersionContext context, BranchType branchType) { var ancestor = FindCommonAncestorWithDevelop(context.Repository, context.CurrentBranch, branchType); if (!IsThereAnyCommitOnTheBranch(context.Repository, context.CurrentBranch)) { var developVersionFinder = new DevelopVersionFinder(); return(developVersionFinder.FindVersion(context)); } var versionOnMasterFinder = new VersionOnMasterFinder(); var versionFromMaster = versionOnMasterFinder.Execute(context, context.CurrentCommit.Committer.When); var numberOfCommitsOnBranchSinceCommit = NumberOfCommitsOnBranchSinceCommit(context, ancestor); var sha = context.CurrentCommit.Sha; var releaseDate = ReleaseDateFinder.Execute(context.Repository, sha, 0); var preReleaseTag = context.CurrentBranch.Name .TrimStart(branchType.ToString() + '-') .TrimStart(branchType.ToString() + '/'); var semanticVersion = new SemanticVersion { Major = versionFromMaster.Major, Minor = versionFromMaster.Minor + 1, Patch = 0, PreReleaseTag = preReleaseTag, BuildMetaData = new SemanticVersionBuildMetaData( numberOfCommitsOnBranchSinceCommit, context.CurrentBranch.Name, releaseDate) }; semanticVersion.OverrideVersionManuallyIfNeeded(context.Repository); return(semanticVersion); }