-
Notifications
You must be signed in to change notification settings - Fork 1
131 lines (117 loc) · 4.78 KB
/
Copy pathfe-sonar.yml
File metadata and controls
131 lines (117 loc) · 4.78 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
name: Frontend SonarQube Scan
# Only run the workflow for master/main and release branches
on:
workflow_call:
secrets:
SONAR_CLOUD_TOKEN:
required: true
description: "SonarCloud authentication token"
DOT_NPMRC:
required: true
description: "Npm token"
inputs:
SONAR_CLOUD_ORG:
required: false
description: "SonarCloud organization key, e.g., 'my-org'"
type: string
default: "collaborationfactory"
SONAR_PROPERTIES:
required: false
description: "Additional sonar-project.properties content"
type: string
default: ""
GITHUB_RUNNER:
required: false
description: "Github runner which is used to run sonar scan jobs"
type: string
default: 'medium'
jobs:
sonarqube-scan:
name: SonarQube Code Quality Scan
runs-on: ${{ inputs.GITHUB_RUNNER }}
# Only run the workflow for master/main and release branches
#if: github.ref_name == 'master' || github.ref_name == 'main' || startsWith(github.ref_name, 'release/')
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0 # Full history for SonarQube analysis
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- name: Cache Node Modules
id: npm-cache
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- name: Use .npmrc
if: steps.npm-cache.outputs.cache-hit != 'true'
id: use-npmrc
uses: bduff9/use-npmrc@v1.2
with:
dot-npmrc: ${{ secrets.DOT_NPMRC }}
- name: Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Run Formatter Check
run: npx nx format:check
- name: Run Linter
run: npx nx run-many --target=lint --all --parallel --configuration=dev
- name: Run Unit Tests with Coverage
run: npx nx run-many --target=test --all --parallel=false --coverage --codeCoverage=true --coverageReporters=lcov --coverageReporters=html
continue-on-error: false
- name: Check for LCOV files
id: check-lcov
run: |
if find ./coverage -name "lcov*.info" -type f 2>/dev/null | grep -q .; then
echo "lcov_exists=true" >> $GITHUB_OUTPUT
echo "LCOV files found"
else
echo "lcov_exists=false" >> $GITHUB_OUTPUT
echo "No LCOV files found, will proceed without coverage"
fi
- name: Merge coverage reports
if: steps.check-lcov.outputs.lcov_exists == 'true'
run: |
echo "=== Finding all LCOV files ==="
find ./coverage -name "lcov*.info" -type f
echo ""
echo "=== Merging coverage files ==="
npx lcov-result-merger "coverage/**/lcov*.info" coverage/lcov.info
echo ""
echo "=== Merge completed ==="
ls -lh ./coverage/lcov.info || echo "Merge failed or no output file"
- name: Normalize LCOV paths
if: steps.check-lcov.outputs.lcov_exists == 'true'
run: |
if [ -f "./coverage/lcov.info" ]; then
sed -i 's|\\|/|g' ./coverage/lcov.info
echo "Normalized LCOV paths to Unix format"
else
echo "Warning: coverage/lcov.info not found"
fi
- name: Write sonar-project.properties
run: |
echo "sonar.host.url=https://sonarcloud.io" > sonar-project.properties
echo "sonar.organization=${{ inputs.SONAR_CLOUD_ORG || 'collaborationfactory' }}" >> sonar-project.properties
echo "sonar.projectKey=collaborationFactory_${{ github.event.repository.name }}" >> sonar-project.properties
echo "sonar.test.inclusions=**/*.spec.ts,**/*.test.ts,**/*.spec.tsx,**/*.test.tsx" >> sonar-project.properties
echo "sonar.branch.name=${{ github.ref_name }}" >> sonar-project.properties
echo "sonar.projectVersion=${{ github.ref_name }}" >> sonar-project.properties
echo "sonar.qualitygate.wait=true" >> sonar-project.properties
if [ -f "./coverage/lcov.info" ]; then
echo "sonar.javascript.lcov.reportPaths=./coverage/lcov.info" >> sonar-project.properties
fi
if [ -n "${{ inputs.SONAR_PROPERTIES }}" ]; then
echo "${{ inputs.SONAR_PROPERTIES }}" >> sonar-project.properties
fi
echo "=== SonarQube Configuration ==="
cat sonar-project.properties
# - name: SonarQube Scan
# uses: SonarSource/sonarqube-scan-action@v6
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}