Skip to content

Commit fc7d5d1

Browse files
authored
Add support for code coverage reporting in pipeline - Fixes #130 (#131)
1 parent dc0e72d commit fc7d5d1

5 files changed

Lines changed: 88 additions & 68 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Automatically publish documentation to GitHub Wiki - Fixes [Issue #122](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/122).
1212
- Renamed `master` branch to `main` - Fixes [Issue #124](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/124).
1313
- Updated `GitVersion.yml` to latest pattern - Fixes [Issue #126](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/126).
14+
- Updated build to use `Sampler.GitHubTasks` - Fixes [Issue #129](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/129).
15+
- Added support for publishing code coverage to `CodeCov.io` and
16+
Azure Pipelines - Fixes [Issue #130](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/130).
1417

1518
## [5.0.0] - 2020-06-20
1619

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/ActiveDirectoryCSDsc/24/main)](https://dsccommunity.visualstudio.com/ActiveDirectoryCSDsc/_test/analytics?definitionId=24&contextType=build)
66
[![PowerShell Gallery (with prereleases)](https://img.shields.io/powershellgallery/vpre/ActiveDirectoryCSDsc?label=ActiveDirectoryCSDsc%20Preview)](https://www.powershellgallery.com/packages/ActiveDirectoryCSDsc/)
77
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/ActiveDirectoryCSDsc?label=ActiveDirectoryCSDsc)](https://www.powershellgallery.com/packages/ActiveDirectoryCSDsc/)
8+
[![codecov](https://codecov.io/gh/dsccommunity/ActiveDirectoryCSDsc/branch/main/graph/badge.svg)](https://codecov.io/gh/dsccommunity/ActiveDirectoryCSDsc)
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
@@ -163,7 +192,7 @@ stages:
163192
displayName: 'Publish Test Results'
164193
inputs:
165194
testResultsFormat: 'NUnit'
166-
testResultsFiles: 'output/testResults/NUnit*.xml'
195+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
167196
testRunTitle: 'Integration (Windows Server 2016)'
168197
condition: succeededOrFailed()
169198

@@ -173,20 +202,12 @@ stages:
173202
vmImage: 'windows-2019'
174203
timeoutInMinutes: 0
175204
steps:
176-
- powershell: |
177-
$repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/'
178-
echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner"
179-
echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName"
180-
name: dscBuildVariable
181-
displayName: 'Set Environment Variables'
182-
183-
- task: DownloadBuildArtifacts@0
184-
displayName: 'Download Build Artifact'
205+
- task: DownloadPipelineArtifact@2
206+
displayName: 'Download Pipeline Artifact'
185207
inputs:
186208
buildType: 'current'
187-
downloadType: 'single'
188-
artifactName: 'output'
189-
downloadPath: '$(Build.SourcesDirectory)'
209+
artifactName: $(buildArtifactName)
210+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
190211

191212
- task: PowerShell@2
192213
name: test
@@ -200,31 +221,22 @@ stages:
200221
displayName: 'Publish Test Results'
201222
inputs:
202223
testResultsFormat: 'NUnit'
203-
testResultsFiles: 'output/testResults/NUnit*.xml'
224+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
204225
testRunTitle: 'Unit (Windows Server 2019)'
205226
condition: succeededOrFailed()
206227

207-
- task: PublishCodeCoverageResults@1
208-
displayName: 'Publish Code Coverage'
209-
condition: succeededOrFailed()
210-
inputs:
211-
codeCoverageTool: 'JaCoCo'
212-
summaryFileLocation: 'output/testResults/CodeCov*.xml'
213-
pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)'
214-
215228
- job: Test_Integration_2019
216229
displayName: 'Integration (Windows Server 2019)'
217230
pool:
218231
vmImage: 'windows-2019'
219232
timeoutInMinutes: 0
220233
steps:
221-
- task: DownloadBuildArtifacts@0
222-
displayName: 'Download Build Artifact'
234+
- task: DownloadPipelineArtifact@2
235+
displayName: 'Download Pipeline Artifact'
223236
inputs:
224237
buildType: 'current'
225-
downloadType: 'single'
226-
artifactName: 'output'
227-
downloadPath: '$(Build.SourcesDirectory)'
238+
artifactName: $(buildArtifactName)
239+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
228240

229241
- task: PowerShell@2
230242
name: configureWinRM
@@ -254,7 +266,7 @@ stages:
254266
displayName: 'Publish Test Results'
255267
inputs:
256268
testResultsFormat: 'NUnit'
257-
testResultsFiles: 'output/testResults/NUnit*.xml'
269+
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
258270
testRunTitle: 'Integration (Windows Server 2019)'
259271
condition: succeededOrFailed()
260272

@@ -275,13 +287,12 @@ stages:
275287
pool:
276288
vmImage: 'ubuntu 16.04'
277289
steps:
278-
- task: DownloadBuildArtifacts@0
279-
displayName: 'Download Build Artifact'
290+
- task: DownloadPipelineArtifact@2
291+
displayName: 'Download Pipeline Artifact'
280292
inputs:
281293
buildType: 'current'
282-
downloadType: 'single'
283-
artifactName: 'output'
284-
downloadPath: '$(Build.SourcesDirectory)'
294+
artifactName: $(buildArtifactName)
295+
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'
285296

286297
- task: PowerShell@2
287298
name: publishRelease

build.yaml

Lines changed: 6 additions & 2 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
####################################################
@@ -65,6 +65,8 @@ Pester:
6565
- tests/Integration
6666
ExcludeTag:
6767
Tag:
68+
CodeCoverageOutputFile: JaCoCo_coverage.xml
69+
CodeCoverageOutputFileEncoding: ascii
6870
CodeCoverageThreshold: 70
6971

7072
DscTest:
@@ -85,6 +87,8 @@ Resolve-Dependency:
8587
ModuleBuildTasks:
8688
Sampler:
8789
- '*.build.Sampler.ib.tasks'
90+
Sampler.GitHubTasks:
91+
- '*.ib.tasks'
8892
DscResource.DocGenerator:
8993
- 'Task.*'
9094

0 commit comments

Comments
 (0)