private async Task <int> CoherencyUpdatesAsync( IRemote barOnlyRemote, IRemoteFactory remoteFactory, List <DependencyDetail> currentDependencies, List <DependencyDetail> dependenciesToUpdate) { Console.WriteLine("Checking for coherency updates..."); CoherencyMode coherencyMode = CoherencyMode.Legacy; if (_options.StrictCoherency) { coherencyMode = CoherencyMode.Strict; } List <DependencyUpdate> coherencyUpdates = null; try { // Now run a coherency update based on the current set of dependencies updated // from the previous pass. coherencyUpdates = await barOnlyRemote.GetRequiredCoherencyUpdatesAsync( currentDependencies, remoteFactory, coherencyMode); } catch (DarcCoherencyException e) { Console.WriteLine("Coherency updates failed for the following dependencies:"); foreach (var error in e.Errors) { Console.WriteLine($" Unable to update {error.Dependency.Name} to have coherency with " + $"{error.Dependency.CoherentParentDependencyName}: {error.Error}"); foreach (string potentialSolution in error.PotentialSolutions) { Console.WriteLine($" - {potentialSolution}"); } } return(Constants.ErrorCode); } foreach (DependencyUpdate dependencyUpdate in coherencyUpdates) { DependencyDetail from = dependencyUpdate.From; DependencyDetail to = dependencyUpdate.To; DependencyDetail coherencyParent = currentDependencies.First(d => d.Name.Equals(from.CoherentParentDependencyName, StringComparison.OrdinalIgnoreCase)); // Print out what we are going to do. Console.WriteLine($"Updating '{from.Name}': '{from.Version}' => '{to.Version}' " + $"to ensure coherency with {from.CoherentParentDependencyName}@{coherencyParent.Version}"); // Final list of dependencies to update dependenciesToUpdate.Add(to); } return(Constants.SuccessCode); }
private void ThenGetRequiredUpdatesShouldHaveBeenCalled(Build withBuild, CoherencyMode withCoherencyMode) { var assets = new List <IEnumerable <AssetData> >(); var dependencies = new List <IEnumerable <DependencyDetail> >(); DarcRemotes[TargetRepo] .Verify(r => r.GetRequiredNonCoherencyUpdatesAsync(SourceRepo, NewCommit, Capture.In(assets), Capture.In(dependencies))); DarcRemotes[TargetRepo] .Verify(r => r.GetDependenciesAsync(TargetRepo, TargetBranch, null, false)); DarcRemotes[TargetRepo] .Verify(r => r.GetRequiredCoherencyUpdatesAsync(Capture.In(dependencies), RemoteFactory.Object, withCoherencyMode)); assets.Should() .BeEquivalentTo( new List <List <AssetData> > { withBuild.Assets.Select( a => new AssetData(false) { Name = a.Name, Version = a.Version }) .ToList() }); }
private async Task <int> CoherencyUpdatesAsync( IRemote barOnlyRemote, IRemoteFactory remoteFactory, List <DependencyDetail> currentDependencies, List <DependencyDetail> dependenciesToUpdate) { Console.WriteLine("Checking for coherency updates..."); CoherencyMode coherencyMode = CoherencyMode.Strict; if (_options.LegacyCoherency) { coherencyMode = CoherencyMode.Legacy; } else { Console.WriteLine("Using 'Strict' coherency mode. If this fails, a second attempt utilizing 'Legacy' Coherency mode will be made."); } List <DependencyUpdate> coherencyUpdates = null; bool updateSucceeded = false; try { // Now run a coherency update based on the current set of dependencies updated from the previous pass. coherencyUpdates = await barOnlyRemote.GetRequiredCoherencyUpdatesAsync(currentDependencies, remoteFactory, coherencyMode); updateSucceeded = true; } catch (DarcCoherencyException e) { PrettyPrintCoherencyErrors(e); } if (coherencyMode == CoherencyMode.Strict && !updateSucceeded) { Console.WriteLine("Attempting fallback to Legacy coherency"); try { // Now run a coherency update based on the current set of dependencies updated from the previous pass. coherencyUpdates = await barOnlyRemote.GetRequiredCoherencyUpdatesAsync(currentDependencies, remoteFactory, CoherencyMode.Legacy); Console.WriteLine("... Legacy-mode fallback worked"); updateSucceeded = true; } catch (DarcCoherencyException e) { PrettyPrintCoherencyErrors(e); } } if (!updateSucceeded) { return(Constants.ErrorCode); } foreach (DependencyUpdate dependencyUpdate in coherencyUpdates) { DependencyDetail from = dependencyUpdate.From; DependencyDetail to = dependencyUpdate.To; DependencyDetail coherencyParent = currentDependencies.First(d => d.Name.Equals(from.CoherentParentDependencyName, StringComparison.OrdinalIgnoreCase)); // Print out what we are going to do. Console.WriteLine($"Updating '{from.Name}': '{from.Version}' => '{to.Version}' " + $"to ensure coherency with {from.CoherentParentDependencyName}@{coherencyParent.Version}"); // Final list of dependencies to update dependenciesToUpdate.Add(to); } return(Constants.SuccessCode); }