Skip to content

Commit 7dc47bb

Browse files
authored
Added Code Coverage to build pipeline - Fixes #91 (#93)
1 parent 8546e7f commit 7dc47bb

File tree

5 files changed

+114
-52
lines changed

5 files changed

+114
-52
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737
branch to `main`.
3838
- Updated `GitVersion.yml` to latest pattern - Fixes [Issue #87](https://github.com/dsccommunity/WSManDsc/issues/87).
3939
- Updated build to use `Sampler.GitHubTasks` - Fixes [Issue #90](https://github.com/dsccommunity/WSManDsc/issues/90).
40+
- Added support for publishing code coverage to `CodeCov.io` and
41+
Azure Pipelines - Fixes [Issue #91](https://github.com/dsccommunity/WSManDsc/issues/91).
4042

4143
## [3.1.1] - 2020-01-31
4244

README.md

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

910
The **WSManDsc** module contains DSC resources for configuring WS-Management and
1011
PowerShell Remoting.

azure-pipelines.yml

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

14+
variables:
15+
buildFolderName: output
16+
buildArtifactName: output
17+
testResultFolderName: testResults
18+
testArtifactName: testResults
19+
sourceFolderName: source
20+
1421
stages:
1522
- stage: Build
1623
jobs:
@@ -36,12 +43,13 @@ stages:
3643
env:
3744
ModuleVersion: $(gitVersion.Informationalversion)
3845

39-
- task: PublishBuildArtifacts@1
40-
displayName: 'Publish Build Artifact'
46+
- task: PublishPipelineArtifact@1
47+
displayName: 'Publish Pipeline Artifact'
4148
inputs:
42-
PathtoPublish: 'output/'
43-
ArtifactName: 'output'
44-
publishLocation: 'Container'
49+
targetPath: '$(buildFolderName)/'
50+
artifact: $(buildArtifactName)
51+
publishLocation: 'pipeline'
52+
parallel: true
4553

4654
- stage: Test
4755
dependsOn: Build
@@ -52,13 +60,12 @@ stages:
5260
vmImage: 'windows-2019'
5361
timeoutInMinutes: 0
5462
steps:
55-
- task: DownloadBuildArtifacts@0
56-
displayName: 'Download Build Artifact'
63+
- task: DownloadPipelineArtifact@2
64+
displayName: 'Download Pipeline Artifact'
5765
inputs:
5866
buildType: 'current'
59-
downloadType: 'single'
60-
artifactName: 'output'
61-
downloadPath: '$(Build.SourcesDirectory)'
67+
artifactName: $(buildArtifactName)
68+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
6269

6370
- task: PowerShell@2
6471
name: Test
@@ -72,7 +79,7 @@ stages:
7279
displayName: 'Publish Test Results'
7380
inputs:
7481
testResultsFormat: 'NUnit'
75-
testResultsFiles: 'output/testResults/NUnit*.xml'
82+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
7683
testRunTitle: 'HQRM'
7784
condition: succeededOrFailed()
7885

@@ -87,12 +94,13 @@ stages:
8794
echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner"
8895
echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName"
8996
name: dscBuildVariable
90-
- task: DownloadBuildArtifacts@0
97+
98+
- task: DownloadPipelineArtifact@2
99+
displayName: 'Download Pipeline Artifact'
91100
inputs:
92101
buildType: 'current'
93-
downloadType: 'single'
94-
artifactName: 'output'
95-
downloadPath: '$(Build.SourcesDirectory)'
102+
artifactName: $(buildArtifactName)
103+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
96104

97105
- task: PowerShell@2
98106
name: test
@@ -106,31 +114,61 @@ stages:
106114
displayName: 'Publish Test Results'
107115
inputs:
108116
testResultsFormat: 'NUnit'
109-
testResultsFiles: 'output/testResults/NUnit*.xml'
117+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
110118
testRunTitle: 'Unit (Windows Server 2016)'
111119
condition: succeededOrFailed()
112120

121+
- task: PublishPipelineArtifact@1
122+
displayName: 'Publish Test Artifact'
123+
inputs:
124+
targetPath: '$(buildFolderName)/$(testResultFolderName)/'
125+
artifactName: $(testArtifactName)
126+
parallel: true
127+
128+
- job: Code_Coverage
129+
displayName: 'Publish Code Coverage'
130+
dependsOn: Test_Unit_2016
131+
pool:
132+
vmImage: 'ubuntu 16.04'
133+
timeoutInMinutes: 0
134+
steps:
135+
- task: DownloadPipelineArtifact@2
136+
displayName: 'Download Pipeline Artifact'
137+
inputs:
138+
buildType: 'current'
139+
artifactName: $(buildArtifactName)
140+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
141+
142+
- task: DownloadPipelineArtifact@2
143+
displayName: 'Download Test Artifact'
144+
inputs:
145+
buildType: 'current'
146+
artifactName: $(testArtifactName)
147+
targetPath: '$(Build.SourcesDirectory)/$(buildFolderName)/$(testResultFolderName)'
148+
113149
- task: PublishCodeCoverageResults@1
114-
displayName: 'Publish Code Coverage'
115-
condition: succeededOrFailed()
150+
displayName: 'Publish Code Coverage to Azure DevOps'
116151
inputs:
117152
codeCoverageTool: 'JaCoCo'
118-
summaryFileLocation: 'output/testResults/CodeCov*.xml'
119-
pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)'
153+
summaryFileLocation: '$(Build.SourcesDirectory)/$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml'
154+
pathToSources: '$(Build.SourcesDirectory)/$(sourceFolderName)/'
155+
156+
- script: |
157+
bash <(curl -s https://codecov.io/bash) -f "./$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml"
158+
displayName: 'Publish Code Coverage to Codecov.io'
120159
121160
- job: Test_Integration_2016
122161
displayName: 'Integration (Windows Server 2016)'
123162
pool:
124163
vmImage: 'vs2017-win2016'
125164
timeoutInMinutes: 0
126165
steps:
127-
- task: DownloadBuildArtifacts@0
128-
displayName: 'Download Build Artifact'
166+
- task: DownloadPipelineArtifact@2
167+
displayName: 'Download Pipeline Artifact'
129168
inputs:
130169
buildType: 'current'
131-
downloadType: 'single'
132-
artifactName: 'output'
133-
downloadPath: '$(Build.SourcesDirectory)'
170+
artifactName: $(buildArtifactName)
171+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
134172

135173
- task: PowerShell@2
136174
name: configureWinRM
@@ -152,7 +190,7 @@ stages:
152190
displayName: 'Publish Test Results'
153191
inputs:
154192
testResultsFormat: 'NUnit'
155-
testResultsFiles: 'output/testResults/NUnit*.xml'
193+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
156194
testRunTitle: 'Integration (Windows Server 2016)'
157195
condition: succeededOrFailed()
158196

@@ -167,12 +205,13 @@ stages:
167205
echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner"
168206
echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName"
169207
name: dscBuildVariable
170-
- task: DownloadBuildArtifacts@0
208+
209+
- task: DownloadPipelineArtifact@2
210+
displayName: 'Download Pipeline Artifact'
171211
inputs:
172212
buildType: 'current'
173-
downloadType: 'single'
174-
artifactName: 'output'
175-
downloadPath: '$(Build.SourcesDirectory)'
213+
artifactName: $(buildArtifactName)
214+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
176215

177216
- task: PowerShell@2
178217
name: test
@@ -186,31 +225,22 @@ stages:
186225
displayName: 'Publish Test Results'
187226
inputs:
188227
testResultsFormat: 'NUnit'
189-
testResultsFiles: 'output/testResults/NUnit*.xml'
228+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
190229
testRunTitle: 'Unit (Windows Server 2019)'
191230
condition: succeededOrFailed()
192231

193-
- task: PublishCodeCoverageResults@1
194-
displayName: 'Publish Code Coverage'
195-
condition: succeededOrFailed()
196-
inputs:
197-
codeCoverageTool: 'JaCoCo'
198-
summaryFileLocation: 'output/testResults/CodeCov*.xml'
199-
pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)'
200-
201232
- job: Test_Integration_2019
202233
displayName: 'Integration (Windows Server 2019)'
203234
pool:
204235
vmImage: 'windows-2019'
205236
timeoutInMinutes: 0
206237
steps:
207-
- task: DownloadBuildArtifacts@0
208-
displayName: 'Download Build Artifact'
238+
- task: DownloadPipelineArtifact@2
239+
displayName: 'Download Pipeline Artifact'
209240
inputs:
210241
buildType: 'current'
211-
downloadType: 'single'
212-
artifactName: 'output'
213-
downloadPath: '$(Build.SourcesDirectory)'
242+
artifactName: $(buildArtifactName)
243+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
214244

215245
- task: PowerShell@2
216246
name: configureWinRM
@@ -232,7 +262,7 @@ stages:
232262
displayName: 'Publish Test Results'
233263
inputs:
234264
testResultsFormat: 'NUnit'
235-
testResultsFiles: 'output/testResults/NUnit*.xml'
265+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
236266
testRunTitle: 'Integration (Windows Server 2019)'
237267
condition: succeededOrFailed()
238268

@@ -253,13 +283,12 @@ stages:
253283
pool:
254284
vmImage: 'ubuntu 16.04'
255285
steps:
256-
- task: DownloadBuildArtifacts@0
257-
displayName: 'Download Build Artifact'
286+
- task: DownloadPipelineArtifact@2
287+
displayName: 'Download Pipeline Artifact'
258288
inputs:
259289
buildType: 'current'
260-
downloadType: 'single'
261-
artifactName: 'output'
262-
downloadPath: '$(Build.SourcesDirectory)'
290+
artifactName: $(buildArtifactName)
291+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
263292

264293
- task: PowerShell@2
265294
name: publishRelease

build.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ BuildWorkflow:
4747
- Pester_If_Code_Coverage_Under_Threshold
4848

4949
publish:
50-
- Publish_Release_to_GitHub
51-
- Publish_Module_to_gallery
50+
- Publish_Release_To_GitHub
51+
- Publish_Module_To_gallery
5252
- Publish_GitHub_Wiki_Content
5353

5454
####################################################
@@ -63,6 +63,8 @@ Pester:
6363
- tests/Unit
6464
ExcludeTag:
6565
Tag:
66+
CodeCoverageOutputFile: JaCoCo_coverage.xml
67+
CodeCoverageOutputFileEncoding: ascii
6668
CodeCoverageThreshold: 85
6769

6870
DscTest:

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: 85
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)