Exemplo n.º 1
0
        public CSemVer(int major, int minor, int patch, [CanBeNull] IPrereleaseVersion preRelVer = null, [CanBeNull] string buildmeta = null)
        {
            major.ValidateRange(0, 99999, nameof(major));
            minor.ValidateRange(0, 49999, nameof(minor));
            patch.ValidateRange(0, 9999, nameof(patch));
            if (buildmeta != null)
            {
                buildmeta.ValidateLength(0, 20, nameof(buildmeta));
            }

            Major             = major;
            Minor             = minor;
            Patch             = patch;
            PrereleaseVersion = preRelVer;
            BuildMetadata     = buildmeta;
        }
Exemplo n.º 2
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)));
            }
        }