Skip to content

Build Quality Checks gives unexpected baseline coverage percentage #252

@QxBytes

Description

@QxBytes

Describe the context

  • Extension: BuildQualityChecks
  • Environment: Azure DevOps Services
    • Server version: N/A
  • Agent type: Microsoft
    • Agent version: N/A
  • Pipeline type: YAML

Describe the problem and expected behavior
When I run BQC twice for the same code I expect the baseline code coverage % to be what BQC reports as the current code coverage in the previous run; however this is not the case and I don't know how BQC gets the previous run's code coverage % (what files it looks for etc.)

Steps:

  • I run my golang unit test suite and generate a coverage profile (coverage.out)
  • I use go tool cover -func=coverage.out to confirm the % covered
  • I convert the .out to .json with gocov convert
  • I convert the .json to .xml with gocov-xml
  • I publish the xml file and upon downloading, I confirm the % covered
  • I publish the xml file using PublishCodeCoverageResults@2
  • I run BuildQualityChecks@8 and it shows the same % covered (Shows # of lines and # of lines covered)
  • I wait for the pipeline to finish and the code coverage tab also reports the same % covered
  • Once the pipeline finishes and I have a baseline, I run it again without making any changes to the code; however, when it reaches the check, the # of lines and # of lines covered is far less and the % covered differs greatly.
  • I expect that if I run BuildQualityChecks and get a % covered w/ # of lines and # of lines covered, the next time I run it, the baseline shows the previous run's % covered w/ # of lines and # of lines covered.
  • I confirm the baseline build ID corresponds to the expected previous run

BQC Logs from second run (The first run shows the current coverage still as 56.11% with same line counts):

Starting: Check Code Coverage Regression
==============================================================================
Task         : Build Quality Checks
Description  : Breaks a build based on quality metrics like number of warnings or code coverage.
Version      : 8.2.1
Author       : Microsoft
Help         : [[Docs]](https://github.com/MicrosoftPremier/VstsExtensions/blob/master/BuildQualityChecks/en-US/overview.md)
...
Validating code coverage policy...
Successfully read code coverage data from build.
Evaluating coverage data from 1 filtered code coverage data sets...
Total lines: 1702
Covered lines: 955
Code Coverage (%): 56.1105
Found baseline build with ID 120470974.
Successfully read code coverage data from build.
Evaluating coverage data from 1 filtered code coverage data sets...
Total lines: 687
Covered lines: 269
Code Coverage (%): 39.1557
[SUCCESS] Code coverage policy passed with 56.1105% (955/1702 lines).

Not sure how we get 39.15%-- if BQC is just reading the previously published xml data shouldn't it still be 56.11%?

Artifacts folder structure:
Image

XML Uploaded:
Image

Code Coverage Tab:
Image

YAML:

- stage: code_coverage
    displayName: Code Coverage Check
    dependsOn:
      - test
    jobs:
      - job: coverage
        displayName: Check Coverage
        pool:
          name: "$(BUILD_POOL_NAME_DEFAULT)"
        variables:
          system.debug: true
          BQC.LogRawData: true
        steps:
          - task: DownloadPipelineArtifact@2
            inputs:
              artifact: 'linux-coverage'
              path: './'
          - bash: |
              ... make tools ...

              gocov convert linux-coverage.out > linux-coverage.json
              gocov-xml < linux-coverage.json > linux-coverage.xml

              mkdir coverage

              mv linux-coverage.xml coverage/
            name: "Coverage"
            displayName: "Generate Coverage Report"
            condition: always()
          - task: UseDotNet@2
            displayName: 'Use .NET Core sdk 7.0.x for Publish Code Coverage Results v2'
            inputs:
              version: 7.0.x
          - task: PublishCodeCoverageResults@2
            displayName: "Publish Code Coverage Report"
            condition: always()
            inputs:
              summaryFileLocation: coverage/linux-coverage.xml
          - task: PublishPipelineArtifact@1
            inputs:
              targetPath: 'coverage/linux-coverage.xml'
              artifactName: 'linux-coverage-xml'
          - task: BuildQualityChecks@8
            displayName: "Check Code Coverage Regression"
            condition: always()
            inputs:
              checkCoverage: true
              coverageFailOption: "build"
              coverageType: "lines"
              fallbackOnPRTargetBranch: false
              baseBranchRef: "my-feature-branch"
              allowCoverageVariance: true
              coverageVariance: 0.25

Task logs
Run your pipeline with the following variables:

  • For BuildQualityChecks: System.Debug and BQC.LogRawData set to true
  • For CreateWorkItem: System.Debug set to true
  • For PostBuildCleanup: System.Debug and PBC.LogRawData set to true

Send the task log to PSGerExtSupport@microsoft.com and reference your GitHub issue.

Attention: The log file may contain sensitive data (e.g., server or organization names, project names, variable information). Please do not attach the log to your GitHub issue and or remove the information from the log file before attaching or sending.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions