/// <summary> /// /// </summary> /// <returns></returns> public int DelService() { // Create a config interface var mConfigInterface = new ConfigInterface(); var serviceMenu = new TypedMenu <MenuChoice>(_services, "Choose a service type to delete", x => x.Name); var ynMenu = new TypedMenu <MenuChoice>(_yesNo, "Save this configuration", x => x.Name); var service = serviceMenu.Display(); switch (service.Id) { case "slack": // get the slack models or create a new list var slackModels = mConfigInterface.Config.SlackModels; if (slackModels == null || !slackModels.Any()) { Console.WriteLine("No Slack configurations to delete!"); return(2); } var slackMenu = new TypedMenu <SlackModel>(slackModels, "Choose a slack config delete", x => x.Label); var choice = slackMenu.Display(); slackModels.Remove(choice); mConfigInterface.Config.SlackModels = slackModels; break; case "cancel": Console.WriteLine("Oh well maybe next time."); return(130); default: Console.WriteLine("You dirty dog, you!"); return(2); // No way you should have gotten here! } // Prompt to confirm var shouldSave = ynMenu.Display(); switch (shouldSave.Id) { case "yes": Console.Write("Saving... "); if (mConfigInterface.WriteConfig()) { Console.WriteLine("Saved!"); return(0); } else { Console.WriteLine("Save Error!"); return(2); } default: // If we did not get yes return a 130 Console.WriteLine("Oh well maybe next time."); return(130); } }
/// <summary> /// Flow to create a new environment group /// </summary> /// <returns></returns> private static async Task CreateEnvironmentGroup() { Console.WriteLine("Creating new Environment Group"); //Get GroupName Console.WriteLine("Enter new group name:"); var groupName = Console.ReadLine(); EnvironmentGroup newGroup = new EnvironmentGroup(); newGroup.Name = groupName; //Get all projects var allProject = await _appVeyorService.GetAllAppVeyorProjects(); Console.WriteLine("Pick a Project:"); var menu = new TypedMenu<AppVeyorProject>(allProject, "Choose a number", x => x.Name); var pickedProject = menu.Display(); newGroup.Project = pickedProject; //Get all environments var allEnv = await _appVeyorService.GetAllAppVeyorEnvironmentsForProject(newGroup.Project.AccountName + "/" + newGroup.Project.Slug); AskForEnvironment(newGroup, allEnv); //Save group //Write JSON to file _groupFileService.SaveGroupToFile(newGroup); Console.WriteLine("Saved Environment Group {0} with {1} environments", newGroup.Name, newGroup.Environments.Count); }
/// <summary> /// Flow to create a new environment group /// </summary> /// <returns></returns> private static async Task CreateEnvironmentGroup() { Console.WriteLine("Creating new Environment Group"); //Get GroupName Console.WriteLine("Enter new group name:"); var groupName = Console.ReadLine(); EnvironmentGroup newGroup = new EnvironmentGroup(); newGroup.Name = groupName; //Get all projects var allProject = await _appVeyorService.GetAllAppVeyorProjects(); Console.WriteLine("Pick a Project:"); var menu = new TypedMenu <AppVeyorProject>(allProject, "Choose a number", x => x.Name); var pickedProject = menu.Display(); newGroup.Project = pickedProject; //Get all environments var allEnv = await _appVeyorService.GetAllAppVeyorEnvironments(); AskForEnvironment(newGroup, allEnv); //Save group //Write JSON to file _groupFileService.SaveGroupToFile(newGroup); Console.WriteLine("Saved Environment Group {0} with {1} environments", newGroup.Name, newGroup.Environments.Count); }
/// <summary> /// Flow to create a new SwapGroup /// </summary> /// <returns></returns> private static async Task CreateSwapGroup() { Console.WriteLine("Creating new Swap Group"); //Get GroupName Console.WriteLine("Enter new group name:"); var groupName = Console.ReadLine(); SwapGroup newGroup = new SwapGroup(); newGroup.Name = groupName; var client = new WebSiteManagementClient(credentials); client.SubscriptionId = subscriptionId; var resourceClient = new ResourceManagementClient(credentials); resourceClient.SubscriptionId = subscriptionId; var resourceGroups = resourceClient.ResourceGroups.List(); var resourceGroepMenu = new TypedMenu <ResourceGroup>(resourceGroups.ToList(), "Choose a resource group", x => x.Name); var resourceGroup = resourceGroepMenu.Display(); var allWebsites = client.WebApps.ListByResourceGroup(resourceGroup.Name).ToList(); AskForSlot(newGroup, resourceGroup, client, allWebsites); //Save group //Write JSON to file _groupFileService.SaveGroupToFile(newGroup); Console.WriteLine("Saved SwapSlots Group {0} with {1} SwapSlots", newGroup.Name, newGroup.SwapSlots.Count); }
private static void ChooseMenu(TypedMenu <SimpleClass> menu) { var choice = menu.Display(); Console.WriteLine("You chose: {0}", choice.Name); Console.ReadKey(true); Console.Clear(); }
/// <summary> /// Adds a new service to our config /// </summary> /// <returns></returns> public int AddService() { // Create a config interface var mConfigInterface = new ConfigInterface(); var serviceMenu = new TypedMenu <MenuChoice>(_services, "Choose a service to configure", x => x.Name); var ynMenu = new TypedMenu <MenuChoice>(_yesNo, "Save this configuration", x => x.Name); var service = serviceMenu.Display(); switch (service.Id) { case "slack": // Create a new slack config var slackConfig = new SlackModel(); // get the slack models or create a new list var slackModels = mConfigInterface.Config.SlackModels ?? new List <SlackModel>(); // Prompt for the config options slackConfig.PromptForNew(); // Add the config to our main config slackModels.Add(slackConfig); // Set the new array mConfigInterface.Config.SlackModels = slackModels; break; case "cancel": Console.WriteLine("Oh well maybe next time."); return(130); default: Console.WriteLine("You dirty dog, you!"); return(2); // No way you should have gotten here! } // Prompt to confirm var shouldSave = ynMenu.Display(); switch (shouldSave.Id) { case "yes": Console.Write("Saving... "); if (mConfigInterface.WriteConfig()) { Console.WriteLine("Saved!"); return(0); } else { Console.WriteLine("Save Error!"); return(2); } default: // If we did not get yes return a 130 Console.WriteLine("Oh well maybe next time."); return(130); } }
public void CreateDefaultMenu <T>(IMetamodelBuilder metamodel, string menuName, string id) { var menu = new TypedMenu <T>(metamodel, false, menuName) { Id = id }; menu.AddRemainingNativeActions(); menu.AddContributedActions(); Menu = menu; }
static async Task MainAsync(string[] args) { //Get AppVeyor API key from first argument if (args.Any()) { _aadTenantDomain = args.First(); } //Or ask for AppVeyor API key if (string.IsNullOrWhiteSpace(_aadTenantDomain)) { Console.WriteLine("Enter Active Directory Tenant domain (yourname.onmicrosoft.com):"); _aadTenantDomain = Console.ReadLine(); if (string.IsNullOrEmpty(_aadTenantDomain)) { Console.WriteLine("No domain, exiting"); return; } } var login = await GetAccessTokenAsync(); credentials = new TokenCredentials(login.AccessToken); var subClient = new SubscriptionClient(credentials); var subs = subClient.Subscriptions.List(); if (subs.Count() == 1) { subscriptionId = subs.First().SubscriptionId; } else { var subMenu = new TypedMenu <Subscription>(subs.ToList(), "Choose a subscription", x => x.DisplayName); var sub = subMenu.Display(); subscriptionId = sub.SubscriptionId; } var choices = new List <Func <Task> > { CreateSwapGroup, NewSwap }; //Present menu of choices var menu = new TypedMenu <Func <Task> >(choices, "Choose a number", x => x.Method.Name); var picked = menu.Display(); picked().Wait(); }
/// <summary> /// Ask for an slot to add to a group /// </summary> /// <param name="newGroup"></param> /// <param name="allEnv"></param> private static void AskForSlot(SwapGroup newGroup, ResourceGroup resourceGroup, WebSiteManagementClient client, List <Site> allWebsites) { Console.WriteLine("Pick a website:"); var filteredWebsites = allWebsites.ToList().Where(x => !newGroup.SwapSlots.Select(s => s.Website).Contains(x.Name)).ToList(); var websiteMenu = new TypedMenu <Site>(filteredWebsites, "Choose a website", x => x.Name); var website = websiteMenu.Display(); var websiteSlots = client.WebApps.ListSlots(resourceGroup.Name, website.Name); if (!websiteSlots.Any()) { Console.WriteLine("No slots found"); } else if (websiteSlots.Count() == 1) { var slot = websiteSlots.First(); Console.WriteLine("Found 1 slot, using: " + slot.Name); var name = slot.Name.Replace(slot.RepositorySiteName + "/", string.Empty); newGroup.SwapSlots.Add(new SlotConfig() { Name = name, ResourceGroup = resourceGroup.Name, Website = website.Name }); } else { var slotMenu = new TypedMenu <Site>(websiteSlots.ToList(), "Choose a slot", x => x.Name); var slot = slotMenu.Display(); var name = slot.Name.Replace(slot.RepositorySiteName + "/", string.Empty); newGroup.SwapSlots.Add(new SlotConfig() { Name = name, ResourceGroup = resourceGroup.Name, Website = website.Name }); } Console.WriteLine("Add another slot? (Y/N) (default Y)"); var answer = Console.ReadLine(); if (answer.Equals("N", StringComparison.InvariantCultureIgnoreCase)) { return; } else { AskForSlot(newGroup, resourceGroup, client, allWebsites); } }
static Task MainAsync(string[] args) { string appVeyorKey = null; //Get AppVeyor API key from first argument if (args.Any()) { appVeyorKey = args.First(); } //Or ask for AppVeyor API key if (string.IsNullOrWhiteSpace(appVeyorKey)) { Console.WriteLine("Enter AppVeyor API key:"); appVeyorKey = Console.ReadLine(); if (string.IsNullOrEmpty(appVeyorKey)) { Console.WriteLine("No key, exiting"); return(null); } } //Initialize the service _appVeyorService = new AppVeyorService(appVeyorKey); var choices = new List <Func <Task> > { CreateEnvironmentGroup, NewDeploy }; //Present menu of choices var menu = new TypedMenu <Func <Task> >(choices, "Choose a number", x => x.Method.Name); var picked = menu.Display(); picked().Wait(); return(Task.FromResult(string.Empty)); }
/// <summary> /// Ask for an environment to add to a group /// </summary> /// <param name="newGroup"></param> /// <param name="allEnv"></param> private static void AskForEnvironment(EnvironmentGroup newGroup, List <AppVeyorEnvironment> allEnv) { Console.WriteLine("Pick an Environment:"); var menu = new TypedMenu <AppVeyorEnvironment>(allEnv.Except(newGroup.Environments).ToList(), "Choose a number", x => x.Name); var picked = menu.Display(); newGroup.Environments.Add(picked); Console.WriteLine("Add another environment? (Y/N) (default Y)"); var answer = Console.ReadLine(); if (answer.Equals("N", StringComparison.InvariantCultureIgnoreCase)) { return; } else { AskForEnvironment(newGroup, allEnv); } }
/// <summary> /// Flow to create a new environment group /// </summary> /// <returns></returns> private static async Task CreateEnvironmentGroup() { Console.WriteLine("Creating new Environment Group"); //Get GroupName Console.WriteLine("Enter new group name:"); var groupName = Console.ReadLine(); EnvironmentGroup newGroup = new EnvironmentGroup(); newGroup.Name = groupName; Console.WriteLine("Default branch (develop):"); var defaultBranch = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(defaultBranch)) { newGroup.DefaultBranch = defaultBranch; } //Get all projects Console.WriteLine("Fetching projects..."); var allProject = await _appVeyorService.GetAllAppVeyorProjects(); Console.WriteLine("Pick a Project:"); var menu = new TypedMenu <AppVeyorProject>(allProject, "Choose a number", x => x.Name); var pickedProject = menu.Display(); newGroup.Project = pickedProject; //Get all environments var allEnv = await _appVeyorService.GetAllAppVeyorEnvironmentsForProject(newGroup.Project.AccountName + "/" + newGroup.Project.Slug); AskForEnvironment(newGroup, allEnv); //Save group //Write JSON to file _groupFileService.SaveGroupToFile(newGroup); Console.WriteLine("Saved Environment Group {0} with {1} environments", newGroup.Name, newGroup.Environments.Count); }
static Task MainAsync(string[] args) { string appVeyorKey = ""; //Get AppVeyor API key from first argument if (args.Any()) appVeyorKey = args.First(); //Or ask for AppVeyor API key if (string.IsNullOrWhiteSpace(appVeyorKey)) { Console.WriteLine("Enter AppVeyor API key:"); appVeyorKey = Console.ReadLine(); if (string.IsNullOrEmpty(appVeyorKey)) { Console.WriteLine("No key, exiting"); return null; } } //Initialize the service _appVeyorService = new AppVeyorService(appVeyorKey); var choices = new List<Func<Task>> { CreateEnvironmentGroup, NewDeploy }; //Present menu of choices var menu = new TypedMenu<Func<Task>>(choices, "Choose a number", x => x.Method.Name); var picked = menu.Display(); picked().Wait(); return Task.FromResult(string.Empty); }
/// <summary> /// Flow to trigger a new deploy /// </summary> /// <returns></returns> private static async Task NewDeploy() { Console.WriteLine("Which Group do you want to deploy to?"); //Get all groups from disk string path = Directory.GetCurrentDirectory(); var allFiles = Directory.GetFiles(path, "*.group.json"); if (!allFiles.Any()) { Console.WriteLine("No group.json files found! Please create an environment group first."); return; } List <EnvironmentGroup> groupList = allFiles.Select(_groupFileService.ReadGroupFile).ToList(); var menu = new TypedMenu <EnvironmentGroup>(groupList, "Choose a number", x => x.Name); var picked = menu.Display(); Console.WriteLine("Going to deploy: " + picked.Name); Console.WriteLine("Project: " + picked.Project.Name); picked.Environments.ForEach(x => Console.WriteLine("Env: " + x.Name)); //Get version to deploy Console.WriteLine("Enter build version to deploy:"); var buildVersion = Console.ReadLine(); Console.WriteLine("Are you sure? (Y/N) (default N)"); var answer = Console.ReadLine(); if (answer.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { //Create new deploys for each environment in this group await DeployEnvironmentGroup(picked, buildVersion); } }
/// <summary> /// Flow to trigger a new deploy /// </summary> /// <returns></returns> private static async Task NewDeploy() { Console.WriteLine("Which Group do you want to deploy to?"); //Get all groups from disk string path = Directory.GetCurrentDirectory(); var allFiles = Directory.GetFiles(path, "*.group.json"); if (!allFiles.Any()) { Console.WriteLine("No group.json files found! Please create an environment group first."); return; } List<EnvironmentGroup> groupList = allFiles.Select(_groupFileService.ReadGroupFile).ToList(); var menu = new TypedMenu<EnvironmentGroup>(groupList, "Choose a number", x => x.Name); var picked = menu.Display(); Console.WriteLine("Going to deploy: " + picked.Name); Console.WriteLine("Project: " + picked.Project.Name); picked.Environments.ForEach(x => Console.WriteLine("Env: " + x.Name)); //Get version to deploy Console.WriteLine("Enter build version to deploy:"); var buildVersion = Console.ReadLine(); Console.WriteLine("Are you sure? (Y/N) (default N)"); var answer = Console.ReadLine(); if (answer.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { //Create new deploys for each environment in this group await DeployEnvironmentGroup(picked, buildVersion); } }
/// <summary> /// Flow to trigger a new deploy /// </summary> /// <returns></returns> private static async Task NewSwap() { Console.WriteLine("Which Swap Group do you want to swap?"); //Get all groups from disk string path = Directory.GetCurrentDirectory(); var allFiles = Directory.GetFiles(path, "*.swap.json"); if (!allFiles.Any()) { Console.WriteLine("No group.json files found! Please create a SwapGroup first."); return; } List <SwapGroup> groupList = allFiles.Select(_groupFileService.ReadGroupFile).ToList(); var menu = new TypedMenu <SwapGroup>(groupList, "Choose a number", x => x.Name); var picked = menu.Display(); Console.WriteLine("-------------------------------------------------------"); Console.WriteLine(); Console.WriteLine($"You want to swap {picked.Name}"); foreach (var swapSlot in picked.SwapSlots) { Console.WriteLine(swapSlot.Website + " - " + swapSlot.Name); } Console.WriteLine("Are you sure? (Y/N) (default N)"); var answer = Console.ReadLine(); Console.WriteLine(); var client = new WebSiteManagementClient(credentials); client.SubscriptionId = subscriptionId; if (answer.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { List <Task> swapTasks = new List <Task>(); foreach (var slot in picked.SwapSlots) { Console.WriteLine($"Begin swapping: {slot.Website} - {slot.Name}"); swapTasks.Add(WaitForSwap(slot, client.WebApps.SwapSlotWithProductionWithHttpMessagesAsync(slot.ResourceGroup, slot.Website, new Microsoft.Azure.Management.WebSites.Models.CsmSlotEntity() { TargetSlot = slot.Name }))); } Console.WriteLine("Waiting for swaps to finish..."); if (swapTasks.Any()) { await Task.WhenAll(swapTasks); } Console.WriteLine("Finished all swap operations!"); } //Start CDN Purge if (picked.CdnPurgeConfigs.Any()) { Console.WriteLine("Do you want to purge CDNs?? (Y/N) (default N)"); foreach (var purge in picked.CdnPurgeConfigs) { Console.WriteLine(purge.EndpointName); } var purgeAnswer = Console.ReadLine(); if (purgeAnswer.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { Console.WriteLine("Start CDN Purge"); var cdnClient = new Microsoft.Azure.Management.Cdn.CdnManagementClient(credentials); cdnClient.SubscriptionId = subscriptionId; List <Task> purgeTasks = new List <Task>(); foreach (var purge in picked.CdnPurgeConfigs) { Console.WriteLine($"Begin purge: {purge.EndpointName}"); purgeTasks.Add(WaitForCdnPurge(purge, cdnClient.Endpoints.PurgeContentWithHttpMessagesAsync(purge.ResourceGroup, purge.ProfileName, purge.EndpointName, new List <string>() { "/*" }))); } Console.WriteLine("Waiting for purge actions to finish..."); if (purgeTasks.Any()) { await Task.WhenAll(purgeTasks); } Console.WriteLine("Finished CDN Purge"); } } }
/// <summary> /// Flow to trigger a new deploy /// </summary> /// <returns></returns> private static async Task NewDeploy() { Console.WriteLine("Which Group do you want to deploy to?"); //Get all groups from disk string path = Directory.GetCurrentDirectory(); var allFiles = Directory.GetFiles(path, "*.group.json"); if (!allFiles.Any()) { Console.WriteLine("No group.json files found! Please create an environment group first."); return; } List<EnvironmentGroup> groupList = allFiles.Select(_groupFileService.ReadGroupFile).ToList(); var menu = new TypedMenu<EnvironmentGroup>(groupList, "Choose a number", x => x.Name); var picked = menu.Display(); Console.WriteLine("Deploying"); Console.WriteLine("---------"); Console.WriteLine("Environment group: " + picked.Name); Console.WriteLine("Project: " + picked.Project.Name); Console.WriteLine(); Console.WriteLine("AppVeyor environments:"); picked.Environments.ForEach(x => Console.WriteLine(" - " + x.Name)); Console.WriteLine(); Console.Write("(develop) Fetching last 10 project builds..."); var projectBuildsResponse = await _appVeyorService.GetProjectBuilds(picked.Project.AccountName, picked.Project.Slug); Console.WriteLine("Done!"); Console.Write("(develop) Fetching last deployable builds..."); var deployableBuildsResponse = await _appVeyorService.GetDeployableBuilds(picked.Project.AccountName, picked.Project.Slug); Console.WriteLine("Done!"); Console.WriteLine(); Console.WriteLine("Last 5 deployable (succesful) builds"); Console.WriteLine("------------------------------------"); // filter out: // pullRequestId's - when given, then these builds are associated with PR's. Which we do not want // branch == develop - we only care about 'develop' branches. var deployableDevelopBuilds = deployableBuildsResponse.Builds.Where(b => string.IsNullOrEmpty(b.PullRequestId) && b.Branch == "develop").ToList(); var allDevelopBuilds = projectBuildsResponse.Builds.Where(b => string.IsNullOrEmpty(b.PullRequestId) && b.Branch == "develop").ToList(); int count = 1; foreach (Build deployableBuild in deployableDevelopBuilds) { Console.WriteLine($"{deployableBuild.Version} / {deployableBuild.Branch} / commit message:\n{deployableBuild.Message}\n"); count++; if (count > 5) break; } var latestDeployableBuild = deployableDevelopBuilds.First(); if (allDevelopBuilds.Count > 0 && deployableDevelopBuilds.Count > 0) { var projectBuild = allDevelopBuilds.First(); Console.WriteLine($"Comparing versions of latest build vs latest deployable: {projectBuild.Version} vs {latestDeployableBuild.Version}"); if (projectBuild.Version != latestDeployableBuild.Version) { Console.WriteLine(); Console.WriteLine("!! WARNING !! -> Newer (non-deployable) build detected:"); Console.WriteLine( $"Build version: {projectBuild.Version} - status: {projectBuild.Status} - branch: {projectBuild.Branch} - message: {projectBuild.Message}"); Console.WriteLine("!! WARNING !!"); } } //Get version to deploy string buildVersion = latestDeployableBuild?.Version; Console.WriteLine(); Console.WriteLine("-------------------------------------------------------"); Console.Write($"Enter build version to deploy (default {buildVersion}) : "); var inputVersion = Console.ReadLine(); if (!string.IsNullOrEmpty(inputVersion)) { buildVersion = inputVersion; } Console.WriteLine("-------------------------------------------------------"); Console.WriteLine(); Console.WriteLine($"You want to deploy {buildVersion}"); Console.WriteLine("Are you sure? (Y/N) (default N)"); var answer = Console.ReadLine(); Console.WriteLine(); if (answer.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { //Create new deploys for each environment in this group var deploymentIds = await DeployEnvironmentGroup(picked, buildVersion); //Monitor deployments await WaitForDeployments(deploymentIds); } }
/// <summary> /// Ask for an environment to add to a group /// </summary> /// <param name="newGroup"></param> /// <param name="allEnv"></param> private static void AskForEnvironment(EnvironmentGroup newGroup, List<AppVeyorEnvironment> allEnv) { Console.WriteLine("Pick an Environment:"); var menu = new TypedMenu<AppVeyorEnvironment>(allEnv.Except(newGroup.Environments).ToList(), "Choose a number", x => x.Name); var picked = menu.Display(); newGroup.Environments.Add(picked); Console.WriteLine("Add another environment? (Y/N) (default Y)"); var answer = Console.ReadLine(); if (answer.Equals("N", StringComparison.InvariantCultureIgnoreCase)) return; else AskForEnvironment(newGroup, allEnv); }
static void Main() { Console.Title = "ConsoleMenu Test App"; var choices = new List <SimpleClass> { new SimpleClass { Name = "One" }, new SimpleClass { Name = "Two" }, new SimpleClass { Name = "Three" }, new SimpleClass { Name = "Four" }, }; var tooManyChoices = new List <SimpleClass>(choices); tooManyChoices.AddRange(new List <SimpleClass> { new SimpleClass { Name = "Five" }, new SimpleClass { Name = "Six" }, new SimpleClass { Name = "Seven" }, new SimpleClass { Name = "Eight" }, new SimpleClass { Name = "Nine" }, new SimpleClass { Name = "Ten" }, new SimpleClass { Name = "Eleven" }, new SimpleClass { Name = "Twelve" }, }); var menu = new TypedMenu <SimpleClass>(choices, "Choose a number", x => x.Name); ChooseMenu(menu); const int defaultVal = 2; var menuWithDefault = new TypedMenu <SimpleClass>(choices, "Choose a number (with default)", x => x.Name, choices[defaultVal - 1]); ChooseMenu(menuWithDefault); var tooManyChoicesMenu = new TypedMenu <SimpleClass>(tooManyChoices, "Choose a number (there are more on the next screen)", x => x.Name); ChooseMenu(tooManyChoicesMenu); }
/// <summary> /// Flow to trigger a new deploy /// </summary> /// <returns></returns> private static async Task NewDeploy() { Console.WriteLine("Which Group do you want to deploy to?"); //Get all groups from disk string path = Directory.GetCurrentDirectory(); var allFiles = Directory.GetFiles(path, "*.group.json"); if (!allFiles.Any()) { Console.WriteLine("No group.json files found! Please create an environment group first."); return; } List <EnvironmentGroup> groupList = allFiles.Select(_groupFileService.ReadGroupFile).ToList(); var menu = new TypedMenu <EnvironmentGroup>(groupList, "Choose a number", x => x.Name); var picked = menu.Display(); Console.WriteLine("Deploying"); Console.WriteLine("---------"); Console.WriteLine("Environment group: " + picked.Name); Console.WriteLine("Project: " + picked.Project.Name); Console.WriteLine(); Console.WriteLine("AppVeyor environments:"); picked.Environments.ForEach(x => Console.WriteLine(" - " + x.Name)); Console.WriteLine(); Console.Write("(develop) Fetching last 10 project builds..."); var projectBuildsResponse = await _appVeyorService.GetProjectBuilds(picked.Project.AccountName, picked.Project.Slug); Console.WriteLine("Done!"); Console.Write("(develop) Fetching last deployable builds..."); var deployableBuildsResponse = await _appVeyorService.GetDeployableBuilds(picked.Project.AccountName, picked.Project.Slug); Console.WriteLine("Done!"); Console.WriteLine(); Console.WriteLine("Last 5 deployable (succesful) builds"); Console.WriteLine("------------------------------------"); // filter out: // pullRequestId's - when given, then these builds are associated with PR's. Which we do not want var branch = picked.DefaultBranch; if (string.IsNullOrWhiteSpace(branch)) { branch = "develop"; } var deployableDevelopBuilds = deployableBuildsResponse.Builds.Where(b => string.IsNullOrEmpty(b.PullRequestId) && b.Branch == branch).ToList(); var allDevelopBuilds = projectBuildsResponse.Builds.Where(b => string.IsNullOrEmpty(b.PullRequestId) && b.Branch == branch).ToList(); int count = 1; foreach (Build deployableBuild in deployableDevelopBuilds) { Console.WriteLine($"{deployableBuild.Version} / {deployableBuild.Branch} / commit message:\n{deployableBuild.Message}\n"); count++; if (count > 5) { break; } } var latestDeployableBuild = deployableDevelopBuilds.FirstOrDefault(); if (allDevelopBuilds.Count > 0 && deployableDevelopBuilds.Count > 0) { var projectBuild = allDevelopBuilds.First(); Console.WriteLine($"Comparing versions of latest build vs latest deployable: {projectBuild.Version} vs {latestDeployableBuild.Version}"); if (projectBuild.Version != latestDeployableBuild?.Version) { Console.WriteLine(); Console.WriteLine("!! WARNING !! -> Newer (non-deployable) build detected:"); Console.WriteLine( $"Build version: {projectBuild.Version} - status: {projectBuild.Status} - branch: {projectBuild.Branch} - message: {projectBuild.Message}"); Console.WriteLine("!! WARNING !!"); } } //Get version to deploy string buildVersion = latestDeployableBuild?.Version; Console.WriteLine(); Console.WriteLine("-------------------------------------------------------"); if (!string.IsNullOrEmpty(buildVersion)) { Console.Write($"Enter build version to deploy (default {buildVersion}) : "); } else { Console.Write($"Enter build version to deploy: "); } var inputVersion = Console.ReadLine(); if (!string.IsNullOrEmpty(inputVersion)) { buildVersion = inputVersion; } Console.WriteLine("-------------------------------------------------------"); Console.WriteLine(); Console.WriteLine($"You want to deploy {buildVersion}"); Console.WriteLine("Are you sure? (Y/N) (default N)"); var answer = Console.ReadLine(); Console.WriteLine(); if (answer.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { //Create new deploys for each environment in this group var deploymentIds = await DeployEnvironmentGroup(picked, buildVersion); //Monitor deployments await WaitForDeployments(deploymentIds); } }