Exemplo n.º 1
0
        public void NoSolutionReturnsNull(
            [Frozen] MockFileSystem fs,
            DirectoryPath existingRepoPath,
            SolutionFileLocator sut)
        {
            fs.File.Create(Path.Combine(existingRepoPath, "SomeFile.txt"));

            sut.GetPath(existingRepoPath)
            .Should().BeNull();
        }
Exemplo n.º 2
0
        public GetResponse <DriverPaths> Get()
        {
            var slnPath = SolutionFileLocator.GetPath(DriverRepoDirectoryProvider.Path);

            if (slnPath == null)
            {
                return(GetResponse <DriverPaths> .Fail("Could not locate solution to run."));
            }

            var availableProjs = AvailableProjectsRetriever.Get(slnPath.Value).ToList();

            return(new DriverPaths(slnPath.Value, availableProjs));
        }
Exemplo n.º 3
0
        public void FindsFirstSlnInDirectory(
            [Frozen] MockFileSystem fs,
            DirectoryPath existingRepoPath,
            SolutionFileLocator sut)
        {
            fs.File.Create(Path.Combine(existingRepoPath, "SomeFile.txt"));
            var pathToFind = new FilePath(Path.Combine(existingRepoPath, "SomeSln.sln"));

            fs.File.Create(pathToFind);
            fs.File.Create(Path.Combine(existingRepoPath, "SomeSln2.sln"));

            sut.GetPath(existingRepoPath)
            .Should().Be(pathToFind);
        }
Exemplo n.º 4
0
        public async Task <ConfigurationState <RunnerRepoInfo> > Checkout(
            CheckoutInput checkoutInput,
            CancellationToken cancel)
        {
            try
            {
                cancel.ThrowIfCancellationRequested();

                _logger.Information("Targeting {PatcherVersioning}", checkoutInput.PatcherVersioning);

                using var repoCheckout = RepoCheckouts.Get(RunnerRepoDirectoryProvider.Path);

                var target = ResetToTarget.Reset(repoCheckout.Repository, checkoutInput.PatcherVersioning, cancel);
                if (target.Failed)
                {
                    return(target.BubbleFailure <RunnerRepoInfo>());
                }

                cancel.ThrowIfCancellationRequested();

                checkoutInput.LibraryNugets.Log(_logger);

                var slnPath = SolutionFileLocator.GetPath(RunnerRepoDirectoryProvider.Path);
                if (slnPath == null)
                {
                    return(GetResponse <RunnerRepoInfo> .Fail("Could not locate solution to run."));
                }

                var foundProjSubPath = RunnerRepoProjectPathRetriever.Get(slnPath.Value, checkoutInput.Proj);
                if (foundProjSubPath == null)
                {
                    return(GetResponse <RunnerRepoInfo> .Fail($"Could not locate target project file: {checkoutInput.Proj}."));
                }

                cancel.ThrowIfCancellationRequested();

                ModifyRunnerProjects.Modify(
                    slnPath.Value,
                    drivingProjSubPath: foundProjSubPath.SubPath,
                    versions: checkoutInput.LibraryNugets.ReturnIfMatch(new NugetVersionPair(null, null)),
                    listedVersions: out var listedVersions);

                var runInfo = new RunnerRepoInfo(
                    SolutionPath: slnPath,
                    ProjPath: foundProjSubPath.FullPath,
                    MetaPath: _metaFilePathProvider.Path,
                    Target: target.Value.Target,
                    CommitMessage: target.Value.CommitMessage,
                    CommitDate: target.Value.CommitDate,
                    ListedVersions: listedVersions,
                    TargetVersions: checkoutInput.LibraryNugets.ReturnIfMatch(listedVersions));

                return(GetResponse <RunnerRepoInfo> .Succeed(runInfo));
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                return(GetResponse <RunnerRepoInfo> .Fail(ex));
            }
        }
Exemplo n.º 5
0
        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;
                    }
                })));