1+ name : .NET CI-CD Pipeline
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ paths :
7+ - ' src/**'
8+ - ' **/*.csproj'
9+ - ' **/*.sln'
10+ - ' .github/workflows/ci-cd.yml'
11+ pull_request :
12+ branches : [ main ]
13+ paths :
14+ - ' src/**'
15+ - ' **/*.csproj'
16+ - ' **/*.sln'
17+
18+ env :
19+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : true
20+ DOTNET_CLI_TELEMETRY_OPTOUT : true
21+ DOTNET_NOLOGO : true
22+
23+ jobs :
24+ build-and-test :
25+ name : Build & Test
26+ runs-on : ubuntu-latest
27+ permissions :
28+ contents : read
29+ pull-requests : write
30+
31+ steps :
32+ - name : Checkout repository
33+ uses : actions/checkout@v4
34+ with :
35+ fetch-depth : 0
36+
37+ - name : Setup .NET
38+ uses : actions/setup-dotnet@v4
39+ with :
40+ dotnet-version : 9.0.x
41+
42+ - name : Cache NuGet packages
43+ uses : actions/cache@v4
44+ with :
45+ path : ~/.nuget/packages
46+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
47+ restore-keys : |
48+ ${{ runner.os }}-nuget-
49+
50+ - name : Restore dependencies
51+ run : dotnet restore
52+
53+ - name : Build library
54+ run : dotnet build --configuration Release --no-restore
55+
56+ - name : Detect test projects
57+ id : detect_tests
58+ run : |
59+ found=false
60+ # Look for explicit IsTestProject flag
61+ if grep -R --include="*.csproj" -l "<IsTestProject>true</IsTestProject>" . >/dev/null 2>&1; then
62+ found=true
63+ fi
64+ # Also detect common test SDK package usage
65+ if [ "$found" = "false" ] && grep -R --include="*.csproj" -l "Microsoft.NET.Test.Sdk" . >/dev/null 2>&1; then
66+ found=true
67+ fi
68+ echo "found=$found" >> $GITHUB_OUTPUT
69+
70+ - name : Run tests
71+ if : steps.detect_tests.outputs.found == 'true'
72+ run : |
73+ dotnet test --configuration Release --no-build --verbosity normal \
74+ --logger "trx;LogFileName=test-results.trx" \
75+ --results-directory ./test-results
76+
77+ - name : Test Report
78+ if : always() && steps.detect_tests.outputs.found == 'true'
79+ uses : dorny/test-reporter@v1
80+ with :
81+ name : Test Results
82+ path : " test-results/*.trx"
83+ reporter : dotnet-trx
84+ fail-on-error : true
85+
86+ validate-package :
87+ name : Validate Package Metadata
88+ runs-on : ubuntu-latest
89+ needs : build-and-test
90+ permissions :
91+ contents : read
92+
93+ steps :
94+ - name : Checkout repository
95+ uses : actions/checkout@v4
96+
97+ - name : Setup .NET
98+ uses : actions/setup-dotnet@v4
99+ with :
100+ dotnet-version : 9.0.x
101+
102+ - name : Restore dependencies
103+ run : dotnet restore
104+
105+ - name : Build library
106+ run : dotnet build --configuration Release --no-restore
107+
108+ - name : Pack for validation
109+ run : dotnet pack --configuration Release --no-build --output ./artifacts
110+
111+ - name : Validate README exists
112+ run : |
113+ if [ ! -f "README.md" ]; then
114+ echo "❌ README.md is missing!"
115+ exit 1
116+ fi
117+ echo "✅ README.md found"
118+
119+ - name : Validate LICENSE exists
120+ run : |
121+ if [ ! -f "LICENSE" ]; then
122+ echo "❌ LICENSE file is missing!"
123+ exit 1
124+ fi
125+ echo "✅ LICENSE found"
126+
127+ - name : Display package info
128+ run : |
129+ echo "📦 Package validation successful"
130+ ls -lh ./artifacts/
0 commit comments