Skip to content

Commit 3cc5289

Browse files
committed
Update build.yml
1 parent 85c1d64 commit 3cc5289

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed

.github/workflows/build.yml

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
name: .NET Build and Test
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
env:
10+
DOTNET_VERSION: '9.0.x'
11+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
12+
DOTNET_NOLOGO: true
13+
DOTNET_CLI_TELEMETRY_OPTOUT: true
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
configuration: [Debug, Release]
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0 # Shallow clones should be disabled for better analysis
28+
29+
- name: Setup .NET
30+
uses: actions/setup-dotnet@v4
31+
with:
32+
dotnet-version: ${{ env.DOTNET_VERSION }}
33+
include-prerelease: true
34+
35+
- name: Display .NET info
36+
run: dotnet --info
37+
38+
- name: Cache NuGet packages
39+
uses: actions/cache@v4
40+
with:
41+
path: ~/.nuget/packages
42+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.props') }}
43+
restore-keys: |
44+
${{ runner.os }}-nuget-
45+
46+
- name: Restore dependencies
47+
run: dotnet restore
48+
49+
- name: Build solution
50+
run: dotnet build --configuration ${{ matrix.configuration }} --no-restore --verbosity minimal
51+
52+
- name: Test library (if tests exist)
53+
run: |
54+
# Check if there are any test projects in the src/NLWebNet directory
55+
TEST_PROJECTS=$(find src/NLWebNet -name "*.csproj" -exec grep -l "Microsoft.NET.Test.Sdk\|xunit\|NUnit\|MSTest" {} \; 2>/dev/null || true)
56+
57+
if [ -n "$TEST_PROJECTS" ]; then
58+
echo "Found test projects, running tests..."
59+
dotnet test src/NLWebNet --configuration ${{ matrix.configuration }} --no-build --verbosity minimal --logger "trx;LogFileName=test-results-${{ matrix.configuration }}.trx" --results-directory TestResults/
60+
else
61+
echo "No test projects found in src/NLWebNet - skipping tests (tests will be implemented in Phase 9)"
62+
mkdir -p TestResults
63+
echo "##[warning]No test projects found - tests will be implemented in Phase 9"
64+
fi
65+
continue-on-error: false
66+
67+
- name: Build demo application
68+
run: dotnet build demo --configuration ${{ matrix.configuration }} --no-restore --verbosity minimal
69+
70+
- name: Publish test results
71+
uses: dorny/test-reporter@v1
72+
if: success() || failure()
73+
with:
74+
name: Test Results (${{ matrix.configuration }})
75+
path: TestResults/*.trx
76+
reporter: dotnet-trx
77+
fail-on-error: false
78+
fail-on-empty: false
79+
80+
- name: Upload build artifacts
81+
if: matrix.configuration == 'Release'
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: build-artifacts-${{ matrix.configuration }}
85+
path: |
86+
src/NLWebNet/bin/Release/
87+
demo/bin/Release/
88+
retention-days: 7
89+
90+
code-quality:
91+
runs-on: ubuntu-latest
92+
needs: build
93+
94+
steps:
95+
- name: Checkout code
96+
uses: actions/checkout@v4
97+
with:
98+
fetch-depth: 0
99+
100+
- name: Setup .NET
101+
uses: actions/setup-dotnet@v4
102+
with:
103+
dotnet-version: ${{ env.DOTNET_VERSION }}
104+
include-prerelease: true
105+
106+
- name: Restore dependencies
107+
run: dotnet restore
108+
109+
- name: Run code analysis
110+
run: |
111+
dotnet build --configuration Release --verbosity minimal --warnaserror
112+
113+
- name: Check formatting
114+
run: dotnet format --verify-no-changes --verbosity diagnostic
115+
116+
security-scan:
117+
runs-on: ubuntu-latest
118+
needs: build
119+
120+
steps:
121+
- name: Checkout code
122+
uses: actions/checkout@v4
123+
124+
- name: Setup .NET
125+
uses: actions/setup-dotnet@v4
126+
with:
127+
dotnet-version: ${{ env.DOTNET_VERSION }}
128+
include-prerelease: true
129+
130+
- name: Restore dependencies
131+
run: dotnet restore
132+
133+
- name: Run security scan
134+
run: |
135+
dotnet list package --vulnerable --include-transitive 2>&1 | tee security-scan.log
136+
if grep -q "has the following vulnerable packages" security-scan.log; then
137+
echo "❌ Vulnerable packages found!"
138+
exit 1
139+
else
140+
echo "✅ No vulnerable packages found."
141+
fi
142+
143+
package-validation:
144+
runs-on: ubuntu-latest
145+
needs: build
146+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
147+
148+
steps:
149+
- name: Checkout code
150+
uses: actions/checkout@v4
151+
152+
- name: Setup .NET
153+
uses: actions/setup-dotnet@v4
154+
with:
155+
dotnet-version: ${{ env.DOTNET_VERSION }}
156+
include-prerelease: true
157+
158+
- name: Restore dependencies
159+
run: dotnet restore
160+
161+
- name: Pack NuGet package
162+
run: dotnet pack src/NLWebNet --configuration Release --no-build --output ./packages
163+
164+
- name: Upload package artifacts
165+
uses: actions/upload-artifact@v4
166+
with:
167+
name: nuget-packages
168+
path: ./packages/*.nupkg
169+
retention-days: 30
170+
171+
- name: Validate package
172+
run: |
173+
echo "📦 Validating NuGet package..."
174+
for package in ./packages/*.nupkg; do
175+
echo "Validating: $package"
176+
dotnet tool install --global dotnet-validate --version 0.0.1-preview.304
177+
dotnet validate package local "$package"
178+
done

0 commit comments

Comments
 (0)