Skip to content

Commit b06446b

Browse files
authored
PFM-ISSUE-31185 - Implement Main Branch Scanning with Manual Trigger (#112)
changelog: Frontend-Core: [PFM-ISSUE-31185] Functionality: Implement Main Branch Scanning with Manual Trigger [PR github-actions#112]
1 parent bd06f21 commit b06446b

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

.github/workflows/fe-sonar.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Frontend SonarQube Scan
2+
# Only run the workflow for master/main and release branches
3+
4+
on:
5+
workflow_call:
6+
secrets:
7+
SONAR_CLOUD_TOKEN:
8+
required: true
9+
description: "SonarCloud authentication token"
10+
inputs:
11+
SONAR_CLOUD_ORG:
12+
required: false
13+
description: "SonarCloud organization key, e.g., 'my-org'"
14+
type: string
15+
default: "collaborationfactory"
16+
SONAR_PROPERTIES:
17+
required: false
18+
description: "Additional sonar-project.properties content"
19+
type: string
20+
default: ""
21+
22+
jobs:
23+
sonarqube-scan:
24+
name: SonarQube Code Quality Scan
25+
runs-on: ubuntu-latest
26+
# Only run the workflow for master/main and release branches
27+
if: github.ref_name == 'master' || github.ref_name == 'main' || startsWith(github.ref_name, 'release/')
28+
permissions:
29+
contents: read
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v5
33+
with:
34+
fetch-depth: 0 # Full history for SonarQube analysis
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v6
38+
with:
39+
node-version-file: .nvmrc
40+
41+
- name: Cache Node Modules
42+
id: npm-cache
43+
uses: actions/cache@v4
44+
with:
45+
path: '**/node_modules'
46+
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
47+
48+
- name: Install dependencies
49+
if: steps.npm-cache.outputs.cache-hit != 'true'
50+
run: npm ci
51+
52+
- name: Run Formatter Check
53+
run: npx nx format:check
54+
55+
- name: Run Linter
56+
run: npx nx run-many --target=lint --all --parallel --configuration=dev
57+
58+
- name: Run Unit Tests with Coverage
59+
run: npx nx run-many --target=test --all --parallel --coverage --codeCoverage=true --coverageReporters=lcov --coverageReporters=html
60+
continue-on-error: false
61+
62+
- name: Check for LCOV files
63+
id: check-lcov
64+
run: |
65+
if find ./coverage -name "lcov*.info" -type f 2>/dev/null | grep -q .; then
66+
echo "lcov_exists=true" >> $GITHUB_OUTPUT
67+
echo "LCOV files found"
68+
else
69+
echo "lcov_exists=false" >> $GITHUB_OUTPUT
70+
echo "No LCOV files found, will proceed without coverage"
71+
fi
72+
73+
- name: Merge coverage reports
74+
if: steps.check-lcov.outputs.lcov_exists == 'true'
75+
run: |
76+
echo "=== Finding all LCOV files ==="
77+
find ./coverage -name "lcov*.info" -type f
78+
echo ""
79+
echo "=== Merging coverage files ==="
80+
npx lcov-result-merger "coverage/**/lcov*.info" coverage/lcov.info
81+
echo ""
82+
echo "=== Merge completed ==="
83+
ls -lh ./coverage/lcov.info || echo "Merge failed or no output file"
84+
85+
- name: Normalize LCOV paths
86+
if: steps.check-lcov.outputs.lcov_exists == 'true'
87+
run: |
88+
if [ -f "./coverage/lcov.info" ]; then
89+
sed -i 's|\\|/|g' ./coverage/lcov.info
90+
echo "Normalized LCOV paths to Unix format"
91+
else
92+
echo "Warning: coverage/lcov.info not found"
93+
fi
94+
95+
- name: Write sonar-project.properties
96+
run: |
97+
echo "sonar.host.url=https://sonarcloud.io" > sonar-project.properties
98+
echo "sonar.organization=${{ inputs.SONAR_CLOUD_ORG || 'collaborationfactory' }}" >> sonar-project.properties
99+
echo "sonar.projectKey=collaborationFactory_${{ github.event.repository.name }}" >> sonar-project.properties
100+
echo "sonar.test.inclusions=**/*.spec.ts,**/*.test.ts,**/*.spec.tsx,**/*.test.tsx" >> sonar-project.properties
101+
echo "sonar.branch.name=${{ github.ref_name }}" >> sonar-project.properties
102+
echo "sonar.projectVersion=${{ github.ref_name }}" >> sonar-project.properties
103+
echo "sonar.qualitygate.wait=true" >> sonar-project.properties
104+
if [ -f "./coverage/lcov.info" ]; then
105+
echo "sonar.javascript.lcov.reportPaths=./coverage/lcov.info" >> sonar-project.properties
106+
fi
107+
if [ -n "${{ inputs.SONAR_PROPERTIES }}" ]; then
108+
echo "${{ inputs.SONAR_PROPERTIES }}" >> sonar-project.properties
109+
fi
110+
echo "=== SonarQube Configuration ==="
111+
cat sonar-project.properties
112+
113+
- name: SonarQube Scan
114+
uses: SonarSource/sonarqube-scan-action@v6
115+
env:
116+
SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}

0 commit comments

Comments
 (0)