Exemple #1
0
        public CSemVer CreateSemVer(bool isAutomatedBuild, bool isPullRequestBuild, DateTime timeStamp)
        {
            using (var repo = new LibGit2Sharp.Repository(Path.GetDirectoryName(BuildVersionXmlFile)))
            {
                Commit head = repo.Head.Tip;

                IPrereleaseVersion preReleaseInfo = null;
                var buildMode = repo.GetBuildMode(isAutomatedBuild, isPullRequestBuild, ReleaseBranch);
                switch (buildMode)
                {
                case BuildMode.LocalDev:
                    // local dev builds are always newer than any other builds
                    preReleaseInfo = new CIPreReleaseVersion("DEV", GetBuildIndexFromUtc(timeStamp.ToUniversalTime()), "zz");
                    break;

                case BuildMode.PullRequest:
                    // PR builds should have a higher precedence than CI or release so that the
                    // builds pull in the components built in previous stages of the current build
                    // instead of the official CI or released builds.
                    preReleaseInfo = new CIPreReleaseVersion("PRQ", GetBuildIndexFromUtc(head.Author.When.UtcDateTime), "pr");
                    break;

                case BuildMode.ContinuousIntegration:
                    preReleaseInfo = new CIPreReleaseVersion("BLD", GetBuildIndexFromUtc(timeStamp.ToUniversalTime()));
                    break;

                case BuildMode.OfficialRelease:
                    if (!string.IsNullOrWhiteSpace(PreReleaseName))
                    {
                        preReleaseInfo = new OfficialPreRelease(PreReleaseName, PreReleaseNumber, PreReleaseFix);
                    }

                    break;

                default:
                    throw new InvalidOperationException("Unexpected/Unsupported repository state");
                }

                return(new CSemVer(BuildMajor, BuildMinor, BuildPatch, preReleaseInfo, head.Id.Sha.Substring(0, 8)));
            }
        }