Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
164 changes: 147 additions & 17 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,164 @@
# This workflow will build a .NET project
# This workflow builds, tests, and validates the .NET Test Framework Boilerplate
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Build
name: Build & Test

on:
push:
branches: ["main"]
branches: ["main", "develop"]
pull_request:
branches: ["main"]
branches: ["main", "develop"]
workflow_dispatch: # Allow manual trigger

permissions:
contents: read
checks: write
pull-requests: write

jobs:
build:
build-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
dotnet-version: ['8.0.x']
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better analysis

- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}

- name: Display .NET version
run: dotnet --version

- name: Restore dependencies
run: dotnet restore

- name: Build solution
run: dotnet build --no-restore --configuration Release

- name: Run tests with coverage
run: dotnet test --no-build --configuration Release --verbosity normal --logger "trx;LogFileName=test-results.trx" --collect:"XPlat Code Coverage" --results-directory ./TestResults

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.os }}-${{ matrix.dotnet-version }}
path: TestResults/**/*.trx
retention-days: 30

- name: Upload code coverage
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: TestResults/**/coverage.cobertura.xml
retention-days: 30

- name: Run SpecFlow Tests & Generate Living Documentation
if: matrix.os == 'ubuntu-latest'
uses: cryptic-wizard/run-specflow-tests@v1.3.3
with:
test-assembly-dll: TestFrameworkBoilerplate.Tests.Integration/bin/Release/net8.0/TestFrameworkBoilerplate.Tests.Integration.dll
test-execution-json: TestFrameworkBoilerplate.Tests.Integration/bin/Release/net8.0/TestExecution.json
output-html: LivingDocumentation.html
framework: net8.0
configuration: 'Release'

- name: Upload Living Documentation
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: living-documentation
path: LivingDocumentation.html
retention-days: 90

- name: Publish Test Report
if: always() && matrix.os == 'ubuntu-latest'
continue-on-error: true # Don't fail workflow if check run creation fails
uses: dorny/test-reporter@v1
with:
name: Test Results (Ubuntu)
path: TestResults/**/*.trx
reporter: dotnet-trx
fail-on-error: true

code-quality:
runs-on: ubuntu-latest
needs: build-and-test

steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Run SpecFlow Tests
uses: cryptic-wizard/run-specflow-tests@v1.3.3

- name: Run code analysis
run: dotnet build --no-restore --configuration Release /p:TreatWarningsAsErrors=false

- name: Check for security vulnerabilities
run: |
dotnet list package --vulnerable --include-transitive 2>&1 | tee vulnerabilities.txt
if grep -q "has the following vulnerable packages" vulnerabilities.txt; then
echo "::warning::Security vulnerabilities detected. Review vulnerabilities.txt"
fi

template-pack:
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup NuGet
uses: nuget/setup-nuget@v2
with:
nuget-version: 'latest'

- name: Pack template as NuGet package
run: nuget pack TestFrameworkBoilerplate.Template.nuspec -Version 1.0.${{ github.run_number }} -OutputDirectory ./artifacts

- name: Upload template package
uses: actions/upload-artifact@v4
with:
test-assembly-dll: TestFrameworkBoilerplate.Tests.Integration/bin/Debug/net7.0/TestFrameworkBoilerplate.Tests.Integration.dll
test-execution-json: TestFrameworkBoilerplate.Tests.Integration/bin/Debug/net7.0/TestExecution.json
output-html: MyTestResults.html
framework: net7.0
configuration: 'Debug'

name: nuget-template-package
path: artifacts/*.nupkg
retention-days: 90

# Uncomment to publish to NuGet.org automatically
# - name: Publish to NuGet
# if: startsWith(github.ref, 'refs/tags/')
# run: dotnet nuget push artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

# Summary job
test-summary:
runs-on: ubuntu-latest
needs: [build-and-test, code-quality]
if: always()

steps:
- name: Check build status
run: |
if [ "${{ needs.build-and-test.result }}" == "success" ] && [ "${{ needs.code-quality.result }}" == "success" ]; then
echo "✅ All checks passed!"
exit 0
else
echo "❌ Some checks failed"
exit 1
fi
Loading
Loading