public void ReturnIfMatch( string muta, string synth, NugetVersionPair pair) { var ret = new NugetsVersioningTarget( new NugetVersioningTarget(muta, NugetVersioningEnum.Match), new NugetVersioningTarget(synth, NugetVersioningEnum.Match)) .ReturnIfMatch(pair); ret.Mutagen.Should().Be(pair.Mutagen); ret.Synthesis.Should().Be(pair.Synthesis); }
public void ReturnIfMatchOther( NugetVersioningEnum versioning, string muta, string synth, NugetVersionPair pair) { var ret = new NugetsVersioningTarget( new NugetVersioningTarget(muta, versioning), new NugetVersioningTarget(synth, versioning)) .ReturnIfMatch(pair); ret.Mutagen.Should().Be(muta); ret.Synthesis.Should().Be(synth); }
public void Swap( XElement proj, NugetVersionPair versions, out NugetVersionPair listedVersions, bool addMissing = true) { listedVersions = new NugetVersionPair(null, null); var missingLibs = new HashSet <string>(MutagenLibraries); XElement?itemGroup = null; foreach (var group in proj.Elements("ItemGroup")) { foreach (var elem in group.Elements().ToArray()) { if (!elem.Name.LocalName.Equals("PackageReference")) { continue; } if (!elem.TryGetAttribute("Include", out var libAttr)) { continue; } string swapInStr; if (libAttr.Value.Equals("Mutagen.Bethesda.Synthesis")) { listedVersions = listedVersions with { Synthesis = elem.Attribute("Version")?.Value }; if (versions.Synthesis == null) { continue; } swapInStr = versions.Synthesis; missingLibs.Remove(libAttr.Value); } else if (MutagenLibraries.Contains(libAttr.Value)) { listedVersions = listedVersions with { Mutagen = elem.Attribute("Version")?.Value }; if (versions.Mutagen == null) { continue; } swapInStr = versions.Mutagen; missingLibs.Remove(libAttr.Value); } else { continue; } elem.SetAttributeValue("Version", swapInStr); } itemGroup = group; } if (itemGroup == null) { throw new ArgumentException("No ItemGroup found in project"); } if (addMissing && versions.Mutagen != null) { foreach (var missing in missingLibs) { itemGroup.Add(new XElement("PackageReference", new XAttribute("Include", missing), new XAttribute("Version", versions.Mutagen))); } } }
public async Task DoWork( NugetVersionPair versions, CancellationToken cancel) { var baseFolder = Path.Combine( _temporaryDirectoryProvider.Path, "SynthesisUnitTests", "Impact"); _fileSystem.Directory.DeleteEntireFolder(baseFolder); using var temp = _tempFolderProvider.Create(baseFolder, deleteAfter: true); var failedDeps = new List <Dependent>(); var projResults = new List <ProjectResult>(); versions = versions with { Mutagen = versions.Mutagen ?? Versions.MutagenVersion, Synthesis = versions.Synthesis ?? Versions.SynthesisVersion, }; System.Console.WriteLine($"Mutagen: {versions.Mutagen}"); System.Console.WriteLine($"Synthesis: {versions.Synthesis}"); var deps = await GitHubDependents.GitHubDependents.GetDependents( user : RegistryConstants.GithubUser, repository : RegistryConstants.GithubRepoName, packageID : RegistryConstants.PackageId, pages : byte.MaxValue) .ToArrayAsync(); bool doThreading = false; await Task.WhenAll(deps.GroupBy(x => x.User).Select(group => TaskExt.Run(doThreading, async() => { cancel.ThrowIfCancellationRequested(); if (group.Key == null) { return; } await Task.WhenAll(group.Select(dependency => TaskExt.Run(doThreading, async() => { cancel.ThrowIfCancellationRequested(); try { if (dependency.User.IsNullOrWhitespace() || dependency.Repository.IsNullOrWhitespace()) { return; } var repoDir = Directory.CreateDirectory(Path.Combine(temp.Dir.Path, group.Key, dependency.Repository)); var clonePath = $"https://github.com/{dependency.User}/{dependency.Repository}"; try { Repository.Clone(clonePath, repoDir.FullName); } catch (Exception ex) { System.Console.Error.WriteLine($"Failed to clone {clonePath}"); System.Console.Error.WriteLine(ex); failedDeps.Add(dependency); return; } cancel.ThrowIfCancellationRequested(); using var repo = new Repository(repoDir.FullName); var slnPath = new SolutionFileLocator( IFileSystemExt.DefaultFilesystem) .GetPath(repo.Info.WorkingDirectory); if (slnPath == null) { System.Console.Error.WriteLine($"Could not get path to solution {clonePath}"); failedDeps.Add(dependency); return; } _modifyRunnerProjects.Modify( solutionPath: slnPath.Value, drivingProjSubPath: string.Empty, versions: versions, out var _); foreach (var proj in _availableProjectsRetriever.Get(slnPath.Value)) { cancel.ThrowIfCancellationRequested(); var path = Path.Combine(repoDir.FullName, proj); if (!ApplicabilityTests.IsMutagenPatcherProject(path)) { System.Console.WriteLine($"Skipping {group.Key}/{dependency.Repository}:{proj}"); continue; } System.Console.WriteLine($"Checking {group.Key}/{dependency.Repository}:{proj}"); var compile = await _build.Compile(path, cancel); if (compile.Failed) { System.Console.WriteLine("Failed compilation"); } projResults.Add(new ProjectResult( dependency, $"{Path.GetDirectoryName(slnPath)}\\{group.Key}\\", proj, compile)); } } catch (Exception ex) { System.Console.Error.WriteLine($"Failed to check {dependency}"); System.Console.Error.WriteLine(ex); return; } })));