|
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 | | - |
79 | | - - name: Upload build artifacts |
80 | | - if: matrix.configuration == 'Release' |
81 | | - uses: actions/upload-artifact@v4 |
82 | | - with: |
83 | | - name: build-artifacts-${{ matrix.configuration }} |
84 | | - path: | |
85 | | - src/NLWebNet/bin/Release/ |
86 | | - demo/bin/Release/ |
87 | | - retention-days: 7 |
88 | | - |
89 | | - code-quality: |
90 | | - runs-on: ubuntu-latest |
91 | | - needs: build |
92 | | - |
93 | | - steps: |
94 | | - - name: Checkout code |
95 | | - uses: actions/checkout@v4 |
96 | | - with: |
97 | | - fetch-depth: 0 |
98 | | - |
99 | | - - name: Setup .NET |
100 | | - uses: actions/setup-dotnet@v4 |
101 | | - with: |
102 | | - dotnet-version: ${{ env.DOTNET_VERSION }} |
103 | | - include-prerelease: true |
104 | | - |
105 | | - - name: Restore dependencies |
106 | | - run: dotnet restore |
107 | | - |
108 | | - - name: Run code analysis |
109 | | - run: | |
110 | | - dotnet build --configuration Release --verbosity minimal --warnaserror |
111 | | - |
112 | | - - name: Check formatting |
113 | | - run: dotnet format --verify-no-changes --verbosity diagnostic |
114 | | - |
115 | | - security-scan: |
116 | | - runs-on: ubuntu-latest |
117 | | - needs: build |
118 | | - |
119 | | - steps: |
120 | | - - name: Checkout code |
121 | | - uses: actions/checkout@v4 |
122 | | - |
123 | | - - name: Setup .NET |
124 | | - uses: actions/setup-dotnet@v4 |
125 | | - with: |
126 | | - dotnet-version: ${{ env.DOTNET_VERSION }} |
127 | | - include-prerelease: true |
128 | | - |
129 | | - - name: Restore dependencies |
130 | | - run: dotnet restore |
131 | | - |
132 | | - - name: Run security scan |
133 | | - run: | |
134 | | - dotnet list package --vulnerable --include-transitive 2>&1 | tee security-scan.log |
135 | | - if grep -q "has the following vulnerable packages" security-scan.log; then |
136 | | - echo "❌ Vulnerable packages found!" |
137 | | - exit 1 |
138 | | - else |
139 | | - echo "✅ No vulnerable packages found." |
140 | | - fi |
141 | | -
|
142 | | - package-validation: |
143 | | - runs-on: ubuntu-latest |
144 | | - needs: build |
145 | | - if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
146 | | - |
147 | | - steps: |
148 | | - - name: Checkout code |
149 | | - uses: actions/checkout@v4 |
150 | | - |
151 | | - - name: Setup .NET |
152 | | - uses: actions/setup-dotnet@v4 |
153 | | - with: |
154 | | - dotnet-version: ${{ env.DOTNET_VERSION }} |
155 | | - include-prerelease: true |
156 | | - |
157 | | - - name: Restore dependencies |
158 | | - run: dotnet restore |
159 | | - |
160 | | - - name: Pack NuGet package |
161 | | - run: dotnet pack src/NLWebNet --configuration Release --no-build --output ./packages |
162 | | - |
163 | | - - name: Upload package artifacts |
164 | | - uses: actions/upload-artifact@v4 |
165 | | - with: |
166 | | - name: nuget-packages |
167 | | - path: ./packages/*.nupkg |
168 | | - retention-days: 30 |
169 | | - |
170 | | - - name: Validate package |
171 | | - run: | |
172 | | - echo "📦 Validating NuGet package..." |
173 | | - for package in ./packages/*.nupkg; do |
174 | | - echo "Validating: $package" |
175 | | - dotnet tool install --global dotnet-validate --version 0.0.1-preview.304 |
176 | | - dotnet validate package local "$package" |
177 | | - done |
0 commit comments