chore: Addition of Deployment and test pipeline #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Unit Tests - DKM | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
types: | |
- opened | |
- ready_for_review | |
- reopened | |
- synchronize | |
jobs: | |
backend_api_tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Install dependencies | |
run: | | |
if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then | |
dotnet restore App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj | |
else | |
echo "No test project found for Backend API. Skipping tests." | |
exit 0 | |
fi | |
- name: Build Test Project | |
run: | | |
if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then | |
dotnet build App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj --no-restore | |
fi | |
- name: Run tests with coverage | |
run: | | |
if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then | |
dotnet test App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj \ | |
--collect:"XPlat Code Coverage" \ | |
--logger "trx;LogFileName=test_results.trx" \ | |
--results-directory "./TestResults" \ | |
/p:CollectCoverage=true \ | |
/p:CoverletOutputFormat=cobertura \ | |
/p:CoverletOutput=./TestResults/coverage.cobertura.xml | |
fi | |
- name: Generate Coverage Report | |
run: | | |
dotnet tool install -g dotnet-reportgenerator-globaltool | |
if [ -f "App/backend-api/Microsoft.GS.DPS.Tests/Microsoft.GS.DPS.Tests.csproj" ]; then | |
reportgenerator \ | |
-reports:./TestResults/**/coverage.cobertura.xml \ | |
-targetdir:./coverage-report \ | |
-reporttypes:TextSummary | |
fi | |
- name: Display Coverage | |
run: | | |
if [ -f "./coverage-report/Summary.txt" ]; then | |
echo "Code Coverage Summary:" | |
cat ./coverage-report/Summary.txt | |
else | |
echo "No coverage summary available." | |
fi | |
- name: Upload Coverage Report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: backend-api-coverage | |
path: ./coverage-report | |
semantic_kernel_tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Install dependencies | |
run: | | |
if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then | |
dotnet restore App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj | |
else | |
echo "No test project found for Semantic Kernel. Skipping tests." | |
exit 0 | |
fi | |
- name: Build Test Project | |
run: | | |
if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then | |
dotnet build App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj --no-restore | |
fi | |
- name: Run tests with coverage | |
run: | | |
if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then | |
dotnet test App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj \ | |
--collect:"XPlat Code Coverage" \ | |
--logger "trx;LogFileName=test_results.trx" \ | |
--results-directory "./TestResults" \ | |
/p:CollectCoverage=true \ | |
/p:CoverletOutputFormat=cobertura \ | |
/p:CoverletOutput=./TestResults/coverage.cobertura.xml | |
fi | |
- name: Install Report Generator | |
run: dotnet tool install -g dotnet-reportgenerator-globaltool | |
- name: Generate Coverage Report | |
run: | | |
if [ -f "App/semantic-kernel/Microsoft.GS.SK.Tests/Microsoft.GS.SK.Tests.csproj" ]; then | |
reportgenerator \ | |
-reports:./TestResults/**/coverage.cobertura.xml \ | |
-targetdir:./coverage-report \ | |
-reporttypes:TextSummary | |
else | |
echo "No coverage report generated. Skipping report generation." | |
fi | |
- name: Display Coverage | |
run: | | |
if [ -f "./coverage-report/Summary.txt" ]; then | |
echo "Code Coverage Summary:" | |
cat ./coverage-report/Summary.txt | |
else | |
echo "No coverage summary available." | |
fi | |
- name: Upload Coverage Report | |
uses: actions/upload-artifact@v3 | |
with: | |
name: semantic-kernel-coverage | |
path: ./coverage-report | |
frontend_tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- name: Install dependencies | |
working-directory: ./App/frontend-app | |
run: | | |
npm install --legacy-peer-deps || echo "Warning: Dependency installation failed. Proceeding." | |
- name: Run tests for Frontend App with coverage | |
working-directory: ./App/frontend-app | |
run: | | |
if find src -type f \( -name "*.test.tsx" -o -name "*.spec.tsx" -o -name "*.test.ts" -o -name "*.spec.ts" \) | grep -q .; then | |
echo "Test files found. Proceeding with tests." | |
npx jest --coverage --coverageDirectory=coverage --detectOpenHandles | |
else | |
echo "No test files found in Frontend App. Skipping tests." | |
fi |