Skip to content

Commit cc2ebb5

Browse files
authored
Added Code Coverage and fix Publish (#369)
1 parent 67805a2 commit cc2ebb5

File tree

6 files changed

+93
-20
lines changed

6 files changed

+93
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- WindowsEventLog
2121
- Reformatted code to better align with current DSCResources coding standards.
2222
- Renamed `master` branch to `main` - Fixes [Issue #348](https://github.com/dsccommunity/ComputerManagementDsc/issues/348).
23+
- Added support for publishing code coverage to `CodeCov.io` and
24+
Azure Pipelines - Fixes [Issue #367](https://github.com/dsccommunity/ComputerManagementDsc/issues/367).
25+
- Updated build to use `Sampler.GitHubTasks` - Fixes [Issue #365](https://github.com/dsccommunity/ComputerManagementDsc/issues/365).
26+
- Corrected case of module publish tasks - Fixes [Issue #368](https://github.com/dsccommunity/ComputerManagementDsc/issues/368).
2327

2428
### Fixed
2529

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/dsccommunity/ComputerManagementDsc/18/main)](https://dsccommunity.visualstudio.com/ComputerManagementDsc/_test/analytics?definitionId=18&contextType=build)
66
[![PowerShell Gallery (with prereleases)](https://img.shields.io/powershellgallery/vpre/ComputerManagementDsc?label=ComputerManagementDsc%20Preview)](https://www.powershellgallery.com/packages/ComputerManagementDsc/)
77
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/ComputerManagementDsc?label=ComputerManagementDsc)](https://www.powershellgallery.com/packages/ComputerManagementDsc/)
8+
[![codecov](https://codecov.io/gh/dsccommunity/ComputerManagementDsc/branch/main/graph/badge.svg)](https://codecov.io/gh/dsccommunity/StorageDsc)
9+
![Azure DevOps coverage (branch)](https://img.shields.io/azure-devops/coverage/dsccommunity/ComputerManagementDsc/14/main)
810

911
## Code of Conduct
1012

RequiredModules.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ModuleBuilder = 'latest'
1515
ChangelogManagement = 'latest'
1616
Sampler = 'latest'
17+
'Sampler.GitHubTasks' = 'latest'
1718
MarkdownLinkCheck = 'latest'
1819
'DscResource.Test' = 'latest'
1920
'DscResource.AnalyzerRules' = 'latest'

azure-pipelines.yml

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ trigger:
1111
exclude:
1212
- "*-*"
1313

14+
variables:
15+
buildFolderName: output
16+
buildArtifactName: output
17+
testResultFolderName: testResults
18+
testArtifactName: testResults
19+
1420
stages:
1521
- stage: Build
1622
jobs:
@@ -72,7 +78,7 @@ stages:
7278
displayName: 'Publish Test Results'
7379
inputs:
7480
testResultsFormat: 'NUnit'
75-
testResultsFiles: 'output/testResults/NUnit*.xml'
81+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
7682
testRunTitle: 'HQRM'
7783
condition: succeededOrFailed()
7884

@@ -109,17 +115,53 @@ stages:
109115
displayName: 'Publish Test Results'
110116
inputs:
111117
testResultsFormat: 'NUnit'
112-
testResultsFiles: 'output/testResults/NUnit*.xml'
118+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
113119
testRunTitle: 'Unit (Windows Server 2016)'
114120
condition: succeededOrFailed()
115121

122+
- task: PublishBuildArtifacts@1
123+
displayName: 'Publish Test Artifact'
124+
inputs:
125+
pathToPublish: '$(buildFolderName)/$(testResultFolderName)/'
126+
artifactName: $(testArtifactName)
127+
publishLocation: 'Container'
128+
129+
- job: Code_Coverage
130+
displayName: 'Publish Code Coverage'
131+
dependsOn: Test_Unit_2016
132+
pool:
133+
vmImage: 'ubuntu 16.04'
134+
timeoutInMinutes: 0
135+
steps:
136+
- pwsh: |
137+
$repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/'
138+
echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner"
139+
echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName"
140+
name: dscBuildVariable
141+
displayName: 'Set Environment Variables'
142+
143+
- task: DownloadBuildArtifacts@0
144+
displayName: 'Download Build Artifact'
145+
inputs:
146+
buildType: 'current'
147+
downloadType: 'single'
148+
artifactName: $(buildArtifactName)
149+
downloadPath: '$(Build.SourcesDirectory)'
150+
151+
- task: DownloadPipelineArtifact@2
152+
displayName: 'Download Test Artifact'
153+
inputs:
154+
buildType: 'current'
155+
artifactName: $(testArtifactName)
156+
targetPath: '$(Build.SourcesDirectory)/$(buildFolderName)/$(testResultFolderName)'
157+
116158
- task: PublishCodeCoverageResults@1
117-
displayName: 'Publish Code Coverage'
118-
condition: succeededOrFailed()
159+
displayName: 'Publish Code Coverage to Azure DevOps'
119160
inputs:
120161
codeCoverageTool: 'JaCoCo'
121-
summaryFileLocation: 'output/testResults/CodeCov*.xml'
122-
pathToSources: '$(Build.SourcesDirectory)/output/$(DscBuildVariable.RepositoryName)'
162+
summaryFileLocation: '$(Build.SourcesDirectory)/$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml'
163+
pathToSources: '$(Build.SourcesDirectory)/$(sourceFolderName)/'
164+
123165

124166
- job: Test_Integration_2016
125167
displayName: 'Integration (Windows Server 2016)'
@@ -159,7 +201,7 @@ stages:
159201
displayName: 'Publish Test Results'
160202
inputs:
161203
testResultsFormat: 'NUnit'
162-
testResultsFiles: 'output/testResults/NUnit*.xml'
204+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
163205
testRunTitle: 'Integration (Windows Server 2016)'
164206
condition: succeededOrFailed()
165207

@@ -196,18 +238,10 @@ stages:
196238
displayName: 'Publish Test Results'
197239
inputs:
198240
testResultsFormat: 'NUnit'
199-
testResultsFiles: 'output/testResults/NUnit*.xml'
241+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
200242
testRunTitle: 'Unit (Windows Server 2019)'
201243
condition: succeededOrFailed()
202244

203-
- task: PublishCodeCoverageResults@1
204-
displayName: 'Publish Code Coverage'
205-
condition: succeededOrFailed()
206-
inputs:
207-
codeCoverageTool: 'JaCoCo'
208-
summaryFileLocation: 'output/testResults/CodeCov*.xml'
209-
pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)'
210-
211245
- job: Test_Integration_2019
212246
displayName: 'Integration (Windows Server 2019)'
213247
pool:
@@ -242,7 +276,7 @@ stages:
242276
displayName: 'Publish Test Results'
243277
inputs:
244278
testResultsFormat: 'NUnit'
245-
testResultsFiles: 'output/testResults/NUnit*.xml'
279+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
246280
testRunTitle: 'Integration (Windows Server 2019)'
247281
condition: succeededOrFailed()
248282

build.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ BuildWorkflow:
4848
- Pester_If_Code_Coverage_Under_Threshold
4949

5050
publish:
51-
- Publish_Release_to_GitHub
52-
- Publish_Module_to_gallery
51+
- Publish_Release_To_GitHub
52+
- Publish_Module_To_gallery
5353
- Publish_GitHub_Wiki_Content
5454

5555
####################################################
@@ -64,7 +64,9 @@ Pester:
6464
- tests/Unit
6565
ExcludeTag:
6666
Tag:
67-
CodeCoverageThreshold: 70
67+
CodeCoverageOutputFile: JaCoCo_coverage.xml
68+
CodeCoverageOutputFileEncoding: ascii
69+
CodeCoverageThreshold: 80
6870

6971
DscTest:
7072
OutputFormat: NUnitXML
@@ -84,6 +86,8 @@ Resolve-Dependency:
8486
ModuleBuildTasks:
8587
Sampler:
8688
- '*.build.Sampler.ib.tasks'
89+
Sampler.GitHubTasks:
90+
- '*.ib.tasks'
8791
DscResource.DocGenerator:
8892
- 'Task.*'
8993

codecov.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
codecov:
2+
require_ci_to_pass: no
3+
# main should be the baseline for reporting
4+
branch: main
5+
6+
comment:
7+
layout: "reach, diff, flags, files"
8+
behavior: default
9+
10+
coverage:
11+
range: 50..80
12+
round: down
13+
precision: 0
14+
15+
status:
16+
project:
17+
default:
18+
# Set the overall project code coverage requirement to 70%
19+
target: 80
20+
patch:
21+
default:
22+
# Set the pull request requirement to not regress overall coverage by more than 5%
23+
# and let codecov.io set the goal for the code changed in the patch.
24+
target: auto
25+
threshold: 5
26+
27+
fixes:
28+
- '^\d+\.\d+\.\d+::source' # move path "X.Y.Z" => "source"

0 commit comments

Comments
 (0)