Skip to content

Commit

Permalink
[IngestionClient] Unit test coverage as part of the CI/CD pipeline (#…
Browse files Browse the repository at this point in the history
…2515)

* Adding job to upload the test coverage

* updating failing test

* adding coverlet msbuild package

* Moved coverlet to 3rd party section

* Dont run e2e tests in coverage

* Bump version

* New bicep version

* Increase version

* Using utcNow as a resourceid is non deterministic

* az bicep upgrade seems to downgrade bicep

* Install if not there, upgrade if it is

* Pull Request comments

---------

Co-authored-by: Komal Grover <[email protected]>
Co-authored-by: Yulin Li <[email protected]>
  • Loading branch information
3 people authored Jul 30, 2024
1 parent d97d53a commit c808bef
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 14 deletions.
62 changes: 58 additions & 4 deletions .github/workflows/ingestion_client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches: ['main', 'master', '*']
paths: ['samples/ingestion/ingestion-client/**', '.github/workflows/ingestion_client.yaml']
pull_request:
branches: ['main', 'master','*']
paths: ['samples/ingestion/ingestion-client/**', '.github/workflows/ingestion_client.yaml']

jobs:
convert_bicep:
Expand All @@ -18,8 +21,12 @@ jobs:
- name: Install Bicep CLI
run: |
az bicep install
az bicep upgrade
if ! command -v az bicep &> /dev/null; then
az bicep install
else
az bicep upgrade
fi
az bicep version
- name: Convert Bicep to ARM Template
run: |
Expand All @@ -31,8 +38,55 @@ jobs:
echo "Generated ARM template does not match the existing main.json. Please update main.json accordingly." >&2
exit 1
fi
build:
test:
runs-on: ubuntu-latest
needs: convert_bicep
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Install coverlet
run: dotnet tool install --global coverlet.console

- name: Install reportgenerator
run: dotnet tool install --global dotnet-reportgenerator-globaltool

- name: Run Unit Tests and Collect Coverage
run: |
dotnet test ./samples/ingestion/ingestion-client/Tests --configuration Release --filter "TestCategory=UnitTest" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
reportgenerator -reports:./samples/ingestion/ingestion-client/Tests/**/coverage.cobertura.xml -targetdir:coveragereport -reporttypes:MarkdownSummaryGithub
env:
PATH: $PATH:/home/runner/.dotnet/tools

- name: Code Coverage Summary Report
uses: irongut/[email protected]
with:
filename: ./samples/ingestion/ingestion-client/Tests/**/coverage.cobertura.xml
badge: true
format: 'markdown'
output: 'both'

# - name: Add Coverage PR Comment
# uses: marocchino/sticky-pull-request-comment@v2
# if: github.event_name == 'pull_request'
# with:
# recreate: true
# path: code-coverage-results.md

- name: Write to Job Summary
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY

- name: Upload Coverage Report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coveragereport

build:
needs: [convert_bicep, test]
runs-on: ubuntu-latest
outputs:
releaseversionoutput: ${{ steps.get_release_versions.outputs.version }}
Expand Down Expand Up @@ -133,4 +187,4 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./FetchTranscription.zip
asset_name: FetchTranscription.zip
asset_content_type: application/zip
asset_content_type: application/zip
1 change: 0 additions & 1 deletion samples/ingestion/ingestion-client/Tests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace Tests
using Moq;
using Newtonsoft.Json;

// using StartTranscriptionByTimer;
[TestClass]
public class EndToEndTests
{
Expand Down
9 changes: 9 additions & 0 deletions samples/ingestion/ingestion-client/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="$(CoverletCollector)">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="$(CoverletMsBuild)">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MSTestSdkPackageVersion)" />
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestTestAdapterPackageVersion)" />
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestTestFrameworkPackageVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

set -e

az bicep version 2>/dev/null || az bicep install
# if az bicep is not installed, install it else upgrade it
if ! command -v az bicep &> /dev/null; then
az bicep install
else
az bicep upgrade
fi

TEMPLATES=()
FILES=()
Expand Down
6 changes: 3 additions & 3 deletions samples/ingestion/ingestion-client/infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ param DeploymentId string = utcNow()
param CompletedServiceBusConnectionString string = ''

