/// <summary> /// Detect valid scope based on the change list in the PR /// Get affected files and find scope based on directory that contains .sln file /// </summary> /// <returns></returns> List <string> GetRPScopes() { FileSystemUtility fileSysUtil = new FileSystemUtility(); IEnumerable <string> prFileList = null; List <string> finalScopePathList = new List <string>(); List <string> intermediateList = new List <string>(); if (!string.IsNullOrWhiteSpace(GitHubRepositoryHtmlUrl)) { TaskLogger.LogInfo("Trying to get Pr info using PrNumber:'{0}', GitHubUrl:'{1}'", GH_PRNumber.ToString(), GitHubRepositoryHtmlUrl); string repoName = string.Empty; //Split the url string[] tokens = GitHubRepositoryHtmlUrl.Split(new char[] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); //Get the last token which represents the repository name if (tokens != null) { repoName = tokens[tokens.Length - 1]; } if (GHSvc.IsRepoAuthorized(repoName)) { prFileList = GHSvc.PR.GetPullRequestFileList(repoName, GH_PRNumber); } } else { TaskLogger.LogWarning("You are not authorized to access '{0}', skipping detecting RP Scope", GitHubRepositoryHtmlUrl); } if (prFileList != null) { TaskLogger.LogInfo(MessageImportance.Low, prFileList, "List of files from PR"); Dictionary <string, string> RPDirs = FindScopeFromPullRequestFileList(prFileList); if (RPDirs.NotNullOrAny <KeyValuePair <string, string> >()) { intermediateList = RPDirs.Select <KeyValuePair <string, string>, string>((item) => item.Key).ToList <string>(); } if (DetectEnv.IsRunningUnderNonWindows) { foreach (string scopePath in intermediateList) { string newPath = scopePath.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); finalScopePathList.Add(newPath); } } else { finalScopePathList = intermediateList; } } return(finalScopePathList); }
T ParseProjectKind <T>(string projKind, T defaultValue) where T : struct { T pk = defaultValue; if (!Enum.TryParse <T>(projKind, true, out pk)) { TaskLogger.LogInfo(MessageImportance.Low, "Provided '{0}' value '{1}' is currently not supported", pk.GetType().Name.ToString(), projKind); TaskLogger.LogInfo(MessageImportance.Low, "Setting it to default '{0}'", defaultValue.ToString()); } return(pk); }
public override bool Execute() { if (DebugMode) { TaskLogger.LogInfo(MessageImportance.Low, "DebugMode Detected"); if (_debugTask == null) { _debugTask = new DebugTask(); } _debugTask.ExecWithInfo(this.NetSdkTaskName); } return(TaskLogger.TaskSucceededWithNoErrorsLogged); }
/// <summary> /// Deletes packages from known nuget cache location /// </summary> /// <returns></returns> public override bool Execute() { base.Execute(); if (WhatIf) { WhatIfAction(); } else { packagesToBeCleaned?.AddRange(PackageReferences); TaskLogger.LogInfo(MessageImportance.Low, packagesToBeCleaned, "Pacakges to be deleted...."); List <string> localCacheLocations = new NugetExec().GetRestoreCacheLocation(); if (RestoreCacheLocations != null) { localCacheLocations.AddRange(RestoreCacheLocations); } if (!string.IsNullOrEmpty(PackageDirSearchPattern)) { packagesToBeCleaned.Add(PackageDirSearchPattern); } if (localCacheLocations.Any <string>()) { Task[] delTsks = new Task[localCacheLocations.Count]; int tskCount = 0; localCacheLocations.ForEach((cl) => { //TaskLogger.LogDebugInfo("Checking {0}", cl); delTsks[tskCount] = Task.Run(async() => await CleanRestoredPackagesAsync(cl)); tskCount++; }); Task.WaitAll(delTsks); TaskLogger.LogInfo("Cleaning of Packages completed....."); } //DeleteNupkgOutputDir(); } return(TaskLogger.TaskSucceededWithNoErrorsLogged); }
protected override void WhatIfAction() { TaskLogger.LogInfo(MessageImportance.High, "Projects will be categorized for Scope '{0}'", BuildScope.ToString()); TaskLogger.LogInfo(MessageImportance.High, "Project Type '{0}' will be used ", ProjType.ToString()); TaskLogger.LogInfo(MessageImportance.High, "Project Category '{0}' will be used ", ProjCat.ToString()); TaskLogger.LogInfo(MessageImportance.High, "Tokens to be included '{0}'", CmdLineIncludeScope); TaskLogger.LogInfo(MessageImportance.High, "Tokens to be excluded '{0}'", CmdLineExcludeScope); TaskLogger.LogInfo(MessageImportance.High, "Repository Root Dir Path '{0}'", RepositoryRootDirPath); ProjectSearchUtility psu = new ProjectSearchUtility(RepositoryRootDirPath, MultipleScopes, BuildScope, FullyQualifiedBuildScopeDirPath, CmdLineExcludeScope, CmdLineIncludeScope, ProjType, ProjCat); psu.UseLegacyDirs = UseLegacyDirStructure; TaskLogger.LogInfo(MessageImportance.High, "Use Legacy Directory Strucuture is set to '{0}'", psu.UseLegacyDirs.ToString()); TaskLogger.LogInfo(MessageImportance.High, "SDK Root Dir Path '{0}'", psu.SDKRootDir); TaskLogger.LogInfo(MessageImportance.High, psu.SearchDirPaths, "Search Dir Path(s)"); }
protected override void WhatIfAction() { List <string> ScopedProjects = GetProjectsToBeSkiped(); if (ScopedProjects.NotNullOrAny <string>()) { TaskLogger.LogInfo("Following Projects will be affected, with following properties, SkipFromTestExecution:'{0}', SkipFromBuild:'{1}'", SkipFromTestExecution.ToString(), SkipFromBuild.ToString()); TaskLogger.LogInfo(ScopedProjects); } else { //TODO: Print all input properties that were provided TaskLogger.LogInfo("No projects matched for provided criteria"); } }
void UpdatePropertyValue(MsbuildProject proj, string propertyName, bool newPropValue) { string existingVal = proj.GetPropertyValue(propertyName); if (string.IsNullOrWhiteSpace(existingVal) && newPropValue == false) { TaskLogger.LogInfo(MessageImportance.Low, "'{0}' property is not currently set and the new value is '{1}'. No changes will be made", propertyName, newPropValue.ToString()); } else if (existingVal.Equals(newPropValue.ToString(), StringComparison.OrdinalIgnoreCase)) { TaskLogger.LogInfo(MessageImportance.Low, "'{0}' current value is '{1}'. New value requested is '{2}'", propertyName, existingVal, newPropValue.ToString()); } else if (!existingVal.Equals(newPropValue.ToString(), StringComparison.OrdinalIgnoreCase)) { TaskLogger.LogInfo(MessageImportance.Low, "{0} current value:'{1}', new value:'{2}'", propertyName, existingVal, newPropValue.ToString()); proj.AddUpdateProperty(propertyName, newPropValue.ToString()); } }
private async Task DeleteDirAsync(string dirToBeDeletedFullPath) { if (WhatIf) { if (Directory.Exists(dirToBeDeletedFullPath)) { TaskLogger.LogInfo("** Would be deleted {0}", dirToBeDeletedFullPath); } } else { if (Directory.Exists(dirToBeDeletedFullPath)) { TaskLogger.LogInfo("Cleaning {0}", dirToBeDeletedFullPath); await Task.Run(() => Directory.Delete(dirToBeDeletedFullPath, true)); } } }
/// <summary> /// Loads project into metadata model /// </summary> /// <param name="projectPathList"></param> /// <returns></returns> Dictionary <string, SdkProjectMetadata> LoadProjectData(List <string> projectPathList) { Dictionary <string, SdkProjectMetadata> d_msbp = new Dictionary <string, SdkProjectMetadata>(); DateTime startTime = DateTime.Now; foreach (string projPath in projectPathList) { SdkProjectMetadata msbp = new SdkProjectMetadata(projPath, BaseLineSdkTargetFx, BaseLineTestTargetFx); if (!d_msbp.ContainsKey(projPath)) { d_msbp.Add(projPath, msbp); } } DateTime endTime = DateTime.Now; TaskLogger.LogInfo(MessageImportance.Low, "Total time for loading '{0}' projects:'{1}'", d_msbp.Count.ToString(), (endTime - startTime).TotalSeconds.ToString()); return(d_msbp); }
void UpdateProjects(List <string> projectList) { foreach (string projectPath in projectList) { TaskLogger.LogInfo("Updating '{0}'", projectPath); MsbuildProject msbp = new MsbuildProject(projectPath); // We will only set SkipBuild for sdk projects, we will never set skipTestexecution for sdk projects if (msbp.IsProjectSdkType) { UpdatePropertyValue(msbp, PROPNAME_SKIP_BUILD, SkipFromBuild); } if (msbp.IsProjectTestType) { UpdatePropertyValue(msbp, PROPNAME_SKIP_BUILD, SkipFromBuild); UpdatePropertyValue(msbp, PROPNAME_SKIP_TEST_EXECUTION, SkipFromTestExecution); } } }
public override bool Execute() { base.Execute(); if (WhatIf) { WhatIfAction(); } else { TaskLogger.LogInfo("Retrieving from keyvault for identifier '{0}'", SecretIdentifier); RetrievedKVSecret = this.KVSvc.GetSecret(SecretIdentifier); if (string.IsNullOrEmpty(RetrievedKVSecret)) { TaskLogger.LogInfo("Retrieved empty value from keyvault"); } else { TaskLogger.LogInfo("Retrieved non-empty value from keyvault. Avoiding logging."); } } return(TaskLogger.TaskSucceededWithNoErrorsLogged); }
private async Task CleanRestoredPackagesAsync(string cacheLocationDirPath) { if (Directory.Exists(cacheLocationDirPath)) { TaskLogger.LogInfo("Checking {0}", cacheLocationDirPath); foreach (string pkgName in packagesToBeCleaned) { try { if (pkgName.Contains("*") || pkgName.Contains("?")) { var pkgSearchDirs = Directory.EnumerateDirectories(cacheLocationDirPath, pkgName, SearchOption.TopDirectoryOnly); if (pkgSearchDirs.Any <string>()) { TaskLogger.LogInfo("Found {0} package(s) under {1}", pkgSearchDirs.Count <string>().ToString(), cacheLocationDirPath); } foreach (string dirWithPkg in pkgSearchDirs) { await DeleteDirAsync(dirWithPkg); } } else { await DeleteDirAsync(Path.Combine(cacheLocationDirPath, pkgName)); } } catch (Exception ex) { TaskLogger.LogInfo(ex.ToString()); } } } }
/// <summary> /// /// </summary> void Categorize() { TaskLogger.LogInfo("Categorizing Projects....."); List <SdkProjectMetadata> sdkProjList = new List <SdkProjectMetadata>(); List <SdkProjectMetadata> testProjList = new List <SdkProjectMetadata>(); List <SdkProjectMetadata> unsupportedProjList = new List <SdkProjectMetadata>(); List <SdkProjectMetadata> testToBeRunProjList = new List <SdkProjectMetadata>(); List <SdkProjectMetadata> platformSpecificSkippedProjList = new List <SdkProjectMetadata>(); List <string> searchedProjects = new List <string>(); ProjectSearchUtility psu = null; Dictionary <string, SdkProjectMetadata> allProj = null; psu = new ProjectSearchUtility(RepositoryRootDirPath, MultipleScopes, BuildScope, FullyQualifiedBuildScopeDirPath, CmdLineExcludeScope, CmdLineIncludeScope, ProjType, ProjCat); psu.UseLegacyDirs = UseLegacyDirStructure; searchedProjects = psu.FindProjects(); allProj = LoadProjectData(searchedProjects); foreach (KeyValuePair <string, SdkProjectMetadata> kv in allProj) { SdkProjectMetadata pmd = kv.Value; switch (pmd.ProjectType) { #region SDK case SdkProjectType.Sdk: { if (!pmd.Fx.IsTargetFxMatch) { if (!pmd.Fx.IsApplicableForCurrentPlatform) { platformSpecificSkippedProjList.Add(pmd); } else { unsupportedProjList.Add(pmd); } } else if (!pmd.Fx.IsApplicableForCurrentPlatform) { platformSpecificSkippedProjList.Add(pmd); } else { if (!pmd.ExcludeFromBuild) { sdkProjList.Add(pmd); } } break; } #endregion #region Test case SdkProjectType.Test: { // WE HAVE INTENTIONALLY SKIPPED CHECKING THIS PROPERTY, BASICALLY WE WILL NOT BE VERIFYING BASELINE TARGETFX FOR TEST PROJECTS // IF WE EVER DECIDE TO DO IT, SIMPLY ENABLE THE BELOW CODE // if (!pmd.Fx.IsTargetFxMatch) // { // if (!pmd.Fx.IsApplicableForCurrentPlatform) // { // platformSpecificSkippedProjList.Add(pmd); // } // else // { // unsupportedProjList.Add(pmd); // } // } if (!pmd.Fx.IsApplicableForCurrentPlatform) { platformSpecificSkippedProjList.Add(pmd); } else { if (!pmd.ExcludeFromBuild) { testProjList.Add(pmd); } if (!pmd.ExcludeFromTest) { testToBeRunProjList.Add(pmd); } } break; } #endregion } } SDK_Projects = sdkProjList.Select <SdkProjectMetadata, SDKMSBTaskItem>((item) => new SDKMSBTaskItem(item)).ToArray <SDKMSBTaskItem>(); Test_Projects = testProjList.Select <SdkProjectMetadata, SDKMSBTaskItem>((item) => new SDKMSBTaskItem(item)).ToArray <SDKMSBTaskItem>(); UnSupportedProjects = unsupportedProjList.Select <SdkProjectMetadata, SDKMSBTaskItem>((item) => new SDKMSBTaskItem(item)).ToArray <SDKMSBTaskItem>(); Test_ToBe_Run = testToBeRunProjList.Select <SdkProjectMetadata, SDKMSBTaskItem>((item) => new SDKMSBTaskItem(item)).ToArray <SDKMSBTaskItem>(); PlatformSpecificSkippedProjects = platformSpecificSkippedProjList.Select <SdkProjectMetadata, SDKMSBTaskItem>((item) => new SDKMSBTaskItem(item)).ToArray <SDKMSBTaskItem>(); SdkPkgReferenceList = GetNormalizedPkgRefList(); TaskLogger.LogInfo("SDK Project(s) found:'{0}'", SDK_Projects.Count().ToString()); TaskLogger.LogInfo(MessageImportance.Low, SDK_Projects, "File Paths for SDK Projects"); TaskLogger.LogInfo("Test Project(s) found:'{0}'", Test_Projects.Count().ToString()); TaskLogger.LogInfo(MessageImportance.Low, Test_Projects, "File Paths for Test Projects"); TaskLogger.LogInfo("Test Project(s) whose tests will be executed are:'{0}'", Test_ToBe_Run.Count().ToString()); TaskLogger.LogInfo(MessageImportance.Low, Test_ToBe_Run, "File Paths for Test Projects whose tests will be executed"); if (UnSupportedProjects.NotNullOrAny <SDKMSBTaskItem>()) { TaskLogger.LogInfo("Project(s) whose target framework is not currently supported:'{0}'", UnSupportedProjects.Count().ToString()); TaskLogger.LogInfo(MessageImportance.Low, UnSupportedProjects, "File Paths for Unsupported Projects"); } //if (Test_ToBe_Run.NotNullOrAny<SDKMSBTaskItem>()) //{ // TaskLogger.LogInfo("Test Project(s) whose tests will be executed are:'{0}'", Test_ToBe_Run.Count().ToString()); // TaskLogger.LogInfo(MessageImportance.Low, Test_ToBe_Run, "File Paths for Test Projects whose tests will be executed"); //} if (PlatformSpecificSkippedProjects.NotNullOrAny <SDKMSBTaskItem>()) { TaskLogger.LogInfo("Test Project(s) that will be skipped from building/executing tests are:'{0}'", PlatformSpecificSkippedProjects.Count().ToString()); TaskLogger.LogInfo(MessageImportance.Low, PlatformSpecificSkippedProjects, "File Paths for Projects that will be skipped that are platform specific"); } if (SdkPkgReferenceList != null) { TaskLogger.LogInfo("PackageReferences count:'{0}'", SdkPkgReferenceList.Count().ToString()); TaskLogger.LogInfo(MessageImportance.Low, SdkPkgReferenceList, "Packages References"); } }
/// <summary> /// Detect valid scope based on the change list in the PR /// Get affected files and find scope based on directory that contains .sln file /// </summary> /// <returns></returns> List <string> GetRPScopes() { TaskLogger.LogInfo("Trying to get Pr info for PrNumber:'{0}'", GH_PRNumber.ToString()); FileSystemUtility fileSysUtil = new FileSystemUtility(); IEnumerable <string> prFileList = null; List <string> finalScopePathList = new List <string>(); if (!string.IsNullOrWhiteSpace(GH_RepositoryHtmlUrl)) { TaskLogger.LogInfo("Trying to get Pr info using PrNumber:'{0}', GitHubUrl:'{1}'", GH_PRNumber.ToString(), GH_RepositoryHtmlUrl); string repoName = string.Empty; //Split the url string[] tokens = GH_RepositoryHtmlUrl.Split(new char[] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); //Get the last token which represents the repository name if (tokens != null) { repoName = tokens[tokens.Length - 1]; } prFileList = GHSvc.PR.GetPullRequestFileList(repoName, GH_PRNumber); } else if (GH_RepositoryId > 0) { TaskLogger.LogInfo("Trying to get Pr info using PrNumber:'{0}', GitHub Repo Id:'{1}'", GH_PRNumber.ToString(), GH_RepositoryId.ToString()); prFileList = GHSvc.PR.GetPullRequestFileList(GH_RepositoryId, GH_PRNumber); } TaskLogger.LogInfo(MessageImportance.Low, prFileList, "List of files from PR"); Dictionary <string, string> RPDirs = FindScopeFromPullRequestFileList(prFileList); //Dictionary<string, string> RPDirs = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); if (RPDirs.NotNullOrAny <KeyValuePair <string, string> >()) { finalScopePathList = RPDirs.Select <KeyValuePair <string, string>, string>((item) => item.Key).ToList <string>(); } //foreach(string filePath in prFileList) //{ // string slnDirPath = fileSysUtil.TraverUptoRootWithFileExtension(filePath); // if (Directory.Exists(slnDirPath)) // { // if(!RPDirs.ContainsKey(slnDirPath)) // { // RPDirs.Add(slnDirPath, slnDirPath); // } // } // else // { // TaskLogger.LogWarning("RPScope Detection: '{0}' does not exists", slnDirPath); // } //} //TaskLogger.LogInfo("Number of RPs detected", RPDirs); //return RPDirs.Select<KeyValuePair<string, string>, string>((item) => item.Key).ToList<string>(); return(finalScopePathList); }
private void ParseInput() { foreach (SDKMSBTaskItem sdkProjTaskItem in SdkProjectFilePaths) { string azPropFilePath = string.Empty; string asmPath = string.Empty; string projectName = Path.GetFileNameWithoutExtension(sdkProjTaskItem.ItemSpec); string dllName = string.Format("{0}.dll", projectName); //e.g. <root>\artifacts\bin\Microsoft.Azure.Management.Billing\Debug\ string outputDirRootPath = sdkProjTaskItem.OutputPath; string azSdkPropDirPath = FileSysUtil.TraverseUptoRootWithFileToken(PROPS_APITAG_FILE_NAME, Path.GetDirectoryName(sdkProjTaskItem.ItemSpec)); if (string.IsNullOrWhiteSpace(azSdkPropDirPath)) { azSdkPropDirPath = FileSysUtil.TraverUptoRootWithFileExtension(Path.GetDirectoryName(sdkProjTaskItem.ItemSpec)); } if (Directory.Exists(azSdkPropDirPath)) { azPropFilePath = Path.Combine(azSdkPropDirPath, PROPS_APITAG_FILE_NAME); } var files = FileSysUtil.FindFilePaths(outputDirRootPath, dllName); if (files.NotNullOrAny <string>()) { var asms = files.Where <string>((item) => item.Contains("netstandard2.0", StringComparison.OrdinalIgnoreCase)); //var asms = files.Where<string>((item) => item.Contains("net45", StringComparison.OrdinalIgnoreCase)); if (asms.NotNullOrAny <string>()) { asmPath = asms.FirstOrDefault <string>(); TaskLogger.LogInfo(MessageImportance.High, "Assembly that will be used to get SdkInfo '{0}'", asmPath); } else { TaskLogger.LogWarning("Unable to find built assembly. Please build your project and try again."); } } if (!File.Exists(azPropFilePath)) { AzPropFileExists = false; } if (!File.Exists(asmPath)) { AssemblyFilePathExists = false; TaskLogger.LogWarning("'{0}' does not exist. Build project '{1}'", asmPath, sdkProjTaskItem.ItemSpec); } if (File.Exists(sdkProjTaskItem.ItemSpec) && //AzPropFileExists == true && AssemblyFilePathExists == true) { dynamic newObj = new ExpandoObject(); //dynamic newObj = new SDKMSBTaskItem(sdkProjTaskItem); newObj.AzPropFilePath = azPropFilePath; newObj.AssemblyFilePath = asmPath; newObj.ProjectFilePath = sdkProjTaskItem.ItemSpec; AssemblyInfoList.Add(newObj); //Tuple<string, string, string> asmTuple = new Tuple<string, string, string>(sdkProjTaskItem.ItemSpec, azPropFilePath, asmPath); //AssemblyInfoList.Add(asmTuple); } } }