From 076ab61ad710cb21d708ca56b9565d7251fca130 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 24 Apr 2021 19:50:31 +1200 Subject: [PATCH] Add code coverage support in pipeline - Fixes #61 (#62) --- CHANGELOG.md | 3 + README.md | 1 + RequiredModules.psd1 | 1 + azure-pipelines.yml | 143 +++++++++++++++++++++++-------------------- build.yaml | 4 ++ codecov.yml | 28 +++++++++ 6 files changed, 114 insertions(+), 66 deletions(-) create mode 100644 codecov.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cc876f..74e9cf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Automatically publish documentation to GitHub Wiki - Fixes [Issue #51](https://github.com/dsccommunity/FileContentDsc/issues/51). - Renamed `master` branch to `main` - Fixes [Issue #53](https://github.com/dsccommunity/FileContentDsc/issues/53). - Updated `GitVersion.yml` to latest pattern - Fixes [Issue #57](https://github.com/dsccommunity/FileContentDsc/issues/57). +- Updated build to use `Sampler.GitHubTasks` - Fixes [Issue #60](https://github.com/dsccommunity/FileContentDsc/issues/60). +- Added support for publishing code coverage to `CodeCov.io` and + Azure Pipelines - Fixes [Issue #61](https://github.com/dsccommunity/FileContentDsc/issues/61). ## [1.3.0.151] - 2019-07-20 diff --git a/README.md b/README.md index d278016..5fa522d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![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) [![PowerShell Gallery (with prereleases)](https://img.shields.io/powershellgallery/vpre/FileContentDsc?label=FileContentDsc%20Preview)](https://www.powershellgallery.com/packages/FileContentDsc/) [![PowerShell Gallery](https://img.shields.io/powershellgallery/v/FileContentDsc?label=FileContentDsc)](https://www.powershellgallery.com/packages/FileContentDsc/) +[![codecov](https://codecov.io/gh/dsccommunity/FileContentDsc/branch/main/graph/badge.svg)](https://codecov.io/gh/dsccommunity/FileContentDsc) ## Code of Conduct diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index f8abe7f..6e1bb95 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -14,6 +14,7 @@ ModuleBuilder = 'latest' ChangelogManagement = 'latest' Sampler = 'latest' + 'Sampler.GitHubTasks' = 'latest' MarkdownLinkCheck = 'latest' 'DscResource.Test' = 'latest' 'DscResource.AnalyzerRules' = 'latest' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1926a09..fc0231e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -11,6 +11,13 @@ trigger: exclude: - "*-*" +variables: + buildFolderName: output + buildArtifactName: output + testResultFolderName: testResults + testArtifactName: testResults + sourceFolderName: source + stages: - stage: Build jobs: @@ -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 @@ -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 @@ -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() @@ -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 @@ -109,17 +108,48 @@ 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)' @@ -127,13 +157,12 @@ stages: 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 @@ -155,7 +184,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() @@ -165,20 +194,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 @@ -192,31 +213,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 @@ -238,7 +250,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() @@ -259,13 +271,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 diff --git a/build.yaml b/build.yaml index 445351f..b995d54 100644 --- a/build.yaml +++ b/build.yaml @@ -64,6 +64,8 @@ Pester: - tests/Unit ExcludeTag: Tag: + CodeCoverageOutputFile: JaCoCo_coverage.xml + CodeCoverageOutputFileEncoding: ascii CodeCoverageThreshold: 70 DscTest: @@ -84,6 +86,8 @@ Resolve-Dependency: ModuleBuildTasks: Sampler: - '*.build.Sampler.ib.tasks' + Sampler.GitHubTasks: + - '*.ib.tasks' DscResource.DocGenerator: - 'Task.*' diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..bff75ea --- /dev/null +++ b/codecov.yml @@ -0,0 +1,28 @@ +codecov: + require_ci_to_pass: no + # main should be the baseline for reporting + branch: main + +comment: + layout: "reach, diff, flags, files" + behavior: default + +coverage: + range: 50..80 + round: down + precision: 0 + + status: + project: + default: + # Set the overall project code coverage requirement to 70% + target: 70 + patch: + default: + # Set the pull request requirement to not regress overall coverage by more than 5% + # and let codecov.io set the goal for the code changed in the patch. + target: auto + threshold: 5 + +fixes: + - '^\d+\.\d+\.\d+::source' # move path "X.Y.Z" => "source"