// Don't change the format for Version variable
var Version = 'v2.1.7'
var Version = 'v2.1.8'
var AudioInputContainer = 'audio-input'
var AudioProcessedContainer = 'audio-processed'
var ErrorFilesOutputContainer = 'audio-failed'
Expand All @@ -171,9 +171,9 @@ var ServiceBusName = 'ServiceBus-${InstanceId}'
var AppInsightsName = 'AppInsights-${InstanceId}'
var KeyVaultName = 'KV-${InstanceId}'
var EventGridSystemTopicName = '${StorageAccountName}-${InstanceId}'
var StartTranscriptionFunctionName = take('StartTranscriptionFunction-${InstanceId}', 60)
var StartTranscriptionFunctionName = take('StartTranscription-${InstanceId}', 60)
var StartTranscriptionFunctionId = StartTranscriptionFunction.id
var FetchTranscriptionFunctionName = take('FetchTranscriptionFunction-${InstanceId}', 60)
var FetchTranscriptionFunctionName = take('FetchTranscription-${InstanceId}', 60)
var FetchTranscriptionFunctionId = FetchTranscriptionFunction.id
var AppServicePlanName = 'AppServicePlan-${InstanceId}'
var AzureSpeechServicesKeySecretName = 'AzureSpeechServicesKey'
Expand Down
10 changes: 5 additions & 5 deletions samples/ingestion/ingestion-client/infra/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.28.1.47646",
"templateHash": "7855477000736253469"
"version": "0.29.47.4906",
"templateHash": "9541547417566949871"
}
},
"parameters": {
Expand Down Expand Up @@ -224,7 +224,7 @@
}
},
"variables": {
"Version": "v2.1.7",
"Version": "v2.1.8",
"AudioInputContainer": "audio-input",
"AudioProcessedContainer": "audio-processed",
"ErrorFilesOutputContainer": "audio-failed",
Expand All @@ -251,9 +251,9 @@
"AppInsightsName": "[format('AppInsights-{0}', variables('InstanceId'))]",
"KeyVaultName": "[format('KV-{0}', variables('InstanceId'))]",
"EventGridSystemTopicName": "[format('{0}-{1}', variables('StorageAccountName'), variables('InstanceId'))]",
"StartTranscriptionFunctionName": "[take(format('StartTranscriptionFunction-{0}', variables('InstanceId')), 60)]",
"StartTranscriptionFunctionName": "[take(format('StartTranscription-{0}', variables('InstanceId')), 60)]",
"StartTranscriptionFunctionId": "[resourceId('Microsoft.Web/sites', variables('StartTranscriptionFunctionName'))]",
"FetchTranscriptionFunctionName": "[take(format('FetchTranscriptionFunction-{0}', variables('InstanceId')), 60)]",
"FetchTranscriptionFunctionName": "[take(format('FetchTranscription-{0}', variables('InstanceId')), 60)]",
"FetchTranscriptionFunctionId": "[resourceId('Microsoft.Web/sites', variables('FetchTranscriptionFunctionName'))]",
"AppServicePlanName": "[format('AppServicePlan-{0}', variables('InstanceId'))]",
"AzureSpeechServicesKeySecretName": "AzureSpeechServicesKey",
Expand Down
4 changes: 4 additions & 0 deletions samples/ingestion/ingestion-client/versions.nugets.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<MSTestTestAdapterPackageVersion>[3.4.3]</MSTestTestAdapterPackageVersion>
<MSTestTestFrameworkPackageVersion>[3.4.3]</MSTestTestFrameworkPackageVersion>
<MSTestSdkPackageVersion>[17.10.0]</MSTestSdkPackageVersion>


<MicrosoftApplicationInsightsWorkerServicePackageVersion>[2.22.0]</MicrosoftApplicationInsightsWorkerServicePackageVersion>
<MicrosoftAzureFunctionsWorkerPackageVersion>[1.22.0]</MicrosoftAzureFunctionsWorkerPackageVersion>
Expand All @@ -24,5 +26,7 @@
<MoqPackageVersion>[4.20.70]</MoqPackageVersion>
<NewtonsoftJsonPackageVersion>[13.0.3]</NewtonsoftJsonPackageVersion>
<PollyPackageVersion>[8.4.1]</PollyPackageVersion>
<CoverletCollector>[6.0.2]</CoverletCollector>
<CoverletMsBuild>[6.0.2]</CoverletMsBuild>
</PropertyGroup>
</Project>

0 comments on commit c808bef

Please sign in to comment.