public async Task ToStringCallsNameProvider( SolutionPatcherRun sut) { sut.NameProvider.ClearReceivedCalls(); sut.ToString(); var n = sut.NameProvider.Received(1).Name; }
public async Task PrepCallsService( CancellationToken cancel, SolutionPatcherRun sut) { await sut.Prep(cancel); await sut.PrepService.Received(1).Prep(cancel); }
public async Task PassesSettingsToRunner( RunSynthesisPatcher settings, CancellationToken cancel, SolutionPatcherRun sut) { await sut.Run(settings, cancel); await sut.SolutionPatcherRunner.Received(1).Run(settings, cancel); }
public async Task PrintsSha( RunSynthesisPatcher settings, CancellationToken cancel, SolutionPatcherRun sut) { await sut.Run(settings, cancel); sut.PrintShaIfApplicable.Received(1).Print(); }
public static void SwapInDesiredVersionsForSolution( string solutionPath, string drivingProjSubPath, string?mutagenVersion, out string?listedMutagenVersion, string?synthesisVersion, out string?listedSynthesisVersion) { listedMutagenVersion = null; listedSynthesisVersion = null; foreach (var subProj in SolutionPatcherRun.AvailableProjects(solutionPath)) { var proj = Path.Combine(Path.GetDirectoryName(solutionPath), subProj); var projXml = XElement.Parse(File.ReadAllText(proj)); SwapInDesiredVersionsForProjectString( projXml, mutagenVersion: mutagenVersion, listedMutagenVersion: out var curListedMutagenVersion, synthesisVersion: synthesisVersion, listedSynthesisVersion: out var curListedSynthesisVersion); TurnOffNullability(projXml); // Just printing on run pipeline side //AddGitInfo(projXml); File.WriteAllText(proj, projXml.ToString()); if (drivingProjSubPath.Equals(subProj)) { listedMutagenVersion = curListedMutagenVersion; listedSynthesisVersion = curListedSynthesisVersion; } } foreach (var item in Directory.EnumerateFiles(Path.GetDirectoryName(solutionPath), "Directory.Build.props")) { var projXml = XElement.Parse(File.ReadAllText(item)); TurnOffNullability(projXml); File.WriteAllText(item, projXml.ToString()); } }
static async Task DoWork( string? mutagenVersion, string? synthesisVersion, CancellationToken cancel) { using var temp = TempFolder.Factory(); var failedDeps = new List<Dependent>(); var projResults = new List<(Dependent, string, ErrorResponse)>(); mutagenVersion ??= Versions.MutagenVersion; synthesisVersion ??= Versions.SynthesisVersion; System.Console.WriteLine($"Mutagen: {mutagenVersion}"); System.Console.WriteLine($"Synthesis: {synthesisVersion}"); var deps = await GitHubDependents.GitHubDependents.GetDependents( user: RegistryConstants.GithubUser, repository: RegistryConstants.GithubRepoName, packageID: RegistryConstants.PackageId, pages: byte.MaxValue) .ToArrayAsync(); await Task.WhenAll(deps.GroupBy(x => x.User).Select(group => Task.Run(async () => { cancel.ThrowIfCancellationRequested(); if (group.Key == null) return; await Task.WhenAll(group.Select(dependency => Task.Run(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 = GitPatcherRun.GetPathToSolution(repo.Info.WorkingDirectory); if (slnPath == null) { System.Console.Error.WriteLine($"Could not get path to solution {clonePath}"); failedDeps.Add(dependency); return; } GitPatcherRun.SwapInDesiredVersionsForSolution( solutionPath: slnPath, drivingProjSubPath: string.Empty, mutagenVersion: mutagenVersion, out var _, synthesisVersion: synthesisVersion, out var _); foreach (var proj in SolutionPatcherRun.AvailableProjectSubpaths(slnPath)) { System.Console.WriteLine($"Checking {group.Key}/{dependency.Repository}:{proj}"); cancel.ThrowIfCancellationRequested(); var path = Path.Combine(repoDir.FullName, proj); var compile = await DotNetCommands.Compile(path, cancel, null); if (compile.Failed) { System.Console.WriteLine("Failed compilation"); } projResults.Add((dependency, proj, compile)); } } catch (Exception ex) { System.Console.Error.WriteLine($"Failed to check {dependency}"); System.Console.Error.WriteLine(ex); return; } }))); }))); cancel.ThrowIfCancellationRequested(); System.Console.WriteLine(); System.Console.WriteLine(); System.Console.WriteLine(); System.Console.WriteLine("-------------------------------"); System.Console.WriteLine(); System.Console.WriteLine(); System.Console.WriteLine(); if (failedDeps.Count > 0) { System.Console.WriteLine("Failed repos:"); foreach (var f in failedDeps .OrderBy(d => d.User) .CreateOrderedEnumerable(d => d.Repository, null, true)) { System.Console.WriteLine($" {f}"); } } var failed = projResults.Where(p => p.Item3.Failed).ToList(); if (failed.Count > 0) { System.Console.WriteLine("Failed projects:"); foreach (var f in failed.OrderBy(f => f.Item1.User) .CreateOrderedEnumerable(d => d.Item1.Repository, null, true) .CreateOrderedEnumerable(d => d.Item2, null, true)) { System.Console.WriteLine($"{f.Item1}: {f.Item2}"); System.Console.WriteLine(); } } }
public ExistingProjectInitVM() { SolutionPath.PathType = PathPickerVM.PathTypeOptions.File; SolutionPath.ExistCheckOption = PathPickerVM.CheckOptions.On; SolutionPath.Filters.Add(new CommonFileDialogFilter("Solution", ".sln")); AvailableProjects = this.WhenAnyValue(x => x.SolutionPath.TargetPath) .ObserveOn(RxApp.TaskpoolScheduler) .Select(x => SolutionPatcherRun.AvailableProjectSubpaths(x)) .Select(x => x.AsObservableChangeSet()) .Switch() .ObserveOnGui() .ToObservableCollection(this); InitializationCall = SelectedProjects.Connect() .Transform(subPath => { if (subPath == null || this.SolutionPath.TargetPath == null) { return(string.Empty); } try { return(Path.Combine(Path.GetDirectoryName(SolutionPath.TargetPath) !, subPath)); } catch (Exception) { return(string.Empty); } }) .Transform(path => { var pathPicker = new PathPickerVM { PathType = PathPickerVM.PathTypeOptions.File, ExistCheckOption = PathPickerVM.CheckOptions.On, TargetPath = path }; pathPicker.Filters.Add(new CommonFileDialogFilter("Project", ".csproj")); return(pathPicker); }) .DisposeMany() .QueryWhenChanged(q => { if (q.Count == 0) { return(GetResponse <InitializerCall> .Fail("No projects selected")); } var err = q .Select(p => p.ErrorState) .Where(e => e.Failed) .And(ErrorResponse.Success) .First(); if (err.Failed) { return(err.BubbleFailure <InitializerCall>()); } return(GetResponse <InitializerCall> .Succeed(async(profile) => { return q.Select(i => { var patcher = new SolutionPatcherVM(profile); patcher.SolutionPath.TargetPath = SolutionPath.TargetPath; patcher.ProjectSubpath = i.TargetPath.TrimStart($"{Path.GetDirectoryName(SolutionPath.TargetPath)}\\" !); return patcher; }); })); }); }
public static async Task <ConfigurationState <RunnerRepoInfo> > CheckoutRunnerRepository( string proj, string localRepoDir, GitPatcherVersioning patcherVersioning, NugetVersioningTarget nugetVersioning, Action <string>?logger, CancellationToken cancel, bool compile = true) { try { cancel.ThrowIfCancellationRequested(); logger?.Invoke($"Targeting {patcherVersioning}"); using var repo = new Repository(localRepoDir); var runnerBranch = repo.Branches[RunnerBranch] ?? repo.CreateBranch(RunnerBranch); repo.Reset(ResetMode.Hard); Commands.Checkout(repo, runnerBranch); string?targetSha; string?target; bool fetchIfMissing = patcherVersioning.Versioning switch { PatcherVersioningEnum.Commit => true, _ => false }; switch (patcherVersioning.Versioning) { case PatcherVersioningEnum.Tag: if (string.IsNullOrWhiteSpace(patcherVersioning.Target)) { return(GetResponse <RunnerRepoInfo> .Fail("No tag selected")); } repo.Fetch(); targetSha = repo.Tags[patcherVersioning.Target]?.Target.Sha; if (string.IsNullOrWhiteSpace(targetSha)) { return(GetResponse <RunnerRepoInfo> .Fail("Could not locate tag")); } target = patcherVersioning.Target; break; case PatcherVersioningEnum.Commit: targetSha = patcherVersioning.Target; if (string.IsNullOrWhiteSpace(targetSha)) { return(GetResponse <RunnerRepoInfo> .Fail("Could not locate commit")); } target = patcherVersioning.Target; break; case PatcherVersioningEnum.Branch: if (string.IsNullOrWhiteSpace(patcherVersioning.Target)) { return(GetResponse <RunnerRepoInfo> .Fail($"Target branch had no name.")); } repo.Fetch(); var targetBranch = repo.Branches[$"origin/{patcherVersioning.Target}"]; if (targetBranch == null) { return(GetResponse <RunnerRepoInfo> .Fail($"Could not locate branch: {patcherVersioning.Target}")); } targetSha = targetBranch.Tip.Sha; target = patcherVersioning.Target; break; default: throw new NotImplementedException(); } if (!ObjectId.TryParse(targetSha, out var objId)) { return(GetResponse <RunnerRepoInfo> .Fail("Malformed sha string")); } cancel.ThrowIfCancellationRequested(); var commit = repo.Lookup(objId, ObjectType.Commit) as Commit; if (commit == null) { if (!fetchIfMissing) { return(GetResponse <RunnerRepoInfo> .Fail("Could not locate commit with given sha")); } repo.Fetch(); commit = repo.Lookup(objId, ObjectType.Commit) as Commit; if (commit == null) { return(GetResponse <RunnerRepoInfo> .Fail("Could not locate commit with given sha")); } } cancel.ThrowIfCancellationRequested(); var slnPath = GitPatcherRun.GetPathToSolution(localRepoDir); if (slnPath == null) { return(GetResponse <RunnerRepoInfo> .Fail("Could not locate solution to run.")); } var foundProjSubPath = SolutionPatcherRun.AvailableProject(slnPath, proj); if (foundProjSubPath == null) { return(GetResponse <RunnerRepoInfo> .Fail($"Could not locate target project file: {proj}.")); } cancel.ThrowIfCancellationRequested(); logger?.Invoke($"Checking out {targetSha}"); repo.Reset(ResetMode.Hard, commit, new CheckoutOptions()); var projPath = Path.Combine(localRepoDir, foundProjSubPath); cancel.ThrowIfCancellationRequested(); logger?.Invoke($"Mutagen Nuget: {nugetVersioning.MutagenVersioning} {nugetVersioning.MutagenVersion}"); logger?.Invoke($"Synthesis Nuget: {nugetVersioning.SynthesisVersioning} {nugetVersioning.SynthesisVersion}"); GitPatcherRun.SwapInDesiredVersionsForSolution( slnPath, drivingProjSubPath: foundProjSubPath, mutagenVersion: nugetVersioning.MutagenVersioning == NugetVersioningEnum.Match ? null : nugetVersioning.MutagenVersion, listedMutagenVersion: out var listedMutagenVersion, synthesisVersion: nugetVersioning.SynthesisVersioning == NugetVersioningEnum.Match ? null : nugetVersioning.SynthesisVersion, listedSynthesisVersion: out var listedSynthesisVersion); // Compile to help prep if (compile) { var compileResp = await SolutionPatcherRun.CompileWithDotnet(projPath, cancel); if (compileResp.Failed) { return(compileResp.BubbleFailure <RunnerRepoInfo>()); } } return(GetResponse <RunnerRepoInfo> .Succeed( new RunnerRepoInfo( slnPath : slnPath, projPath : projPath, target : target, commitMsg : commit.Message, commitDate : commit.Author.When.LocalDateTime, listedSynthesis : listedSynthesisVersion, listedMutagen : listedMutagenVersion))); } catch (OperationCanceledException) { throw; } catch (Exception ex) { return(GetResponse <RunnerRepoInfo> .Fail(ex)); } }