Skip to content

Add TDD/spec-driven workflow, code coverage enforcement, and session … #15

Add TDD/spec-driven workflow, code coverage enforcement, and session …

Add TDD/spec-driven workflow, code coverage enforcement, and session … #15

Workflow file for this run

name: CI
on:
push:
branches: [main]
tags: ['[0-9]*.[0-9]*.[0-9]*']
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Test with coverage
run: >
dotnet test --no-build --configuration Release --verbosity normal
--collect:"XPlat Code Coverage"
--results-directory ./coverage
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura
- name: Check coverage threshold
run: |
# Find the coverage file
COVERAGE_FILE=$(find ./coverage -name 'coverage.cobertura.xml' | head -1)
if [ -z "$COVERAGE_FILE" ]; then
echo "::error::No coverage file found"
exit 1
fi
# Extract line coverage rate
LINE_RATE=$(grep -oP 'line-rate="\K[^"]+' "$COVERAGE_FILE" | head -1)
PERCENTAGE=$(echo "$LINE_RATE * 100" | bc -l | xargs printf "%.1f")
echo "Line coverage: ${PERCENTAGE}%"
# Fail if below 100%
PASS=$(echo "$LINE_RATE >= 1.0" | bc -l)
if [ "$PASS" -ne 1 ]; then
echo "::error::Code coverage is ${PERCENTAGE}%, required 100%"
exit 1
fi
- name: Pack
run: dotnet pack PanoramicData.Render/PanoramicData.Render.csproj --no-build --configuration Release --output ./artifacts
- name: Upload NuGet artifact
uses: actions/upload-artifact@v4
with:
name: nuget
path: |
./artifacts/*.nupkg
./artifacts/*.snupkg
publish:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: nuget
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: NuGet Login (Trusted Publishing)
uses: NuGet/login@v1
id: login
with:
user: david_n_m_bond
- name: Push to NuGet
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate