예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="semVersion"></param>
        /// <param name="commitHash"></param>
        public VersionInfo(SemVersion semVersion, string commitHash)
        {
            // Convert the semVersion into other .Net Version values
            SemVersion         = semVersion;
            SemVersionAsString = semVersion.ToString();

            string prefix = semVersion.Major + "." + semVersion.Minor + "." + semVersion.Patch + ".";

            // Assembly is the semVersion with the 4th value always a zero.
            AssemblyVersion = prefix + "0";

            // File Version
            if (!String.IsNullOrEmpty(semVersion.Prerelease))
            {
                PreRelease = new SemVersionPreRelease(semVersion.Prerelease);
                int fileNum = 1;
                if (PreRelease.ReleaseType == "alpha")
                {
                    fileNum = 100000;
                }
                else if (PreRelease.ReleaseType == "beta")
                {
                    fileNum = 200000;
                }
                fileNum    += PreRelease.ReleaseNumber;
                FileVersion = prefix + fileNum;
            }
            else
            {
                FileVersion = prefix + "1";
            }


            InformationalVersion = SemVersionAsString + ".g" + commitHash;

            NPMVersion = semVersion.Major + "." + semVersion.Minor + "." + semVersion.Patch;
        }
예제 #2
0
파일: Program.cs 프로젝트: SlugEnt/SlugCI
        /// <summary>
        /// Allows user to change the next version of the app - manually.
        /// </summary>
        /// <param name="ciSession"></param>
        /// <param name="slugCi"></param>
        private static void ManualVersionPrompts(CISession ciSession, SlugCI slugCi)
        {
            Misc.WriteMainHeader("Set Version Override");
            Console.ForegroundColor = Color.WhiteSmoke;

            Console.WriteLine();
            Console.WriteLine("This allows you to manually set the primary version numbers of the application for the branch being deployed to.");
            Console.WriteLine();
            Console.WriteLine("You are currently targeting a build to: {0}", ciSession.PublishTarget.ToString());

            bool continueLooping         = true;
            PublishTargetEnum target     = ciSession.PublishTarget;
            string            branchName = target switch
            {
                PublishTargetEnum.Alpha => "alpha",
                PublishTargetEnum.Beta => "beta",
                PublishTargetEnum.Production => ciSession.GitProcessor.MainBranchName,
            };

            SemVersion currentMaxVersion = ciSession.GitProcessor.GetMostRecentVersionTagOfBranch(branchName);
            SemVersion newManualVersion  = new SemVersion(0, 0, 0);

            Console.WriteLine("{0}The latest version on this Branch is: {1}", Environment.NewLine, currentMaxVersion);
            if (target == PublishTargetEnum.Production)
            {
                Console.WriteLine("  (1) To bump the Major version number from {0} to {1}", currentMaxVersion.Major, currentMaxVersion.Major + 1);
                Console.WriteLine("  (2) To bump the Minor version number from {0} to {1}", currentMaxVersion.Minor, currentMaxVersion.Minor + 1);
                Console.WriteLine("  (3) To bump the Patch number from {0} to {1}", currentMaxVersion.Patch, currentMaxVersion.Patch + 1);
                Console.WriteLine("  (9) To change all 3 components at once.");
                while (continueLooping)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey();
                    if (keyInfo.Key == ConsoleKey.D3)
                    {
                        newManualVersion = new SemVersion(currentMaxVersion.Major, currentMaxVersion.Minor, currentMaxVersion.Patch + 1);
                    }
                    else if (keyInfo.Key == ConsoleKey.D2)
                    {
                        newManualVersion = new SemVersion(currentMaxVersion.Major, currentMaxVersion.Minor + 1, 0);
                    }
                    else if (keyInfo.Key == ConsoleKey.D1)
                    {
                        newManualVersion = new SemVersion(currentMaxVersion.Major + 1, 0, 0);
                    }
                    else if (keyInfo.Key == ConsoleKey.D9)
                    {
                        Console.WriteLine("Enter X to exit without changing version  OR  enter Version number in format #.#.#");
                        string manVer = Console.ReadLine();
                        if (manVer == "x" || manVer == "X")
                        {
                            return;
                        }

                        // Change Version
                        if (slugCi.SetVersionManually(manVer))
                        {
                            continueLooping = false;
                        }
                    }

                    else
                    {
                        continue;
                    }
                    break;
                }

                Console.WriteLine("{0} Y/N?  Do you want to set the version for branch {1} to version # {2}", Environment.NewLine, branchName, newManualVersion.ToString());
                while (true)
                {
                    while (Console.KeyAvailable)
                    {
                        Console.ReadKey();
                    }
                    ConsoleKeyInfo keyInfoPYN = Console.ReadKey(true);
                    if (keyInfoPYN.Key == ConsoleKey.Y)
                    {
                        ciSession.ManuallySetVersion = newManualVersion;
                        return;
                    }
                    else if (keyInfoPYN.Key == ConsoleKey.N)
                    {
                        return;
                    }
                }
            }

            // Alpha / Beta branch
            else
            {
                SemVersionPreRelease svpr;
                if (currentMaxVersion.Prerelease != string.Empty)
                {
                    svpr = new SemVersionPreRelease(currentMaxVersion.Prerelease);
                }
                else
                {
                    svpr = new SemVersionPreRelease(branchName, 0, IncrementTypeEnum.Patch);
                }

                Console.WriteLine("  (1) To bump the Major version number from {0} to {1}", currentMaxVersion.Major, currentMaxVersion.Major + 1);
                Console.WriteLine("  (2) To bump the Minor version number from {0} to {1}", currentMaxVersion.Minor, currentMaxVersion.Minor + 1);
                Console.WriteLine("  (3) To bump the Patch number from {0} to {1}", currentMaxVersion.Patch, currentMaxVersion.Patch + 1);
                Console.WriteLine("  (4) To bump the pre-release number from {0} to {1}", svpr.ReleaseNumber, svpr.ReleaseNumber + 1);
                Console.WriteLine("  (9) To change all 3 components at once.");

                while (continueLooping)
                {
                    while (Console.KeyAvailable)
                    {
                        Console.ReadKey();
                    }
                    ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                    if (keyInfo.Key == ConsoleKey.D3)
                    {
                        svpr             = new SemVersionPreRelease(branchName, 0, IncrementTypeEnum.Patch);
                        newManualVersion = new SemVersion(currentMaxVersion.Major, currentMaxVersion.Minor, currentMaxVersion.Patch + 1, svpr.Tag());
                    }
                    else if (keyInfo.Key == ConsoleKey.D2)
                    {
                        svpr             = new SemVersionPreRelease(branchName, 0, IncrementTypeEnum.Minor);
                        newManualVersion = new SemVersion(currentMaxVersion.Major, currentMaxVersion.Minor + 1, 0, svpr.Tag());

                        //svpr.BumpMinor();
                    }
                    else if (keyInfo.Key == ConsoleKey.D1)
                    {
                        svpr             = new SemVersionPreRelease(branchName, 0, IncrementTypeEnum.Major);
                        newManualVersion = new SemVersion(currentMaxVersion.Major + 1, 0, 0, svpr.Tag());

                        //svpr.BumpMajor();
                    }
                    else if (keyInfo.Key == ConsoleKey.D4)
                    {
                        newManualVersion = currentMaxVersion;
                        svpr.BumpVersion();
                    }
                    else if (keyInfo.Key == ConsoleKey.D9)
                    {
                        Console.WriteLine("Enter X to exit without changing version  OR  enter Version number in format #.#.#");
                        string manVer = Console.ReadLine();
                        if (manVer == "x" || manVer == "X")
                        {
                            return;
                        }
                        if (!SemVersion.TryParse(manVer, out SemVersion newVer))
                        {
                            continue;
                        }
                        svpr = new SemVersionPreRelease(branchName, 0, IncrementTypeEnum.None);

                        newManualVersion = new SemVersion(newVer.Major, newVer.Minor, newVer.Patch, svpr.Tag());
                    }
                    else
                    {
                        continue;
                    }
                    break;
                }

                newManualVersion = new SemVersion(newManualVersion.Major, newManualVersion.Minor, newManualVersion.Patch, svpr.Tag());

                Console.WriteLine("{0}Y/N?  Do you want to set the version for branch {1} to version # {2}", Environment.NewLine, branchName, newManualVersion.ToString());
                while (true)
                {
                    while (Console.KeyAvailable)
                    {
                        Console.ReadKey();
                    }
                    ConsoleKeyInfo keyInfoPYN = Console.ReadKey();
                    if (keyInfoPYN.Key == ConsoleKey.Y)
                    {
                        ciSession.ManuallySetVersion = newManualVersion;
                        return;
                    }
                    else if (keyInfoPYN.Key == ConsoleKey.N)
                    {
                        return;
                    }
                }
            }
        }