Skip to content

Commit

Permalink
Update Code Coverage Calculations (#266)
Browse files Browse the repository at this point in the history
Update code coverage calculations to have the ability to reorganize the
report by INF using `stuart_parse` and `stuart_report.`

Code Coverage is now disabled by default and must be enabled with `calculate_code_coverage: true` in MuDevOpsWrapper.yml
  • Loading branch information
Javagedes authored Nov 3, 2023
1 parent eb94dce commit 649a4ba
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .sync/azure_pipelines/MuDevOpsWrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ parameters:
displayName: Perform Stuart PR Evaluation
type: boolean
default: true
- name: calculate_code_coverage
displayName: Calculate Code Coverage From Unit Tests
default: false
- name: container_build
displayName: Flag for whether this repo should do stuart_setup
type: boolean
Expand Down Expand Up @@ -89,6 +92,7 @@ jobs:
do_ci_build: ${{ parameters.do_ci_build }}
do_ci_setup: ${{ parameters.do_ci_setup }}
do_pr_eval: ${{ parameters.do_pr_eval }}
calculate_code_coverage: ${{ parameters.calculate_code_coverage }}
do_non_ci_setup: ${{ parameters.do_non_ci_setup }}
do_non_ci_build: ${{ parameters.do_non_ci_build }}
build_matrix: ${{ parameters.build_matrix }}
Expand Down
36 changes: 24 additions & 12 deletions Jobs/PrGate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ parameters:
displayName: Perform Stuart PR Evaluation
type: boolean
default: true
- name: calculate_code_coverage
displayName: Calculate Code Coverage
type: boolean
default: false
- name: extra_post_build_steps
displayName: Extra Post-Build Steps
type: stepList
Expand Down Expand Up @@ -164,19 +168,27 @@ jobs:
self_host_agent: true
${{ else }}:
self_host_agent: false
extra_build_args: CODE_COVERAGE=TRUE
${{ if eq(parameters.calculate_code_coverage, true) }}:
extra_build_args: CODE_COVERAGE=TRUE
${{ else }}:
extra_build_args: ''

- job: PublishCoverage
dependsOn:
- ${{ each item in parameters.build_matrix }}:
- Build_${{ item.Key }}
condition: and(not(Canceled()), not(Failed()))
- ${{ if eq(parameters.calculate_code_coverage, true) }}:
- job: PublishCoverage
dependsOn:
- ${{ each item in parameters.build_matrix }}:
- Build_${{ item.Key }}
condition: and(not(Canceled()), not(Failed()))

workspace:
clean: all
workspace:
clean: all

pool:
vmImage: 'windows-latest'
pool:
vmImage: 'windows-latest'

steps:
- template: ../Steps/PublishCodeCoverage.yml
steps:
- template: ../Steps/PublishCodeCoverage.yml
parameters:
reorganize_by_inf: true
extra_parse_args: -t NOOPT TOOL_CHAIN_TAG=$(tool_chain_tag)
build_file: ${{ parameters.build_file }}
35 changes: 34 additions & 1 deletion Steps/PublishCodeCoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@ parameters:
displayName: Perform self checkout step
type: boolean
default: true
- name: setup_python
displayName: Setup Python
type: boolean
default: true
- name: reorganize_by_inf
displayName: Reorganize cobertura report by INF # Requires stuart_report & stuart_parse
type: boolean
default: false
- name: extra_parse_args
displayName: Extra arguments for stuart_parse
type: string
default: ''
- name: build_file
displayName: Stuart Build File
type: string
default: ".pytool/CISettings.py"

steps:
- ${{ if eq(parameters.checkout_self, true) }}:
- checkout: self
clean: true
fetchDepth: 1

- ${{ if eq(parameters.setup_python, true ) }}:
- template: SetupPythonPreReqs.yml
parameters:
install_python: true
#
# Download the build
#
Expand All @@ -34,13 +54,26 @@ steps:
displayName: Check For Coverage Files

- task: CmdLine@2
displayName: Create Coverage Report
displayName: Merge Coverage Reports
inputs:
script: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:$(Build.ArtifactStagingDirectory)/coverage/**/*coverage.xml -targetdir:$(Build.ArtifactStagingDirectory)/Coverage -reporttypes:Cobertura
condition: gt(variables.coverage_file_count, 0)

- ${{ if eq(parameters.reorganize_by_inf, true) }}:
- task: CmdLine@2
displayName: Parse Workspace
inputs:
script: stuart_parse -c ${{ parameters.build_file }} ${{ parameters.extra_parse_args }}
condition: gt(variables.coverage_file_count, 0)

- task: CmdLine@2
displayName: Organize report by INF
inputs:
script: stuart_report coverage $(Build.ArtifactStagingDirectory)/Coverage/Cobertura.xml --by-package -o $(Build.ArtifactStagingDirectory)/Coverage/Cobertura.xml
condition: gt(variables.coverage_file_count, 0)

- task: PublishCodeCoverageResults@1
displayName: Publish Code Coverage
inputs:
Expand Down

0 comments on commit 649a4ba

Please sign in to comment.