Skip to content

Commented out broken step to test without it. #9

Commented out broken step to test without it.

Commented out broken step to test without it. #9

name: Build and test API on push or PR
#asdf
#controls when the workflow is triggered. Works on push or pull request to main branch
on:
push:
branches:
- main
pull_request:
branches:
- main
# specify the permissions for the workflow
permissions:
contents: read #needed to read the repository content
checks: write #needed to post check run results
pull-requests: write #needed to post PR comments for test results
# workflow is made of one or more jobs that can be run sequentially or in parallel
jobs:
run-tests:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.x"
- name: Restore dependencies
run: dotnet restore
- name: Run tests with coverage
run: |
mkdir -p test-results
dotnet test --logger "trx;LogFileName=test-results.trx" --results-directory test-results --collect:"XPlat Code Coverage"
continue-on-error: true
- name: Display code coverage summary
run: |
echo "Code Coverage Results:"
find test-results -name "coverage.cobertura.xml" -exec echo "Coverage file: {}" \;
# Install reportgenerator tool to create summary
dotnet tool install -g dotnet-reportgenerator-globaltool
if [ -f test-results/*/coverage.cobertura.xml ]; then
reportgenerator -reports:test-results/*/coverage.cobertura.xml -targetdir:test-results/coverage-report -reporttypes:TextSummary
cat test-results/coverage-report/Summary.txt
else
echo "No coverage files found"
fi
- name: Debug - List test results directory
run: |
echo "Contents of test-results directory:"
ls -la test-results/ || echo "test-results directory not found"
echo "Looking for .trx files:"
find test-results -name "*.trx" -type f || echo "No .trx files found"
echo "Looking for coverage files:"
find test-results -name "coverage.cobertura.xml" -type f || echo "No coverage files found"
echo "Full directory structure of test-results:"
find test-results -type f || echo "test-results directory is empty"
- name: Publish Test Results
uses: dorny/test-reporter@v1
if: always()
with:
name: .NET Tests
path: test-results/*.trx
reporter: dotnet-trx
# - name: Code Coverage Report
# uses: irongut/CodeCoverageSummary@v1.3.0
# if: always()
# with:
# filename: "test-results/**/coverage.cobertura.xml"
# badge: true
# fail_below_min: false
# format: markdown
# hide_branch_rate: false
# hide_complexity: true
# indicators: true
# output: both
# thresholds: "60 80"
- 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: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
files: test-results/*/coverage.cobertura.xml
fail_ci_if_error: true