azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

Build snippets failed for `ResourceManager` and `Azure.Core`

Open fengzhou-msft opened this issue 2 years ago • 10 comments
trafficstars

See CI error.

sdk/resourcemanager/Azure.ResourceManager/tests/Samples/Readme.cs(26,9): error CS1022: Type or namespace definition, or end-of-file expected sdk/resourcemanager/Azure.ResourceManager/tests/Samples/Readme.cs(30,9): error CS0106: The modifier 'public' is not valid for this item sdk/core/Azure.Core/tests/samples/PollyPolicy.cs(75,1): error CS1022: Type or namespace definition, or end-of-file expected

It's probably related to the use of #if SNIPPET or #if !SNIPPET in following files: Readme.cs PollyPolicy.cs

fengzhou-msft avatar Feb 07 '23 09:02 fengzhou-msft

@heaths can you advise on how to fix the issue?

fengzhou-msft avatar Feb 07 '23 09:02 fengzhou-msft

//cc: @JoshLove-msft

The Polly Policy code appears to be invalid when SNIPPET is defined. I believe it needs an #else that hides the rest of the code. Likewise, for ReadMe.cs - when SNIPPET is defined, the code is malformed and not compilable. There seems to be major structural issues in that scenario that require some tweaking.

To test, I'd suggest defining SNIPPET in your IDE or the project file and attempting to compile. That will allow you to see what the pipeline is seeing and troubleshoot the compiler errors.

jsquire avatar Feb 07 '23 14:02 jsquire

Hmm I'm not sure how the change to always build snippets was able to merge in with build failures.

JoshLove-msft avatar Feb 07 '23 19:02 JoshLove-msft

@JoshLove-msft I had the same problem with Cognitive. I'm assuming it's because we changed how net - core - ci works now, that it doesn't necessarily build everything.

@fengzhou-msft the code - whether built with SNIPPET or not - has to be valid code. There's lots of tricks you can do, but generally think about either defining things uniquely in any #if SNIPPET and #else block, or define them generally and override in an #if !SNIPPET block. Use the command line from the pipeline failure e.g., dotnet build eng/service.proj ... to test your changes before submitting to avoid pushing commit after commit until the CI works (faster, too).

heaths avatar Feb 07 '23 19:02 heaths

net - core - ci doesn't build everything? I thought we split the tests out among different pipelines but that we would still build everything. /cc @weshaggard @m-nash

JoshLove-msft avatar Feb 07 '23 19:02 JoshLove-msft

@JoshLove-msft snippets are only built in the Analyze step not during the normal source or test build which is why it wasn't covered by the core ci.

weshaggard avatar Feb 07 '23 23:02 weshaggard

It also didn't occur because sdk/core/ci.yml had BuildSnippets: false because of some of its own errors that didn't have a straight forward solution. Either way, these were missed. I'm working on fixing a few and will turn off snippet build for * as well as individual project directories if not immediately easy to fix.

heaths avatar Feb 08 '23 00:02 heaths

@weshaggard we might consider doing the same thing we did with resourcemanager where the leaf projects run but only the build and analyze steps which are much faster.

m-nash avatar Feb 09 '23 23:02 m-nash

That wouldn't have helped here as those other pipelines weren't triggered because it was a common file that changed and not anything in their directory.

weshaggard avatar Feb 10 '23 00:02 weshaggard

Yeah my suggestion was around updating triggers so that they do run off common files :-)

Or maybe the solution is to build a 2nd sparse matrix that handles build / analyze while the current one handles tests.

m-nash avatar Feb 10 '23 18:02 m-nash