Skip to content

Commit 7586a6a

Browse files
authored
Merge pull request #1244
* chore(36015): fix the PR decorations for sonarqube * chore(36015): add exclusions for code duplication * chore(36015): fix bug with dynamic imports in cypress * chore(36015): refactor the code coverage script for local dev * chore(36015): add context * chore(36015): linting * chore(36015): revert "fix bug with dynamic imports in cypress" * chore(36015): update dependencies
1 parent 9dbaba1 commit 7586a6a

21 files changed

+2526
-57
lines changed

.github/workflows/check-frontend.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ jobs:
208208
-Dsonar.verbose=false
209209
env:
210210
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
211+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
211212

212213
percy_finalise:
213214
name: Percy (finalise)

hivemq-edge-frontend/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ test-results
3535
/coverage-e2e/
3636
/coverage-vitest/
3737
/coverage-cypress/
38+
/coverage-combined/
3839

3940

4041
# Local dev fixes
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"all": true,
3+
"report-dir": "./coverage-cypress-matrix",
4+
"temp-dir": "./.nyc_output/matrix",
5+
"extends": "@istanbuljs/nyc-config-typescript",
6+
"check-coverage": false,
7+
"include": ["src/**/*.ts", "src/**/*.tsx"],
8+
"exclude": ["cypress/**/*.*", "**/*.d.ts", "**/*.cy.tsx", "**/*.cy.ts"],
9+
"reporter": ["json", "lcovonly"]
10+
}
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
# SonarCloud Decoration - Action Plan
2+
3+
**Task:** 36015-sonarcloud-decoration
4+
**Date:** October 24, 2025
5+
6+
## Executive Summary
7+
8+
The HiveMQ Edge Frontend has a SonarCloud configuration and GitHub Actions workflow in place, but it's using the **wrong GitHub Action** (SonarQube instead of SonarCloud) which prevents proper PR decoration. This document outlines the issues and proposed fixes.
9+
10+
## Critical Issues Found
11+
12+
### 🔴 Issue #1: Wrong GitHub Action (BLOCKING PR DECORATION)
13+
14+
**Current State:**
15+
16+
```yaml
17+
- name: SonarQube Scan
18+
uses: SonarSource/sonarqube-scan-action@2500896589ef8f7247069a56136f8dc177c27ccf # v5
19+
```
20+
21+
**Problem:**
22+
23+
- This action is for **SonarQube** (self-hosted server)
24+
- SonarQube action **cannot** decorate GitHub PRs with SonarCloud
25+
- Missing required PR decoration parameters
26+
27+
**Impact:** PR decoration is not working at all
28+
29+
**Fix Required:**
30+
31+
```yaml
32+
- name: SonarCloud Scan
33+
uses: SonarSource/[email protected]
34+
```
35+
36+
---
37+
38+
### 🟡 Issue #2: Missing PR Context
39+
40+
**Current State:**
41+
42+
- No pull request number passed to SonarCloud
43+
- No base branch configuration
44+
- Missing PR-specific metadata
45+
46+
**Impact:** Even if we switch actions, PR decoration won't have context
47+
48+
**Fix Required:**
49+
Add GitHub PR context to the scan:
50+
51+
```yaml
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
55+
```
56+
57+
The `GITHUB_TOKEN` enables automatic PR decoration.
58+
59+
---
60+
61+
### 🟡 Issue #3: Coverage Path Configuration
62+
63+
**Current Setup:**
64+
65+
- Artifacts uploaded as separate folders: `lcov-cypress-Components`, `lcov-cypress-E2E`, etc.
66+
- Downloaded to: `hivemq-edge-frontend/coverage-combined/`
67+
- Config expects: `./coverage-combined/lcov-*/lcov.info`
68+
69+
**Potential Issue:**
70+
Path resolution depends on working directory context. Currently using:
71+
72+
```yaml
73+
with:
74+
projectBaseDir: hivemq-edge-frontend
75+
```
76+
77+
**Status:** Likely working, but worth verifying in logs
78+
79+
---
80+
81+
### 🟢 Issue #4: Job Execution Condition
82+
83+
**Current State:**
84+
85+
```yaml
86+
if: success() || failure()
87+
```
88+
89+
**Analysis:**
90+
91+
- Runs even if tests fail
92+
- Submits partial/incomplete coverage
93+
- May be intentional for catching quality issues
94+
95+
**Recommendation:** Keep current behavior, but document why
96+
97+
---
98+
99+
## Configuration Review
100+
101+
### ✅ Well-Configured Items
102+
103+
1. **Project Identification:**
104+
105+
```ini
106+
sonar.projectKey=hivemq_hivemq-edge
107+
sonar.organization=hivemq
108+
```
109+
110+
2. **Coverage Sources:**
111+
112+
- 6 LCOV reports (5 Cypress splits + Vitest)
113+
- Proper path structure
114+
115+
3. **Exclusions:**
116+
117+
- Generated files
118+
- Test utilities
119+
- Schema files
120+
- Tools directory
121+
122+
4. **Test Inclusions:**
123+
- All test file patterns covered
124+
125+
---
126+
127+
## Proposed Changes
128+
129+
### Change #1: Switch to SonarCloud Action
130+
131+
**File:** `.github/workflows/check-frontend.yml`
132+
133+
**Before:**
134+
135+
```yaml
136+
- name: SonarQube Scan
137+
uses: SonarSource/sonarqube-scan-action@2500896589ef8f7247069a56136f8dc177c27ccf # v5
138+
with:
139+
projectBaseDir: hivemq-edge-frontend
140+
args: >
141+
-Dsonar.verbose=false
142+
env:
143+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
144+
```
145+
146+
**After:**
147+
148+
```yaml
149+
- name: SonarCloud Scan
150+
uses: SonarSource/[email protected]
151+
with:
152+
projectBaseDir: hivemq-edge-frontend
153+
args: >
154+
-Dsonar.verbose=false
155+
env:
156+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
158+
```
159+
160+
**Key Changes:**
161+
162+
1. Switch from `sonarqube-scan-action` → `sonarcloud-github-action`
163+
2. Add `GITHUB_TOKEN` for PR decoration
164+
3. Update job name from "SonarQube" → "SonarCloud"
165+
166+
---
167+
168+
### Change #2: Add Quality Gate Check (Optional Enhancement)
169+
170+
Add a quality gate status check after the scan:
171+
172+
```yaml
173+
- name: SonarCloud Quality Gate
174+
uses: SonarSource/[email protected]
175+
timeout-minutes: 5
176+
env:
177+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
178+
```
179+
180+
This will fail the workflow if quality gate doesn't pass.
181+
182+
---
183+
184+
### Change #3: Improve Artifact Verification
185+
186+
**Current:**
187+
188+
```yaml
189+
- name: Verify LCOV Artifacts
190+
run: |
191+
ls -R ./coverage-combined
192+
ls -R **/**/*.info
193+
```
194+
195+
**Enhanced:**
196+
197+
```yaml
198+
- name: Verify LCOV Artifacts
199+
run: |
200+
echo "=== Coverage artifacts downloaded ==="
201+
ls -la ./coverage-combined/
202+
echo ""
203+
echo "=== LCOV files found ==="
204+
find ./coverage-combined -name "lcov.info" -type f
205+
echo ""
206+
echo "=== File sizes ==="
207+
find ./coverage-combined -name "lcov.info" -type f -exec ls -lh {} \;
208+
```
209+
210+
This provides better debugging information.
211+
212+
---
213+
214+
## Implementation Plan
215+
216+
### Phase 1: Critical Fix (REQUIRED)
217+
218+
1. ✅ Audit current configuration (COMPLETED)
219+
2. 🔲 Switch to `sonarcloud-github-action`
220+
3. 🔲 Add `GITHUB_TOKEN` environment variable
221+
4. 🔲 Test on a PR
222+
223+
### Phase 2: Verification (REQUIRED)
224+
225+
1. 🔲 Verify PR decoration appears on pull requests
226+
2. 🔲 Verify coverage reports are uploaded correctly
227+
3. 🔲 Check SonarCloud dashboard for analysis results
228+
229+
### Phase 3: Enhancements (OPTIONAL)
230+
231+
1. 🔲 Add quality gate check action
232+
2. 🔲 Improve artifact verification logging
233+
3. 🔲 Document the setup for team members
234+
235+
---
236+
237+
## Testing Strategy
238+
239+
### Test 1: Create Test PR
240+
241+
1. Make a trivial change to a frontend file
242+
2. Create a PR
243+
3. Verify the workflow runs
244+
4. Check for SonarCloud decoration on the PR
245+
246+
### Test 2: Verify Coverage
247+
248+
1. Check SonarCloud dashboard
249+
2. Verify all 6 coverage reports are processed
250+
3. Confirm coverage metrics are accurate
251+
252+
### Test 3: Quality Gate
253+
254+
1. Introduce a deliberate code smell
255+
2. Verify SonarCloud detects it
256+
3. Verify it appears in PR decoration
257+
258+
---
259+
260+
## Risk Assessment
261+
262+
### Low Risk
263+
264+
- Switching GitHub Actions (both are official SonarSource actions)
265+
- Adding GITHUB_TOKEN (standard practice)
266+
267+
### Medium Risk
268+
269+
- Coverage path resolution (already configured, unlikely to break)
270+
271+
### High Risk
272+
273+
- None identified
274+
275+
---
276+
277+
## Rollback Plan
278+
279+
If issues occur:
280+
281+
1. Revert the workflow file change
282+
2. Original SHA: `2500896589ef8f7247069a56136f8dc177c27ccf`
283+
3. Workflow will continue to run (just without PR decoration)
284+
285+
---
286+
287+
## Success Criteria
288+
289+
- ✅ SonarCloud analysis runs on every PR
290+
- ✅ PR shows SonarCloud decoration with:
291+
- Code quality metrics
292+
- Coverage changes
293+
- New issues found
294+
- Quality gate status
295+
- ✅ Team can see analysis results before merging
296+
- ✅ No workflow failures due to configuration issues
297+
298+
---
299+
300+
## References
301+
302+
- SonarCloud GitHub Action: https://github.com/SonarSource/sonarcloud-github-action
303+
- SonarCloud PR Decoration: https://docs.sonarcloud.io/enriching/pr-decoration/
304+
- Current workflow: `.github/workflows/check-frontend.yml`
305+
- Configuration: `hivemq-edge-frontend/sonar-project.properties`

0 commit comments

Comments
 (0)