bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Output Linting results to an Nunit Xml file

Open lr90 opened this issue 5 years ago • 6 comments

Is your feature request related to a problem? Please describe. I would like to use the Bicep Linting to validate bicep code as part of my (ADO) build pipelines as an alternative to using the ARM-TTK toolkit. Ensuring code is created and tested against the same ruleset. While I can do this I can't report in ADO that n linting tests have been run across m bicep files and light up all the ADO charts/analysis.

Could the linter be extended to generate a Nunit XML output file (new option in bicepconfig.json)

I did look at enabling the verbose output in the hope I might have been able to parse/manipulate that but it does not report successes and in any event there is probably a far easier way :-)

Describe the solution you'd like Not too fixed on how but if I could add an output filename to the bicepconfig.json such that the pipeline could run the linting tests over one or more bicep files and the XML file is then available for import into ADO using the PublishTestResults@2 task that would be great!

lr90 avatar Jun 08 '21 16:06 lr90

Compilers and linters typically just fail the build if there are errors and log results to a text log file or stdout. Usually, it's the test results run by a test framework (like nUnit or mstest) that get published to ADO rather than compiler logs.

I have some questions to make sure I understand the ask:

  1. Do you see the Bicep linter as a set of tests that validate the template rather than "just" a linter?
  2. Would you expect us to model each rule that is run as a test in the output file with a corresponding pass/fail state?
  3. What do you do with the results after they were published from the pipeline?

majastrz avatar Jun 08 '21 18:06 majastrz

Darn must have failed to hit comment last time before I got distracted :(

In brief:

  1. Yes, we run all 22 arm-ttk 'tests' currently and it does improve quality/consistency
  2. Yes, 22 tests on two Bicep files would show 44 tests with pass/fail status and details of the failures
  3. They light up the ADO pipeline analysis graphs/dashboards showing test rates and failures over time

Happy to provide more info of show what we're doing in ADO with our Bicep pipelines

lr90 avatar Jun 10 '21 16:06 lr90

@lr90 - do you happen to know of other linters that emit with this format?

alex-frankel avatar Jun 10 '21 20:06 alex-frankel

I'm coming from having used arm-ttk in my pipelines to provide a level of quality testing of the code and didn't consider it a linter. Arm-ttk "can be used for analyzing and testing Azure Resource Manager Templates" and I'm using the PublishBuildArtifacts@1 task to publish the results into ADO.

To output the results in NunitXML format I'm using the psm form here: https://github.com/MathieuBuisson/PowerShell-DevOps/blob/master/Export-NUnitXml/Export-NUnitXml.psm1

lr90 avatar Jun 11 '21 09:06 lr90

@alex-frankel - eslint outputs to JUnit. The Publish Test Results Task mentioned in the original post supports this.

https://github.com/eslint/eslint/blob/master/lib/cli-engine/formatters/junit.js

https://eslint.org/docs/user-guide/formatters/#output-examples

nicktolhurst avatar Jun 17 '21 22:06 nicktolhurst

I'm going to close this in favor of #2973. Definitely a case to be made for publishing linter results in a variety of formats per eslint - thanks for the context @nicktolhurst

alex-frankel avatar Jun 17 '21 22:06 alex-frankel