-
Notifications
You must be signed in to change notification settings - Fork 1
281 lines (232 loc) · 10 KB
/
Copy pathcode-quality.yml
File metadata and controls
281 lines (232 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: 📊 Code Quality
on:
workflow_dispatch:
pull_request:
branches: [main]
push:
branches:
- main
- "releases/*"
jobs:
# Qodana Analysis
qodana:
name: 🔍 Qodana Analysis
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
checks: write
steps:
- name: 📥 Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: 🔍 Qodana Scan
id: qodana
uses: JetBrains/qodana-action@4861e015da555e86a72b862892aba6c2b93e6891
continue-on-error: true
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
with:
args: --linter,qodana-cdnet --project,QRCoder.Core/QRCoder.Core.csproj --baseline,qodana.sarif.json --fail-threshold,0
cache-default-branch-only: true
upload-result: false
primary-cache-key: qodana-2025.3-refs/heads/main-${{ github.sha }}
additional-cache-key: qodana-2025.3-refs/heads/main
- name: 📊 Upload Qodana Results
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
if: always()
with:
name: qodana-report
path: ${{ github.workspace }}/qodana
# SonarQube Analysis
sonarqube:
name: 📊 SonarQube Analysis
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
permissions:
contents: read
steps:
- name: 📥 Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
with:
fetch-depth: 0
- name: 📦 Setup NuGet
uses: NuGet/setup-nuget@fd55a6f3b34392fa83fde1454582407d8c714123
- name: 🗄️ Setup .NET
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1
with:
dotnet-version: "10.0.x"
- name: ☕ Set up JDK 17
uses: actions/setup-java@0f481fcb613427c0f801b606911222b5b6f3083a
with:
java-version: 17
distribution: "zulu"
- name: 🔧 Clear NuGet cache
run: dotnet nuget locals all --clear
- name: 📦 Install SonarQube Tools
run: dotnet tool install --global --ignore-failed-sources dotnet-sonarscanner
- name: 📦 Install Coverlet Tools
run: dotnet tool install --global --ignore-failed-sources coverlet.console
- name: 🔧 Fix Permission
run: |
if [ -d sonar ]; then
chmod -R u+rwX,go+rX,go-w sonar
fi
- name: 🔍 Prepare analysis on SonarQube
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN || secrets.SONAR_TOKEN }}
run: |
echo "🔍 Checking SonarQube configuration..."
if [ -z "$SONAR_TOKEN" ]; then
echo "❌ SONAR_TOKEN is not set or empty"
echo "⚠️ Skipping SonarQube analysis"
exit 0
fi
echo "✅ SONAR_TOKEN is configured"
dotnet sonarscanner begin \
/o:"afonsoft" \
/k:"afonsoft_QRCoder.Core" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.token="$SONAR_TOKEN" \
/d:sonar.scm.provider=git \
/d:sonar.coverage.exclusions="**Test*.cs"
- name: 🏗️ Build
run: dotnet build QRCoder.Core.sln --configuration release
- name: 🔍 Run Code Analysis
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN || secrets.SONAR_TOKEN }}
run: |
echo "🔍 Finalizing SonarQube analysis..."
if [ -z "$SONAR_TOKEN" ]; then
echo "⚠️ SONAR_TOKEN not configured, skipping analysis"
exit 0
fi
dotnet sonarscanner end /d:sonar.token="$SONAR_TOKEN"
# Snyk Security Analysis
snyk:
name: 🛡️ Snyk Security
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- name: 📥 Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
- name: 🗄️ Setup .NET
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1
with:
dotnet-version: "10.0.x"
- name: 🔧 Restore Dependencies
run: dotnet restore QRCoder.Core.sln --ignore-failed-sources
- name: 🛡️ Run Snyk
uses: snyk/actions/dotnet@8e119fbb6c251787721d34ba683ed48eba792766
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: test
args: --file=QRCoder.Core.sln --severity-threshold=high --sarif-file-output=snyk.sarif --json-output=snyk.json
- name: 📊 Upload Snyk Results
uses: github/codeql-action/upload-sarif@99df26d4f13ea111d4ec1a7dddef6063f76b97e9
if: always() && hashFiles('snyk.sarif') != ''
with:
sarif_file: snyk.sarif
category: snyk
- name: 📋 Generate Snyk Summary
if: always()
run: |
echo "## 🛡️ Snyk Security Scan Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f "snyk.json" ]; then
echo "### 📊 Vulnerability Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Extract summary from JSON
VULNS=$(cat snyk.json | jq -r '.results[0].vulnerabilities | length' 2>/dev/null || echo "0")
DEPS=$(cat snyk.json | jq -r '.results[0].dependencies | length' 2>/dev/null || echo "0")
echo "- **Dependencies Analyzed**: $DEPS" >> $GITHUB_STEP_SUMMARY
echo "- **Vulnerabilities Found**: $VULNS" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "$VULNS" -gt 0 ]; then
echo "### ⚠️ Vulnerabilities Detected" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Extract vulnerability details
cat snyk.json | jq -r '.results[0].vulnerabilities[] |
"- **\(.severity | ascii_upcase)**: \(.title) in \(.package)@\(.version)"' 2>/dev/null | head -10 >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🔧 Affected Projects" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Extract affected projects
cat snyk.json | jq -r '.results[0].vulnerabilities[] |
"- \(.from[0] | split("/")[-1])"' 2>/dev/null | sort -u >> $GITHUB_STEP_SUMMARY
else
echo "✅ **No vulnerabilities found!** All dependencies are secure." >> $GITHUB_STEP_SUMMARY
fi
else
echo "⚠️ **Snyk scan results not available**" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📋 Scan Configuration" >> $GITHUB_STEP_SUMMARY
echo "- **Severity Threshold**: High" >> $GITHUB_STEP_SUMMARY
echo "- **Target**: QRCoder.Core.sln" >> $GITHUB_STEP_SUMMARY
echo "- **Scanner**: Snyk .NET" >> $GITHUB_STEP_SUMMARY
# Code Quality Metrics
quality-metrics:
name: 📈 Quality Metrics
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: 📥 Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
- name: 🗄️ Setup .NET
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1
with:
dotnet-version: "10.0.x"
- name: 🔧 Restore Dependencies
run: dotnet restore QRCoder.Core.sln --ignore-failed-sources
- name: 🏗️ Build Solution
run: dotnet build QRCoder.Core.sln --configuration Release --no-restore --verbosity minimal
- name: 📊 Calculate Metrics
run: |
echo "📊 Analyzing code quality metrics..."
# Count lines of code
echo "Lines of Code: $(find src -name '*.cs' -exec wc -l {} + | tail -1 | awk '{print $1}')"
# Count test files
echo "Test Files: $(find tests -name '*Tests.cs' | wc -l)"
# Count projects
echo "Projects: $(find src -name '*.csproj' | wc -l)"
# Count pending markers in source files
echo "Pending markers: $(grep -r 'TODO' src --include='*.cs' | wc -l)"
echo "Quality metrics analysis completed!"
# Quality Summary
quality-summary:
name: 📋 Quality Summary
runs-on: ubuntu-latest
needs: [qodana, sonarqube, snyk, quality-metrics]
if: always()
permissions:
contents: read
steps:
- name: 📋 Generate Quality Report
run: |
echo "## 📊 Code Quality Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Tool | Status |" >> $GITHUB_STEP_SUMMARY
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| 🔍 Qodana | ${{ needs.qodana.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| 📊 SonarQube | ${{ needs.sonarqube.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| 🛡️ Snyk | ${{ needs.snyk.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| 📈 Metrics | ${{ needs.quality-metrics.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.qodana.result }}" == "failure" || "${{ needs.sonarqube.result }}" == "failure" || "${{ needs.snyk.result }}" == "failure" ]]; then
echo "❌ **Quality issues detected! Please review the analysis reports.**" >> $GITHUB_STEP_SUMMARY
else
echo "✅ **All quality checks passed!**" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📊 Quality Metrics" >> $GITHUB_STEP_SUMMARY
echo "- **Lines of Code**: Calculated during build" >> $GITHUB_STEP_SUMMARY
echo "- **Test Coverage**: Available in CI pipeline" >> $GITHUB_STEP_SUMMARY
echo "- **Technical Debt**: Analyzed by Qodana & SonarQube" >> $GITHUB_STEP_SUMMARY
echo "- **Security**: Scanned by Snyk" >> $GITHUB_STEP_SUMMARY