protected override async Task <int> Run(CommandLineApplication command) { var file = GetStringFromUser(VariablesWithProfileOptionNames.File, string.Empty, false); var config = StandardSerialiser.DeserializeFromJsonNet <VariableSetCollection>(File.ReadAllText(file)); if (config != null) { foreach (var varSet in config.VariableSets) { System.Console.WriteLine(String.Format(languageProvider.GetString(LanguageSection.UiStrings, "UpdatingVariableSet"), varSet.Id, varSet.Variables.Count)); try { await octoHelper.UpdateVariableSet(varSet); } catch (Exception e) { System.Console.WriteLine(String.Format(languageProvider.GetString(LanguageSection.UiStrings, "FailedUpdatingVariableSet"), e.Message)); return(-1); } } } else { System.Console.WriteLine(languageProvider.GetString(LanguageSection.UiStrings, "FailedParsingVariableFile")); } System.Console.WriteLine(String.Format(languageProvider.GetString(LanguageSection.UiStrings, "Done"), string.Empty)); return(0); }
public async Task StartJob(string pathToProfile, string message, string releaseVersion, bool forceDeploymentIfSamePackage) { if (!File.Exists(pathToProfile)) { this.WriteLine("Couldn't find file at " + pathToProfile); return; } try { var job = StandardSerialiser.DeserializeFromJsonNet <EnvironmentDeployment>(File.ReadAllText(pathToProfile)); var projects = new List <ProjectDeployment>(); foreach (var project in job.ProjectDeployments) { var octoProject = await this.helper.GetProject(project.ProjectId, job.EnvironmentId, project.ChannelVersionRange, project.ChannelVersionTag); var packages = await this.helper.GetPackages(octoProject.ProjectId, project.ChannelVersionRange, project.ChannelVersionTag); IList <PackageStep> defaultPackages = null; foreach (var package in project.Packages) { if (package.PackageId == "latest") { // Filter to packages specifically for this package step, then update the package versions var availablePackages = packages.Where(pack => pack.StepId == package.StepId); // If there are no packages for this step, check if we've been asked to jump back to default channel. if ((!availablePackages.Any() || availablePackages.First().SelectedPackage == null) && job.FallbackToDefaultChannel && !string.IsNullOrEmpty(configuration.DefaultChannel)) { if (defaultPackages == null) { var defaultChannel = await this.helper.GetChannelByName(project.ProjectId, configuration.DefaultChannel); defaultPackages = await this.helper.GetPackages(project.ProjectId, defaultChannel.VersionRange, defaultChannel.VersionTag); // We're now using the default channel, so update the project release to have the correct channel info for the deployment. project.ChannelId = defaultChannel.Id; project.ChannelName = defaultChannel.Name; project.ChannelVersionRange = defaultChannel.VersionRange; project.ChannelVersionTag = defaultChannel.VersionTag; } availablePackages = defaultPackages.Where(pack => pack.StepId == package.StepId); } var selectedPackage = availablePackages.First().SelectedPackage; if (selectedPackage != null) { package.PackageId = selectedPackage.Id; package.PackageName = selectedPackage.Version; package.StepName = selectedPackage.StepName; } else { System.Console.Out.WriteLine(string.Format(languageProvider.GetString(LanguageSection.UiStrings, "NoSuitablePackageFound"), package.StepName, project.ProjectName)); continue; } } } if (!forceDeploymentIfSamePackage) { if (!await IsDeploymentRequired(job, project)) { continue; } } if (!string.IsNullOrEmpty(message)) { project.ReleaseMessage = message; } if (!string.IsNullOrEmpty(releaseVersion)) { project.ReleaseVersion = releaseVersion; } projects.Add(project); } job.ProjectDeployments = projects; await this.deployer.StartJob(job, this, true); } catch (Exception e) { this.WriteLine("Couldn't deploy! " + e.Message + e.StackTrace); } }
public async Task StartJob(string pathToProfile, string message, string releaseVersion, bool forceDeploymentIfSamePackage) { if (!File.Exists(pathToProfile)) { this.WriteLine("Couldn't find file at " + pathToProfile); return; } try { var job = StandardSerialiser.DeserializeFromJsonNet <EnvironmentDeployment>(File.ReadAllText(pathToProfile)); var projects = new List <ProjectDeployment>(); foreach (var project in job.ProjectDeployments) { var octoProject = await this._helper.GetProject(project.ProjectId, job.EnvironmentId, project.ChannelVersionRange); if (project.PackageId == "latest") { var packages = await this._helper.GetPackages(octoProject.ProjectId, project.ChannelVersionRange); project.PackageId = packages.First().Id; project.PackageName = packages.First().Version; project.StepName = packages.First().StepName; } if (!forceDeploymentIfSamePackage) { var currentRelease = await this._helper.GetReleasedVersion(project.ProjectId, job.EnvironmentId); if (currentRelease != null && !string.IsNullOrEmpty(currentRelease.Id)) { var release = await this._helper.GetRelease(currentRelease.Id); var currentPackage = release.SelectedPackages[0]; if (currentPackage.Version == project.PackageName) { continue; } } } if (!string.IsNullOrEmpty(message)) { project.ReleaseMessage = message; } if (!string.IsNullOrEmpty(releaseVersion)) { project.ReleaseVersion = releaseVersion; } projects.Add(project); } job.ProjectDeployments = projects; await this._deployer.StartJob(job, this, true); } catch (Exception e) { this.WriteLine("Couldn't deploy! " + e.Message + e.StackTrace); } }