/// <summary> /// Ensures the Deploy Folders have a value and that it can be accessed. If no value then it prompts user for value /// </summary> /// <param name="config"></param> /// <param name="slugCiConfig"></param> /// <returns></returns> private bool ValidateDeployFolders(PublishTargetEnum config, SlugCIConfig slugCiConfig) { // Does the config have a root folder set? if (!slugCiConfig.IsRootFolderSpecified(config)) { string name = config.ToString(); Misc.WriteSubHeader(name + ": Set Deploy Folder"); Console.WriteLine("The [" + config + "] deployment folder is undefined in the SlugCI config file, You can enter a value OR press enter to force the system to look for and use environment variables.", Color.DarkOrange); Console.WriteLine( "--: If you want to always use the environment variables for these entries, just hit the Enter key. Otherwise enter a valid path to the root location they should be deployed too.", Color.DarkOrange); bool invalidAnswer = true; string answer = ""; while (invalidAnswer) { Console.WriteLine(); Console.WriteLine("Enter the root deployment folder for {0} [{1}]", Color.DarkCyan, name, config); answer = Console.ReadLine(); answer = answer.Trim(); if (answer == string.Empty) { answer = "_"; } // Make sure such a folder exists. if (answer != "_") { if (DirectoryExists((AbsolutePath)answer)) { invalidAnswer = false; } } else { invalidAnswer = false; } } if (config == PublishTargetEnum.Production) { slugCiConfig.DeployProdRoot = answer; } else if (config == PublishTargetEnum.Alpha) { slugCiConfig.DeployAlphaRoot = answer; } else if (config == PublishTargetEnum.Beta) { slugCiConfig.DeployBetaRoot = answer; } else if (config == PublishTargetEnum.Development) { slugCiConfig.DeployDevRoot = answer; } } return(true); }
/// <summary> /// Validates that the DeployRoot folder based upon the current config is set to a value. /// </summary> /// <param name="config"></param> /// <returns></returns> public bool IsRootFolderSpecified(PublishTargetEnum config) { string value = ""; if (config == PublishTargetEnum.Production) { value = DeployProdRoot; } else if (config == PublishTargetEnum.Beta) { value = DeployBetaRoot; } else if (config == PublishTargetEnum.Alpha) { value = DeployAlphaRoot; } else if (config == PublishTargetEnum.Development) { value = DeployDevRoot; } else { throw new ArgumentException("PublishTargetEnum: Value was not in IF logic. Probably means a code update needs to be done."); } if (value == null) { return(false); } if (value == string.Empty) { return(false); } if (value.Trim() == string.Empty) { return(false); } return(true); }
/// <summary> /// Determines if the root folder for the given config is set to use environment variables or is unset. /// </summary> /// <param name="config"></param> /// <returns></returns> public bool IsRootFolderUsingEnvironmentVariable(PublishTargetEnum config) { if (config == PublishTargetEnum.Production) { return(DeployProdRoot == "_"); } else if (config == PublishTargetEnum.Beta) { return(DeployBetaRoot == "_"); } else if (config == PublishTargetEnum.Alpha) { return(DeployAlphaRoot == "_"); } else if (config == PublishTargetEnum.Development) { return(DeployDevRoot == "_"); } else { throw new ArgumentException("PublishTargetEnum: Value was not in IF logic. Probably means a code update needs to be done."); } }
/// <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; } } } }