Skip to content

Commit

Permalink
Add support for code coverage reporting in pipeline - Fixes #130 (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueHO authored Apr 21, 2021
1 parent dc0e72d commit fc7d5d1
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 68 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Automatically publish documentation to GitHub Wiki - Fixes [Issue #122](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/122).
- Renamed `master` branch to `main` - Fixes [Issue #124](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/124).
- Updated `GitVersion.yml` to latest pattern - Fixes [Issue #126](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/126).
- Updated build to use `Sampler.GitHubTasks` - Fixes [Issue #129](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/129).
- Added support for publishing code coverage to `CodeCov.io` and
Azure Pipelines - Fixes [Issue #130](https://github.com/dsccommunity/ActiveDirectoryCSDsc/issues/130).

## [5.0.0] - 2020-06-20

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![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)
[![PowerShell Gallery (with prereleases)](https://img.shields.io/powershellgallery/vpre/ActiveDirectoryCSDsc?label=ActiveDirectoryCSDsc%20Preview)](https://www.powershellgallery.com/packages/ActiveDirectoryCSDsc/)
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/ActiveDirectoryCSDsc?label=ActiveDirectoryCSDsc)](https://www.powershellgallery.com/packages/ActiveDirectoryCSDsc/)
[![codecov](https://codecov.io/gh/dsccommunity/ActiveDirectoryCSDsc/branch/main/graph/badge.svg)](https://codecov.io/gh/dsccommunity/ActiveDirectoryCSDsc)

## Code of Conduct

Expand Down
1 change: 1 addition & 0 deletions RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Sampler = 'latest'
'Sampler.GitHubTasks' = 'latest'
MarkdownLinkCheck = 'latest'
'DscResource.Test' = 'latest'
'DscResource.AnalyzerRules' = 'latest'
Expand Down
143 changes: 77 additions & 66 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ trigger:
exclude:
- "*-*"

variables:
buildFolderName: output
buildArtifactName: output
testResultFolderName: testResults
testArtifactName: testResults
sourceFolderName: source

stages:
- stage: Build
jobs:
Expand All @@ -36,12 +43,13 @@ stages:
env:
ModuleVersion: $(gitVersion.Informationalversion)

- task: PublishBuildArtifacts@1
displayName: 'Publish Build Artifact'
- task: PublishPipelineArtifact@1
displayName: 'Publish Pipeline Artifact'
inputs:
PathtoPublish: 'output/'
ArtifactName: 'output'
publishLocation: 'Container'
targetPath: '$(buildFolderName)/'
artifact: $(buildArtifactName)
publishLocation: 'pipeline'
parallel: true

- stage: Test
dependsOn: Build
Expand All @@ -52,13 +60,12 @@ stages:
vmImage: 'windows-2019'
timeoutInMinutes: 0
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifact'
- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'
artifactName: $(buildArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'

- task: PowerShell@2
name: test
Expand All @@ -72,7 +79,7 @@ stages:
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'output/testResults/NUnit*.xml'
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
testRunTitle: 'HQRM'
condition: succeededOrFailed()

Expand All @@ -82,20 +89,12 @@ stages:
vmImage: 'vs2017-win2016'
timeoutInMinutes: 0
steps:
- powershell: |
$repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/'
echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner"
echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName"
name: dscBuildVariable
displayName: 'Set Environment Variables'
- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifact'
- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'
artifactName: $(buildArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'

- task: PowerShell@2
name: test
Expand All @@ -109,31 +108,61 @@ stages:
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'output/testResults/NUnit*.xml'
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
testRunTitle: 'Unit (Windows Server 2016)'
condition: succeededOrFailed()

- task: PublishPipelineArtifact@1
displayName: 'Publish Test Artifact'
inputs:
targetPath: '$(buildFolderName)/$(testResultFolderName)/'
artifactName: $(testArtifactName)
parallel: true

- job: Code_Coverage
displayName: 'Publish Code Coverage'
dependsOn: Test_Unit_2016
pool:
vmImage: 'ubuntu 16.04'
timeoutInMinutes: 0
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
artifactName: $(buildArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'

- task: DownloadPipelineArtifact@2
displayName: 'Download Test Artifact'
inputs:
buildType: 'current'
artifactName: $(testArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildFolderName)/$(testResultFolderName)'

- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage'
condition: succeededOrFailed()
displayName: 'Publish Code Coverage to Azure DevOps'
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: 'output/testResults/CodeCov*.xml'
pathToSources: '$(Build.SourcesDirectory)/output/$(DscBuildVariable.RepositoryName)'
summaryFileLocation: '$(Build.SourcesDirectory)/$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml'
pathToSources: '$(Build.SourcesDirectory)/$(sourceFolderName)/'

- script: |
bash <(curl -s https://codecov.io/bash) -f "./$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml"
displayName: 'Publish Code Coverage to Codecov.io'
- job: Test_Integration_2016
displayName: 'Integration (Windows Server 2016)'
pool:
vmImage: 'vs2017-win2016'
timeoutInMinutes: 0
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifact'
- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'
artifactName: $(buildArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'

- task: PowerShell@2
name: configureWinRM
Expand Down Expand Up @@ -163,7 +192,7 @@ stages:
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'output/testResults/NUnit*.xml'
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
testRunTitle: 'Integration (Windows Server 2016)'
condition: succeededOrFailed()

Expand All @@ -173,20 +202,12 @@ stages:
vmImage: 'windows-2019'
timeoutInMinutes: 0
steps:
- powershell: |
$repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/'
echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner"
echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName"
name: dscBuildVariable
displayName: 'Set Environment Variables'
- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifact'
- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'
artifactName: $(buildArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'

- task: PowerShell@2
name: test
Expand All @@ -200,31 +221,22 @@ stages:
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'output/testResults/NUnit*.xml'
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
testRunTitle: 'Unit (Windows Server 2019)'
condition: succeededOrFailed()

- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage'
condition: succeededOrFailed()
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: 'output/testResults/CodeCov*.xml'
pathToSources: '$(Build.SourcesDirectory)/output/$(dscBuildVariable.RepositoryName)'

- job: Test_Integration_2019
displayName: 'Integration (Windows Server 2019)'
pool:
vmImage: 'windows-2019'
timeoutInMinutes: 0
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifact'
- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'
artifactName: $(buildArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'

- task: PowerShell@2
name: configureWinRM
Expand Down Expand Up @@ -254,7 +266,7 @@ stages:
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'output/testResults/NUnit*.xml'
testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml'
testRunTitle: 'Integration (Windows Server 2019)'
condition: succeededOrFailed()

Expand All @@ -275,13 +287,12 @@ stages:
pool:
vmImage: 'ubuntu 16.04'
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download Build Artifact'
- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'
artifactName: $(buildArtifactName)
targetPath: '$(Build.SourcesDirectory)/$(buildArtifactName)'

- task: PowerShell@2
name: publishRelease
Expand Down
8 changes: 6 additions & 2 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ BuildWorkflow:
- Pester_If_Code_Coverage_Under_Threshold

publish:
- Publish_Release_to_GitHub
- Publish_Module_to_gallery
- Publish_Release_To_GitHub
- Publish_Module_To_gallery
- Publish_GitHub_Wiki_Content

####################################################
Expand All @@ -65,6 +65,8 @@ Pester:
- tests/Integration
ExcludeTag:
Tag:
CodeCoverageOutputFile: JaCoCo_coverage.xml
CodeCoverageOutputFileEncoding: ascii
CodeCoverageThreshold: 70

DscTest:
Expand All @@ -85,6 +87,8 @@ Resolve-Dependency:
ModuleBuildTasks:
Sampler:
- '*.build.Sampler.ib.tasks'
Sampler.GitHubTasks:
- '*.ib.tasks'
DscResource.DocGenerator:
- 'Task.*'

Expand Down

0 comments on commit fc7d5d1

Please sign in to comment.