public void BumpPatch_Success(string preRelease, IncrementTypeEnum incrementType, string expected) { SemVersionPreRelease start = new SemVersionPreRelease(preRelease); if (incrementType == IncrementTypeEnum.Patch) { start.BumpPatch(); } else if (incrementType == IncrementTypeEnum.Minor) { start.BumpMinor(); } else if (incrementType == IncrementTypeEnum.Major) { start.BumpMajor(); } else { start.BumpVersion(); } SemVersionPreRelease end = new SemVersionPreRelease(expected); Assert.AreEqual(expected, start.Tag(), "A10:"); Assert.AreEqual(end.ReleaseNumber, start.ReleaseNumber, "A20:"); Assert.AreEqual(start.ReleaseType, end.ReleaseType, "A30:"); Assert.AreEqual(end.IncrementType, start.IncrementType, "A40:"); }
public void Tag_success(string releaseType, int numeric, IncrementTypeEnum incrementType, string expTag) { SemVersionPreRelease sem = new SemVersionPreRelease(releaseType, numeric, incrementType); Assert.AreEqual(releaseType, sem.ReleaseType, "A10:"); Assert.AreEqual(numeric, sem.ReleaseNumber, "A20:"); Assert.AreEqual(incrementType, sem.IncrementType, "A30:"); Assert.AreEqual(expTag, sem.Tag(), "A40:"); }
public void Constructor_String__Success(string preTag, bool success, string releaseType, int numValue, IncrementTypeEnum incrementType) { if (success) { Assert.DoesNotThrow(() => new SemVersionPreRelease(preTag), "A10:"); SemVersionPreRelease sem = new SemVersionPreRelease(preTag); Assert.AreEqual(releaseType, sem.ReleaseType, "A20:"); Assert.AreEqual(numValue, sem.ReleaseNumber); Assert.AreEqual(incrementType, sem.IncrementType, "A30:"); } else { Assert.Throws <Exception>(() => new SemVersionPreRelease(preTag), "A100:"); } }
/// <summary> /// Computes the version for the Alpha Branch. /// </summary> /// <param name="comparisonBranch"></param> private void CalculateAlphaVersion(GitBranchInfo comparisonBranch) { // See if main is newer and if it's tag is newer. If so we need to set the comparison's // tag to the main version and then add the alpha / beta to it... SemVersion tempVersion = CompareToMainVersion(mostRecentBranchTypeVersion, comparisonBranch.Name); // If this is the first Version tag on an alpha branch then create new. SemVersionPreRelease semPre; if (tempVersion.Prerelease != string.Empty) { semPre = new SemVersionPreRelease(tempVersion.Prerelease); } else { semPre = new SemVersionPreRelease("alpha", 0, IncrementTypeEnum.None); } if (incrementMinor) { semPre.BumpMinor(); } else if (incrementPatch) { semPre.BumpPatch(); } else if (incrementMajor) { semPre.BumpMajor(); } else { semPre.BumpVersion(); } newVersion = new SemVersion(tempVersion.Major, tempVersion.Minor, tempVersion.Patch, semPre.Tag()); }
/// <summary> /// Runs the Calculate Version process /// </summary> /// <returns></returns> protected override StageCompletionStatusEnum ExecuteProcess() { currentBranchName = CISession.GitProcessor.CurrentBranch.ToLower(); GitBranchInfo comparisonBranch = null; string branchToFind = ""; if (CISession.PublishTarget == PublishTargetEnum.Alpha) { branchToFind = "alpha"; } if (CISession.PublishTarget == PublishTargetEnum.Beta) { branchToFind = "beta"; } if (CISession.PublishTarget == PublishTargetEnum.Production) { branchToFind = CISession.GitProcessor.MainBranchName; } // Make sure branch exists. if (!CISession.GitBranches.TryGetValue(branchToFind, out comparisonBranch)) { ControlFlow.Assert(true == false, "The destination branch [" + branchToFind + "] does not exist. You must manually create this branch."); } // Get Main Branch info mainBranch = CISession.GitBranches [CISession.GitProcessor.MainBranchName]; GitBranchInfo currentBranch = CISession.GitBranches [CISession.GitProcessor.CurrentBranch]; // If version has been set by user manually, then we validate it and set it. if (CISession.ManuallySetVersion != null) { ControlFlow.Assert(CISession.ManuallySetVersion > currentBranch.LatestSemVersionOnBranch, "Manually set version must be greater than the most current version on the branch deploying to"); string releaseType = ""; if (CISession.PublishTarget == PublishTargetEnum.Alpha) { releaseType = "alpha"; } else if (CISession.PublishTarget == PublishTargetEnum.Beta) { releaseType = "beta"; } else if (CISession.PublishTarget == PublishTargetEnum.Production) { newVersion = CISession.ManuallySetVersion; CISession.VersionInfo = new VersionInfo(newVersion, currentBranch.LatestCommitOnBranch.CommitHash); return(StageCompletionStatusEnum.Success); } SemVersionPreRelease semPre = new SemVersionPreRelease(releaseType, 0, IncrementTypeEnum.None); newVersion = new SemVersion(CISession.ManuallySetVersion.Major, CISession.ManuallySetVersion.Minor, CISession.ManuallySetVersion.Patch, semPre.Tag()); CISession.VersionInfo = new VersionInfo(newVersion, currentBranch.LatestCommitOnBranch.CommitHash); AOT_Info("Success: Manual Version Set: " + newVersion); return(StageCompletionStatusEnum.Success); } // If the top commit on branch is already version tagged, then we are assuming they want to // finish off later steps that might not have run successfully previously. if ((CISession.PublishTarget == PublishTargetEnum.Production && currentBranch.Name == mainBranch.Name) || CISession.PublishTarget != PublishTargetEnum.Production) { SemVersion mostCurrentSemVerOnBranch = currentBranch.LatestCommitOnBranch.GetGreatestVersionTag(); SemVersion zero = new SemVersion(0, 0, 0); if (mostCurrentSemVerOnBranch > zero) { CISession.WasPreviouslyCommitted = true; newVersion = mostCurrentSemVerOnBranch; CISession.VersionInfo = new VersionInfo(newVersion, currentBranch.LatestCommitOnBranch.CommitHash); AOT_Warning("No changes require a version change. Assuming this is a continuation of a prior post compile failure."); AOT_Info("No Version Change! Existing Version is: " + newVersion); return(StageCompletionStatusEnum.Success); } } // Determine the potential version bump... incrementPatch = (currentBranchName.StartsWith("fix") || currentBranchName.StartsWith("bug")); incrementMinor = (currentBranchName.StartsWith("feature") || currentBranchName.StartsWith("feat")); incrementMajor = (currentBranchName.StartsWith("major")); // Set IncrementPatch if it is not a key branch name and none of the above is set. if (!incrementMajor && !incrementMinor && !incrementPatch) { if (currentBranchName != "alpha" && currentBranchName != "beta" && currentBranchName != CISession.GitProcessor.MainBranchName) { incrementPatch = true; } } string versionPreReleaseName = "alpha"; if (CISession.PublishTarget == PublishTargetEnum.Beta) { versionPreReleaseName = "beta"; } // Get most recent Version Tag for the desired branch type mostRecentBranchTypeVersion = GetMostRecentVersionTagOfBranch(currentBranch); //mostRecentBranchTypeVersion = CISession.GitProcessor.GetMostRecentVersionTagOfBranch(versionPreReleaseName); if (CISession.PublishTarget == PublishTargetEnum.Production) { CalculateMainVersion(); } else if (CISession.PublishTarget == PublishTargetEnum.Alpha) { CalculateAlphaVersion(comparisonBranch); } else if (CISession.PublishTarget == PublishTargetEnum.Beta) { CalculateBetaVersion(comparisonBranch); } else { throw new ApplicationException("Publish Target of [" + CISession.PublishTarget.ToString() + "] has no implemented functionality"); } // Store the version that should be set for the build. CISession.VersionInfo = new VersionInfo(newVersion, currentBranch.LatestCommitOnBranch.CommitHash); AOT_Info("New Version is: " + newVersion); return(StageCompletionStatusEnum.Success); }
/// <summary> /// Calculate version of project when Target is Beta /// </summary> /// <param name="comparisonBranch"></param> private void CalculateBetaVersion(GitBranchInfo comparisonBranch) { // Find the parents max version number. GitCommitInfo commitBeta = comparisonBranch.LatestCommitOnBranch; // Look for the highest version number from one of its parents and keep it. SemVersion newestVersion = new SemVersion(0, 0, 0); foreach (string commitHash in commitBeta.ParentCommits) { GitCommitInfo commitInfo = CISession.GitProcessor.GetCommitInfo(commitHash); SemVersion parentVersion = commitInfo.GetGreatestVersionTag(); if (parentVersion > newestVersion) { newestVersion = parentVersion; } } SemVersionPreRelease updatedBeta; // Build New PreRelease tag based upon old, but with new number and type set to Beta. if (mostRecentBranchTypeVersion > newestVersion) { newestVersion = mostRecentBranchTypeVersion; updatedBeta = new SemVersionPreRelease(newestVersion.Prerelease); } else { // Get pre-release of the newest version, which is not a beta branch SemVersionPreRelease preOld = new SemVersionPreRelease(newestVersion.Prerelease); // Get pre-release of most current beta branch version SemVersionPreRelease currentBeta = new SemVersionPreRelease(mostRecentBranchTypeVersion.Prerelease); // Update the beta to be of the Increment Type if (currentBeta.IncrementType < preOld.IncrementType) { updatedBeta = new SemVersionPreRelease(currentBeta.ReleaseType, currentBeta.ReleaseNumber, preOld.IncrementType); } else { updatedBeta = currentBeta; } newestVersion = new SemVersion(newestVersion.Major, newestVersion.Minor, newestVersion.Patch, updatedBeta.Tag()); } // Increase version if (incrementMinor) { updatedBeta.BumpMinor(); } else if (incrementPatch) { updatedBeta.BumpPatch(); } else if (incrementMajor) { updatedBeta.BumpMajor(); } else { updatedBeta.BumpVersion(); } newVersion = new SemVersion(newestVersion.Major, newestVersion.Minor, newestVersion.Patch, updatedBeta.Tag()); }