Skip to content

Commit 076ab61

Browse files
authored
Add code coverage support in pipeline - Fixes #61 (#62)
1 parent 415a771 commit 076ab61

File tree

6 files changed

+114
-66
lines changed

6 files changed

+114
-66
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Automatically publish documentation to GitHub Wiki - Fixes [Issue #51](https://github.com/dsccommunity/FileContentDsc/issues/51).
2525
- Renamed `master` branch to `main` - Fixes [Issue #53](https://github.com/dsccommunity/FileContentDsc/issues/53).
2626
- Updated `GitVersion.yml` to latest pattern - Fixes [Issue #57](https://github.com/dsccommunity/FileContentDsc/issues/57).
27+
- Updated build to use `Sampler.GitHubTasks` - Fixes [Issue #60](https://github.com/dsccommunity/FileContentDsc/issues/60).
28+
- Added support for publishing code coverage to `CodeCov.io` and
29+
Azure Pipelines - Fixes [Issue #61](https://github.com/dsccommunity/FileContentDsc/issues/61).
2730

2831
## [1.3.0.151] - 2019-07-20
2932

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/FileContentDsc/31/main)](https://dsccommunity.visualstudio.com/FileContentDsc/_test/analytics?definitionId=31&contextType=build)
66
[![PowerShell Gallery (with prereleases)](https://img.shields.io/powershellgallery/vpre/FileContentDsc?label=FileContentDsc%20Preview)](https://www.powershellgallery.com/packages/FileContentDsc/)
77
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/FileContentDsc?label=FileContentDsc)](https://www.powershellgallery.com/packages/FileContentDsc/)
8+
[![codecov](https://codecov.io/gh/dsccommunity/FileContentDsc/branch/main/graph/badge.svg)](https://codecov.io/gh/dsccommunity/FileContentDsc)
89

910
## Code of Conduct
1011

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: 77 additions & 66 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

@@ -82,20 +89,12 @@ stages:
8289
vmImage: 'vs2017-win2016'
8390
timeoutInMinutes: 0
8491
steps:
85-
- powershell: |
86-
$repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/'
87-
echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner"
88-
echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName"
89-
name: dscBuildVariable
90-
displayName: 'Set Environment Variables'
91-
92-
- task: DownloadBuildArtifacts@0
93-
displayName: 'Download Build Artifact'
92+
- task: DownloadPipelineArtifact@2
93+
displayName: 'Download Pipeline Artifact'
9494
inputs:
9595
buildType: 'current'
96-
downloadType: 'single'
97-
artifactName: 'output'
98-
downloadPath: '$(Build.SourcesDirectory)'
96+
artifactName: $(buildArtifactName)
97+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
9998

10099
- task: PowerShell@2
101100
name: test
@@ -109,31 +108,61 @@ stages:
109108
displayName: 'Publish Test Results'
110109
inputs:
111110
testResultsFormat: 'NUnit'
112-
testResultsFiles: 'output/testResults/NUnit*.xml'
111+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
113112
testRunTitle: 'Unit (Windows Server 2016)'
114113
condition: succeededOrFailed()
115114

115+
- task: PublishPipelineArtifact@1
116+
displayName: 'Publish Test Artifact'
117+
inputs:
118+
targetPath: '$(buildFolderName)/$(testResultFolderName)/'
119+
artifactName: $(testArtifactName)
120+
parallel: true
121+
122+
- job: Code_Coverage
123+
displayName: 'Publish Code Coverage'
124+
dependsOn: Test_Unit_2016
125+
pool:
126+
vmImage: 'ubuntu 16.04'
127+
timeoutInMinutes: 0
128+
steps:
129+
- task: DownloadPipelineArtifact@2
130+
displayName: 'Download Pipeline Artifact'
131+
inputs:
132+
buildType: 'current'
133+
artifactName: $(buildArtifactName)
134+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
135+
136+
- task: DownloadPipelineArtifact@2
137+
displayName: 'Download Test Artifact'
138+
inputs:
139+
buildType: 'current'
140+
artifactName: $(testArtifactName)
141+
targetPath: '$(Build.SourcesDirectory)/$(buildFolderName)/$(testResultFolderName)'
142+
116143
- task: PublishCodeCoverageResults@1
117-
displayName: 'Publish Code Coverage'
118-
condition: succeededOrFailed()
144+
displayName: 'Publish Code Coverage to Azure DevOps'
119145
inputs:
120146
codeCoverageTool: 'JaCoCo'
121-
summaryFileLocation: 'output/testResults/CodeCov*.xml'
122-
pathToSources: '$(Build.SourcesDirectory)/output/$(DscBuildVariable.RepositoryName)'
147+
summaryFileLocation: '$(Build.SourcesDirectory)/$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml'
148+
pathToSources: '$(Build.SourcesDirectory)/$(sourceFolderName)/'
149+
150+
- script: |
151+
bash <(curl -s https://codecov.io/bash) -f "./$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml"
152+
displayName: 'Publish Code Coverage to Codecov.io'
123153
124154
- job: Test_Integration_2016
125155
displayName: 'Integration (Windows Server 2016)'
126156
pool:
127157
vmImage: 'vs2017-win2016'
128158
timeoutInMinutes: 0
129159
steps:
130-
- task: DownloadBuildArtifacts@0
131-
displayName: 'Download Build Artifact'
160+
- task: DownloadPipelineArtifact@2
161+
displayName: 'Download Pipeline Artifact'
132162
inputs:
133163
buildType: 'current'
134-
downloadType: 'single'
135-
artifactName: 'output'
136-
downloadPath: '$(Build.SourcesDirectory)'
164+
artifactName: $(buildArtifactName)
165+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
137166

138167
- task: PowerShell@2
139168
name: configureWinRM
@@ -155,7 +184,7 @@ stages:
155184
displayName: 'Publish Test Results'
156185
inputs:
157186
testResultsFormat: 'NUnit'
158-
testResultsFiles: 'output/testResults/NUnit*.xml'
187+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
159188
testRunTitle: 'Integration (Windows Server 2016)'
160189
condition: succeededOrFailed()
161190

@@ -165,20 +194,12 @@ stages:
165194
vmImage: 'windows-2019'
166195
timeoutInMinutes: 0
167196
steps:
168-
- powershell: |
169-
$repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/'
170-
echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner"
171-
echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName"
172-
name: dscBuildVariable
173-
displayName: 'Set Environment Variables'
174-
175-
- task: DownloadBuildArtifacts@0
176-
displayName: 'Download Build Artifact'
197+
- task: DownloadPipelineArtifact@2
198+
displayName: 'Download Pipeline Artifact'
177199
inputs:
178200
buildType: 'current'
179-
downloadType: 'single'
180-
artifactName: 'output'
181-
downloadPath: '$(Build.SourcesDirectory)'
201+
artifactName: $(buildArtifactName)
202+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
182203

183204
- task: PowerShell@2
184205
name: test
@@ -192,31 +213,22 @@ stages:
192213
displayName: 'Publish Test Results'
193214
inputs:
194215
testResultsFormat: 'NUnit'
195-
testResultsFiles: 'output/testResults/NUnit*.xml'
216+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
196217
testRunTitle: 'Unit (Windows Server 2019)'
197218
condition: succeededOrFailed()
198219

199-
- task: PublishCodeCoverageResults@1
200-
displayName: 'Publish Code Coverage'
201-
condition: succeededOrFailed()
202-
inputs:
203-
codeCoverageTool: 'JaCoCo'
204-
summaryFileLocation: 'output/testResults/CodeCov*.xml'
205-
pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)'
206-
207220
- job: Test_Integration_2019
208221
displayName: 'Integration (Windows Server 2019)'
209222
pool:
210223
vmImage: 'windows-2019'
211224
timeoutInMinutes: 0
212225
steps:
213-
- task: DownloadBuildArtifacts@0
214-
displayName: 'Download Build Artifact'
226+
- task: DownloadPipelineArtifact@2
227+
displayName: 'Download Pipeline Artifact'
215228
inputs:
216229
buildType: 'current'
217-
downloadType: 'single'
218-
artifactName: 'output'
219-
downloadPath: '$(Build.SourcesDirectory)'
230+
artifactName: $(buildArtifactName)
231+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
220232

221233
- task: PowerShell@2
222234
name: configureWinRM
@@ -238,7 +250,7 @@ stages:
238250
displayName: 'Publish Test Results'
239251
inputs:
240252
testResultsFormat: 'NUnit'
241-
testResultsFiles: 'output/testResults/NUnit*.xml'
253+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
242254
testRunTitle: 'Integration (Windows Server 2019)'
243255
condition: succeededOrFailed()
244256

@@ -259,13 +271,12 @@ stages:
259271
pool:
260272
vmImage: 'ubuntu 16.04'
261273
steps:
262-
- task: DownloadBuildArtifacts@0
263-
displayName: 'Download Build Artifact'
274+
- task: DownloadPipelineArtifact@2
275+
displayName: 'Download Pipeline Artifact'
264276
inputs:
265277
buildType: 'current'
266-
downloadType: 'single'
267-
artifactName: 'output'
268-
downloadPath: '$(Build.SourcesDirectory)'
278+
artifactName: $(buildArtifactName)
279+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
269280

270281
- task: PowerShell@2
271282
name: publishRelease

build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Pester:
6464
- tests/Unit
6565
ExcludeTag:
6666
Tag:
67+
CodeCoverageOutputFile: JaCoCo_coverage.xml
68+
CodeCoverageOutputFileEncoding: ascii
6769
CodeCoverageThreshold: 70
6870

6971
DscTest:
@@ -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: 70
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)