예제 #1
0
        public void Should_Not_Set_Repository_CommitId_When_Building_Single_Solution()
        {
            var buildConfig = new DotNetProjectBuildConfig
            {
                GitRepository = new GitRepository("volo", "dev", "")
                {
                    DependingRepositories = new List <GitRepository>()
                    {
                        new GitRepository("abp", "dev", "")
                    }
                },
                SlFilePath = "test.sln"
            };

            var changedProjects = new List <DotNetProjectInfo>()
            {
                new DotNetProjectInfo("volo", "project1.csproj", true)
            };

            var builtProjects = new List <string>()
            {
                "project1.csproj"
            };

            var lastCommitId = "1";

            _gitRepositoryHelper.GetLastCommitId(buildConfig.GitRepository).Returns(lastCommitId);
            _gitRepositoryHelper.GetFriendlyName(buildConfig.GitRepository).Returns("volo");

            var status = _buildStatusGenerator.Generate(buildConfig, changedProjects, builtProjects);

            status.CommitId.ShouldBeNull();
        }
예제 #2
0
        public void Should_Set_Repository_CommitId_When_All_Projects_Built_For_Child_Repository()
        {
            var buildConfig = new DotNetProjectBuildConfig
            {
                GitRepository = new GitRepository("volo", "dev", "")
                {
                    DependingRepositories = new List <GitRepository>()
                    {
                        new GitRepository("abp", "dev", "")
                    }
                }
            };

            var changedProjects = new List <DotNetProjectInfo>()
            {
                new DotNetProjectInfo("abp", "project1.csproj", true)
            };

            var builtProjects = new List <string>()
            {
                "project1.csproj"
            };

            var lastCommitId = "1";

            _gitRepositoryHelper.GetLastCommitId(buildConfig.GitRepository).Returns(lastCommitId);
            _gitRepositoryHelper.GetFriendlyName(buildConfig.GitRepository).Returns("abp");

            var status = _buildStatusGenerator.Generate(buildConfig, changedProjects, builtProjects);

            status.CommitId.ShouldBe(lastCommitId);
        }
        public List <DotNetProjectInfo> Find(DotNetProjectBuildConfig buildConfig)
        {
            if (!buildConfig.SlFilePath.IsNullOrEmpty())
            {
                return(FindBySlnFile(buildConfig));
            }

            return(FindByRepository(buildConfig));
        }
        public DotNetProjectBuildConfig Read(string directoryPath)
        {
            var buildConfig   = new DotNetProjectBuildConfig();
            var solutionFiles = Directory.GetFiles(directoryPath, "*.sln", SearchOption.TopDirectoryOnly);

            if (solutionFiles.Length == 1)
            {
                buildConfig.SlFilePath = solutionFiles.First();
                var configFile = GetClosestFile(directoryPath, _buildConfigName);
                if (configFile.IsNullOrEmpty())
                {
                    buildConfig.GitRepository = GetGitRepositoryUsingDirectory(directoryPath);
                }
                else
                {
                    var configFileContent = File.ReadAllText(configFile);
                    buildConfig.GitRepository = _jsonSerializer.Deserialize <GitRepository>(configFileContent);
                }

                SetBranchNames(buildConfig.GitRepository);

                return(buildConfig);
            }

            var configFiles = Directory.GetFiles(directoryPath, _buildConfigName, SearchOption.TopDirectoryOnly);

            if (configFiles.Length == 1)
            {
                var configFile        = configFiles.First();
                var configFileContent = File.ReadAllText(configFile);
                buildConfig.GitRepository = _jsonSerializer.Deserialize <GitRepository>(configFileContent);

                SetBranchNames(buildConfig.GitRepository);

                return(buildConfig);
            }

            if (configFiles.Length > 1)
            {
                throw new Exception(
                          "There are more than 1 config (abp-build-config.json) file in the directory!"
                          );
            }

            return(new DotNetProjectBuildConfig
            {
                GitRepository = GetGitRepositoryUsingDirectory(directoryPath)
            });
        }
예제 #5
0
        /// <summary>
        /// Returns list of projects in a repository and its depending repositories sorted by dependencies
        /// </summary>
        /// <param name="buildConfig"></param>
        /// <returns></returns>
        private List <DotNetProjectInfo> FindAllProjects(DotNetProjectBuildConfig buildConfig)
        {
            var projects = new List <DotNetProjectInfo>();

            AddProjectsOfRepository(buildConfig.GitRepository, projects);

            _dotNetProjectDependencyFiller.Fill(projects);

            var allSortedProjectList = _buildProjectListSorter.SortByDependencies(
                projects,
                new DotNetProjectInfoEqualityComparer()
                );

            return(FilterIgnoredDirectories(allSortedProjectList, buildConfig.GitRepository));
        }
