From 33e224691aa6357aeadca9cba52ead87ec8a224d Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Wed, 25 Sep 2024 09:37:59 -0700 Subject: [PATCH 1/5] Improve DevOps logging for code owners linter --- .../Program.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs index 55967bc9638..e9ed4ca9708 100644 --- a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs +++ b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs @@ -269,13 +269,23 @@ static int LintCodeownersFile(string teamUserBlobStorageUri, errors = baselineUtils.FilterErrorsUsingBaseline(errors); } } - + bool loggingInDevOps = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SYSTEM_TEAMPROJECTID")); int returnCode = 0; // If there are errors, and this isn't a baseline generation, ensure the returnCode is non-zero and output the errors. if ((errors.Count > 0) && !generateBaseline) { returnCode = 1; + // DevOps only adds the first 4 errors to the github checks list so lets always add the generic one first and then as many of the individual ones as can be found afterwards + if (loggingInDevOps) + { + Console.WriteLIne($"##vso[task.logissue type=error;]There are linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them."); + } + else + { + Console.WriteLine($"There are linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them."); + } + // Output the errors sorted ascending by line number and by type. If there's a block // error with the same starting line number as a single line error, the block error // should be output first. @@ -283,10 +293,15 @@ static int LintCodeownersFile(string teamUserBlobStorageUri, foreach (var error in errorsByLineAndType) { - Console.WriteLine(error + Environment.NewLine); + if (loggingInDevOps) + { + Console.WriteLIne($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace('\n','%0D%0A'}"); + } + else + { + Console.WriteLine(error + Environment.NewLine); + } } - - Console.WriteLine($"There were linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them."); } return returnCode; } From 1cc8aaaad1331c521aa5ec786d623e2f03d0961c Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Wed, 25 Sep 2024 10:03:55 -0700 Subject: [PATCH 2/5] Fix missing brace --- .../Azure.Sdk.Tools.CodeownersLinter/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs index e9ed4ca9708..5ee405bfc02 100644 --- a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs +++ b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs @@ -295,7 +295,7 @@ static int LintCodeownersFile(string teamUserBlobStorageUri, { if (loggingInDevOps) { - Console.WriteLIne($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace('\n','%0D%0A'}"); + Console.WriteLIne($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace('\n','%0D%0A')}"); } else { From deebca597617bb35bad302e064511ef034642e65 Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Wed, 25 Sep 2024 11:11:19 -0700 Subject: [PATCH 3/5] Update Program.cs --- .../Azure.Sdk.Tools.CodeownersLinter/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs index 5ee405bfc02..4dbd9a8858d 100644 --- a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs +++ b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs @@ -295,7 +295,7 @@ static int LintCodeownersFile(string teamUserBlobStorageUri, { if (loggingInDevOps) { - Console.WriteLIne($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace('\n','%0D%0A')}"); + Console.WriteLIne($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace(Environment.NewLine,"%0D%0A")}"); } else { From 711a515b43e570eea6a157e951aa4d81d47ee286 Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Wed, 25 Sep 2024 13:26:03 -0700 Subject: [PATCH 4/5] Update Program.cs --- .../Azure.Sdk.Tools.CodeownersLinter/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs index 4dbd9a8858d..981513e7053 100644 --- a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs +++ b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs @@ -279,7 +279,7 @@ static int LintCodeownersFile(string teamUserBlobStorageUri, // DevOps only adds the first 4 errors to the github checks list so lets always add the generic one first and then as many of the individual ones as can be found afterwards if (loggingInDevOps) { - Console.WriteLIne($"##vso[task.logissue type=error;]There are linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them."); + Console.WriteLine($"##vso[task.logissue type=error;]There are linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them."); } else { @@ -295,7 +295,7 @@ static int LintCodeownersFile(string teamUserBlobStorageUri, { if (loggingInDevOps) { - Console.WriteLIne($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace(Environment.NewLine,"%0D%0A")}"); + Console.WriteLine($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace(Environment.NewLine,"%0D%0A")}"); } else { From 4f346d93c57aeb3f5dc52d3fdcb3353d66fbdfdf Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Thu, 26 Sep 2024 09:20:09 -0700 Subject: [PATCH 5/5] Update Program.cs Add a comment as to why we had to replace the newline with an encoded newline. --- .../codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs index 981513e7053..7a7cd10f86d 100644 --- a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs +++ b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs @@ -295,6 +295,7 @@ static int LintCodeownersFile(string teamUserBlobStorageUri, { if (loggingInDevOps) { + // Environment.NewLine needs to be replaced by an encoded NewLine "%0D%0A" in order to display on GitHub and DevOps checks Console.WriteLine($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace(Environment.NewLine,"%0D%0A")}"); } else