Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: publish code coverage #170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
fcc2f6b
chore: publish code coverage
stijnmoreels Jul 26, 2024
3f8dc62
pr-fix: ci trigger
stijnmoreels Jul 26, 2024
d90213c
pr-fix: collect code coverage
stijnmoreels Jul 26, 2024
dd7cb65
pr-fix: coverlage update
stijnmoreels Jul 26, 2024
1c72ec5
pr-fix: project var name
stijnmoreels Jul 26, 2024
0493cb9
pr-fix: add coverage to integration test project
stijnmoreels Jul 26, 2024
c11dbdf
pr-fix: use az devops code coverge
stijnmoreels Jul 26, 2024
dae0549
pr-fix: add coverage settings to integration test project
stijnmoreels Jul 26, 2024
487a5c9
pr-fix: check integrtion test coverage
stijnmoreels Jul 26, 2024
b1b699f
pr-fix: single publish coverage result
stijnmoreels Jul 26, 2024
99763f5
pr-fix: use single test stage
stijnmoreels Jul 26, 2024
c783468
pr-fix: adds depends on
stijnmoreels Jul 26, 2024
2b38b41
pr-fix: publish artifacts directly
stijnmoreels Jul 26, 2024
586fe7b
pr-fix: publish artifacts directly
stijnmoreels Jul 26, 2024
aa45a08
pr-fix: publish artifacts directly
stijnmoreels Jul 26, 2024
04130fb
pr-fix: publish artifacts directly
stijnmoreels Jul 26, 2024
0e93f4a
pr-fix: publish artifacts directly
stijnmoreels Jul 26, 2024
f286876
pr-fix: single test job
stijnmoreels Jul 26, 2024
b0eee3e
pr-fix: single test job
stijnmoreels Jul 26, 2024
fe7fbda
pr-fix: remove msbuild from csproj
stijnmoreels Jul 26, 2024
38aef37
pr-fix: force result directory
stijnmoreels Jul 26, 2024
b3010d1
pr-fix: force result directory
stijnmoreels Jul 26, 2024
0aa25d6
pr-fix: explicitly publish results
stijnmoreels Jul 26, 2024
ff0cbcf
pr-fix: Cobertura type
stijnmoreels Jul 26, 2024
7ec7851
Update publish-coverage.yml
stijnmoreels Jul 27, 2024
6c88c97
pr-fix: add gh comment
stijnmoreels Jul 27, 2024
d01b73c
pr-fix: add summary report
stijnmoreels Jul 27, 2024
7a9c5c4
pr-fix: secrets
stijnmoreels Jul 27, 2024
7564b53
pr-fix: pr number
stijnmoreels Jul 27, 2024
9e2476f
pr-fix: pr number
stijnmoreels Jul 27, 2024
2c9563c
pr-fix: pr number
stijnmoreels Jul 27, 2024
e97bb07
pr-fix: publish code coverage in gh workflow
stijnmoreels Jul 29, 2024
a25c156
pr-fix: correct gh action
stijnmoreels Jul 29, 2024
089ce55
pr-fix: publish on pr
stijnmoreels Jul 29, 2024
adc70d3
pr-fix: correct path
stijnmoreels Jul 29, 2024
445fa47
pr-fix: use gh cli
stijnmoreels Jul 29, 2024
2ca6a95
pr-fix: install other way
stijnmoreels Jul 29, 2024
186517c
pr-fix: remove useless test
stijnmoreels Jul 29, 2024
27d34df
pr-fix: use pr number
stijnmoreels Jul 29, 2024
f2ca016
pr-fix: upsert comment
stijnmoreels Jul 29, 2024
f64f7b7
pr-fix: change summary
stijnmoreels Jul 29, 2024
9d22961
pr-fix: use gh summary
stijnmoreels Jul 31, 2024
6065c1d
pr-fix: separate jobs
stijnmoreels Aug 1, 2024
5e36e0c
pr-fix: use wildards
stijnmoreels Aug 1, 2024
03ebfd2
pr-fix: use own test
stijnmoreels Aug 1, 2024
6e68888
pr-fix: use correct artifacts
stijnmoreels Aug 1, 2024
e0d1a3f
pr-fix: use correct var name
stijnmoreels Aug 1, 2024
a811ea0
pr-fix: correct multi-line
stijnmoreels Aug 1, 2024
6f6fa61
pr-fix: correct coverage path
stijnmoreels Aug 1, 2024
3daad7d
pr-ifix: correct multi-line
stijnmoreels Aug 1, 2024
6176860
pr-fix: correct format
stijnmoreels Aug 1, 2024
7a3cce6
pr-fix: sinlge line
stijnmoreels Aug 1, 2024
c8cdcd9
pr-fix: w/o no-build
stijnmoreels Aug 1, 2024
54cce00
pr-fix: publish to gh
stijnmoreels Aug 1, 2024
baed18f
pr-fix: update comment
stijnmoreels Aug 1, 2024
cd67a83
pr-fix: motivational message
stijnmoreels Aug 1, 2024
4bdcb6c
pr-fix: correct syntax error
stijnmoreels Aug 1, 2024
658dd22
pr-fix: improve coverage
stijnmoreels Aug 1, 2024
c81e53a
pr-fix: error multi-line
stijnmoreels Aug 1, 2024
eea37da
pr-fix: more coverage + flexibe retrieval
stijnmoreels Aug 1, 2024
e36283c
pr-fix: write host
stijnmoreels Aug 1, 2024
e963ff3
pr-fix: correct pattern
stijnmoreels Aug 1, 2024
70230dd
pr-fix: update with more coverage
stijnmoreels Aug 1, 2024
8668cfb
pr-fix: improve branch coverage
stijnmoreels Aug 1, 2024
90e2bd0
pr-fix: improve coverage
stijnmoreels Aug 1, 2024
1f2582f
pr-fix: improve coverage
stijnmoreels Aug 1, 2024
7156226
pr-fix: correct tests
stijnmoreels Aug 1, 2024
9e1a4e8
pr-fix: resuse min coverage level
stijnmoreels Aug 1, 2024
f55672e
Merge branch 'main' into chore/publish-code-coverage
stijnmoreels Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .github/workflows/code-coverage.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Arcus - Testing
[![Build Status](https://dev.azure.com/codit/Arcus/_apis/build/status/Commit%20builds/CI%20-%20Arcus.Testing?branchName=main)](https://dev.azure.com/codit/Arcus/_build/latest?definitionId=804&branchName=main)
[![NuGet Badge](https://buildstats.info/nuget/Arcus.Testing.Logging.Xunit?includePreReleases=true)](https://www.nuget.org/packages/Arcus.Testing.Logging/)
[![codecov](https://codecov.io/gh/arcus-azure/arcus.testing/graph/badge.svg?token=GIXXJO815Q)](https://codecov.io/gh/arcus-azure/arcus.testing)
![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/codit/Arcus/804)

Reusable testing components for Arcus repo's.

Expand Down
18 changes: 5 additions & 13 deletions build/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pr:
paths:
include:
- src/*
- build/ci-build.yml
- build/*

parameters:
- name: 'Package.Version.ManualTrigger'
Expand All @@ -31,7 +31,7 @@ resources:
endpoint: arcus-azure

variables:
- group: 'Arcus - GitHub Package Registry'
- group: 'GitHub Configuration'
- group: 'Build Configuration'
- template: ./variables/build.yml

Expand Down Expand Up @@ -66,27 +66,19 @@ stages:
targetPath: '$(Pipeline.Workspace)/build'
artifactName: Build

- stage: UnitTests
displayName: Unit Tests
- stage: Tests
dependsOn: Build
condition: succeeded()
jobs:
- template: templates/unit-tests.yml

- stage: IntegrationTests
displayName: Integration Tests
dependsOn: Build
condition: succeeded()
jobs:
- template: templates/integration-tests.yml
parameters:
azureServiceConnection: '${{ parameters.azureServiceConnection }}'
- template: templates/publish-coverage.yml

- stage: ReleaseToMyget
displayName: 'Release to MyGet'
dependsOn:
- UnitTests
- IntegrationTests
dependsOn: Tests
condition: succeeded()
jobs:
- job: PushToMyGet
Expand Down
38 changes: 33 additions & 5 deletions build/templates/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,36 @@ jobs:
Set-AzDevOpsVariable -Name 'Arcus.Testing.ServicePrincipal.ClientId' -Value $env:servicePrincipalId
Set-AzDevOpsVariable -Name 'Arcus.Testing.ServicePrincipal.ClientSecret' -Value $env:servicePrincipalKey

- template: test/run-integration-tests.yml@templates
parameters:
dotnetSdkVersion: '$(DotNet.Sdk.Version)'
projectName: '$(Project).Tests.Integration'
includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions)
- task: UseDotNet@2
displayName: 'Import .NET Core SDK ($(DotNet.Sdk.Version))'
inputs:
packageType: 'sdk'
version: '$(DotNet.Sdk.Version)'
includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions)

- task: qetza.replacetokens.replacetokens-task.replacetokens@6
displayName: 'Replace integration test tokens'
inputs:
root: 'src/$(Project).Tests.Integration/'
sources: 'appsettings.json'
missingVarLog: 'error'
logLevel: 'debug'
addBOM: true
tokenPrefix: '#{'
tokenSuffix: '}#'

- script: |
dotnet test src/**/$(Project).Tests.Integration.csproj --configuration $(Build.Configuration) --collect:"XPlat Code Coverage" --logger trx --results-directory $(Pipeline.Workspace)
displayName: 'Run integration tests'

- task: PublishTestResults@2
displayName: 'Publish integration test results'
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '$(Pipeline.Workspace)/*.trx'

- task: PublishPipelineArtifact@0
displayName: 'Publish code coverage artifacts'
inputs:
targetPath: '$(Pipeline.Workspace)'
artifactName: Coverage-Integration
98 changes: 98 additions & 0 deletions build/templates/publish-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
jobs:
- job: PublishCoverage
displayName: 'Publish code coverage'
pool:
vmImage: '$(Vm.Image)'
dependsOn:
- UnitTests
- IntegrationTests
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download coverage unit artifacts'
inputs:
artifact: 'Coverage-Unit'
path: '$(Build.SourcesDirectory)/TestResults'

- task: DownloadPipelineArtifact@2
displayName: 'Download coverage integration artifacts'
inputs:
artifact: 'Coverage-Integration'
path: '$(Build.SourcesDirectory)/TestResults'

- task: reportgenerator@5
displayName: 'Generate code coverage report'
inputs:
reports: '$(Build.SourcesDirectory)/TestResults/**/coverage.cobertura.xml'
targetdir: coveragereport
reporttypes: Html;HtmlInline_AzurePipelines_Dark;Cobertura;MarkdownSummaryGithub
publishCodeCoverageResults: true

- script: sudo apt install gh
displayName: 'Install GitHub CLI'

- powershell: |
gh auth login --with-token $(GITHUB_TOKEN)
gh repo view

$summary = Get-Content -Path './coveragereport/SummaryGithub.md' -Raw
Write-Host "Summary: $summary"

$lineCoveragePattern = "\*\*Line coverage:\*\*\s*\|\s*(\d+(\.\d+)?%)"
$branchCoveragePattern = "\*\*Branch coverage:\*\*\s*\|\s*(\d+(\.\d+)?%)"

$lineCoverage = "N/A"
if ($summary -match $lineCoveragePattern) {
$lineCoverage = $matches[1]
Write-Host "Line coverage: $lineCoverage"
} else {
Write-Host "Line coverage not found"
}

$branchCoverage = "N/A"
if ($summary -match $branchCoveragePattern) {
$branchCoverage = $matches[1]
Write-Host "Branch coverage: $branchCoverage"
} else {
Write-Host "Branch coverage not found"
}

$lineCoverageValue = [double]($lineCoverage -replace '%', '')
$branchCoverageValue = [double]($branchCoverage -replace '%', '')
$buildId = $env:BUILD_BUILDID
$reportUrl = "https://dev.azure.com/codit/Arcus/_build/results?buildId=$buildId&view=codecoverage-tab"

$minCoverage = 80
if ($lineCoverageValue -ge $minCoverage -and $branchCoverage -ge $minCoverage) {
$motivationalMessage = "Great job! 😎 Your code coverage is higher than my caffeine levels! ☕"
} else {
$motivationalMessage = @"
😟 Your code coverage is not fully reaching **$minCoverage %** yet.
Please inspect [the report]($reportUrl) to find possible improvements and before you know it, your code coverage will reach the stars! 🚀
"@
}

if ($lineCoverageValue -ge $minCoverage) { $lineCoverageBadge = "🟢" } else { $lineCoverageBadge = "🔴" }
if ($branchCoverageValue -ge $minCoverage) { $branchCoverageBadge = "🟢" } else { $branchCoverageBadge = "🔴" }

$comments = gh pr view $env:PR_NUMBER --json comments --jq '.comments[].body'
$commentExists = $comments | Where-Object { $_ -like "*Code coverage*" -and $_ -like "*summary*" }

$content = @"
## 🧪 [Code coverage]($reportUrl) summary
| Metric | Value |
| ------ | ----- |
| Line coverage | $lineCoverageBadge **$lineCoverage** |
| Branch coverage | $branchCoverageBadge **$branchCoverage** |

$motivationalMessage
"@

if ($commentExists) {
gh pr comment $env:PR_NUMBER --body $content --edit-last
} else {
gh pr comment $env:PR_NUMBER --body $content
}
env:
GITHUB_TOKEN: $(GITHUB_TOKEN)
PR_NUMBER: $(System.PullRequest.PullRequestNumber)
displayName: 'Publish code coverage summary on GitHub'
27 changes: 22 additions & 5 deletions build/templates/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,25 @@ jobs:
packageType: 'sdk'
version: '$(DotNet.Sdk.VersionBC)'

- template: test/run-unit-tests.yml@templates
parameters:
dotnetSdkVersion: '$(DotNet.Sdk.Version)'
projectName: '$(Project).Tests.Unit'
includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions)
- task: UseDotNet@2
displayName: 'Import .NET Core SDK ($(DotNet.Sdk.Version))'
inputs:
packageType: 'sdk'
version: '$(DotNet.Sdk.Version)'
includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions)

- script: |
dotnet test src/**/$(Project).Tests.Unit.csproj --configuration $(Build.Configuration) --collect:"XPlat Code Coverage" --logger trx --results-directory $(Pipeline.Workspace)
displayName: 'Run unit tests'

- task: PublishTestResults@2
displayName: 'Publish unit test results'
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '$(Pipeline.Workspace)/*.trx'

- task: PublishPipelineArtifact@0
displayName: 'Publish code coverage artifacts'
inputs:
targetPath: '$(Pipeline.Workspace)'
artifactName: Coverage-Unit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -7,6 +7,10 @@

<ItemGroup>
<PackageReference Include="Bogus" Version="29.0.2" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Guard.Net" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" />
Expand Down
27 changes: 0 additions & 27 deletions src/Arcus.Testing.Tests.Integration/DemoIntegrationTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FsCheck.Xunit" Version="2.16.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
Expand Down
Loading
Loading