예제 #6
0
        private bool ShouldUpdateRepositoryCommitId(
            DotNetProjectBuildConfig buildConfig,
            List <DotNetProjectInfo> changedProjects,
            List <string> buildSucceededProjects)
        {
            if (!buildConfig.SlFilePath.IsNullOrEmpty())
            {
                return(false);
            }

            if (changedProjects.Count == 0 || buildSucceededProjects.Count == 0)
            {
                return(false);
            }

            return(changedProjects.Count == buildSucceededProjects.Count);
        }
        private List <DotNetProjectInfo> FindByRepository(DotNetProjectBuildConfig buildConfig)
        {
            var gitRepositoryBuildStatus = _repositoryBuildStatusStore.Get(
                buildConfig.BuildName,
                buildConfig.GitRepository
                );

            var allSortedProjectList = FindAllProjects(buildConfig);

            MarkProjectsForBuild(
                buildConfig.GitRepository,
                gitRepositoryBuildStatus,
                buildConfig.ForceBuild,
                allSortedProjectList
                );

            return(allSortedProjectList.Where(e => e.ShouldBuild).ToList());
        }
예제 #8
0
        private void GenerateBuildStatusInternal(
            DotNetProjectBuildConfig buildConfig,
            GitRepository gitRepository,
            List <DotNetProjectInfo> changedProjects,
            List <string> buildSucceededProjects,
            GitRepositoryBuildStatus status)
        {
            var lastCommitId     = _gitRepositoryHelper.GetLastCommitId(gitRepository);
            var repoFriendlyName = _gitRepositoryHelper.GetFriendlyName(gitRepository);

            var dependingRepositoryStatus = new GitRepositoryBuildStatus(
                gitRepository.Name,
                repoFriendlyName
                );

            if (ShouldUpdateRepositoryCommitId(buildConfig, changedProjects, buildSucceededProjects))
            {
                dependingRepositoryStatus.CommitId = lastCommitId;
            }

            dependingRepositoryStatus.SucceedProjects = changedProjects.Where(p =>
                                                                              p.RepositoryName == gitRepository.Name &&
                                                                              buildSucceededProjects.Contains(p.CsProjPath)
                                                                              )
                                                        .Select(e => new DotNetProjectBuildStatus()
            {
                CsProjPath = e.CsProjPath,
                CommitId   = lastCommitId
            }).ToList();

            foreach (var dependingRepository in gitRepository.DependingRepositories)
            {
                GenerateBuildStatusInternal(
                    buildConfig,
                    dependingRepository,
                    changedProjects,
                    buildSucceededProjects,
                    dependingRepositoryStatus
                    );
            }

            status.DependingRepositories.Add(dependingRepositoryStatus);
        }
예제 #9
0
        public List <DotNetProjectInfo> FindByRepository(DotNetProjectBuildConfig buildConfig)
        {
            Console.WriteLine("Finding changed projects for repository...");

            var gitRepositoryBuildStatus = _repositoryBuildStatusStore.Get(
                buildConfig.BuildName,
                buildConfig.GitRepository
                );

            var allSortedProjectList = FindAllProjects(buildConfig);

            MarkProjectsForBuild(
                buildConfig.GitRepository,
                gitRepositoryBuildStatus,
                buildConfig.ForceBuild,
                allSortedProjectList
                );

            return(allSortedProjectList.Where(e => e.ShouldBuild).ToList());
        }
        private List <DotNetProjectInfo> FindBySlnFile(DotNetProjectBuildConfig buildConfig)
        {
            var allProjectList = FindAllProjects(buildConfig);

            var slFine      = new FileInfo(buildConfig.SlFilePath);
            var csProjFiles = slFine.Directory.GetFiles(
                "*.csproj",
                SearchOption.AllDirectories
                ).Select(e => e.FullName)
                              .ToList();

            foreach (var csProjFile in csProjFiles)
            {
                MarkDependantProjectsForBuild(buildConfig.GitRepository, csProjFile, allProjectList);
            }

            return(_buildProjectListSorter.SortByDependencies(
                       allProjectList,
                       new DotNetProjectInfoEqualityComparer()
                       ).Where(e => e.ShouldBuild).ToList());
        }
        public DotNetProjectBuildConfig Read(string directoryPath)
        {
            var buildConfig   = new DotNetProjectBuildConfig();
            var solutionFiles = Directory.GetFiles(directoryPath, "*.sln", SearchOption.TopDirectoryOnly);

            if (solutionFiles.Length == 1)
            {
                buildConfig.SlFilePath = solutionFiles.First();
                var configFile        = GetClosestFile(directoryPath, _buildConfigName);
                var configFileContent = File.ReadAllText(configFile);
                buildConfig.GitRepository = _jsonSerializer.Deserialize <GitRepository>(configFileContent);

                SetBranchNames(buildConfig.GitRepository);

                return(buildConfig);
            }

            var configFiles = Directory.GetFiles(directoryPath, _buildConfigName, SearchOption.TopDirectoryOnly);

            if (configFiles.Length == 1)
            {
                var configFile        = configFiles.First();
                var configFileContent = File.ReadAllText(configFile);
                buildConfig.GitRepository = _jsonSerializer.Deserialize <GitRepository>(configFileContent);

                SetBranchNames(buildConfig.GitRepository);

                return(buildConfig);
            }

            Console.WriteLine(
                "There are more than 1 config (abp-build-config.json) file in the directory!"
                );

            throw new Exception("There is no solution file (*.sln) or " + _buildConfigName + " in the working directory !");
        }