-
Notifications
You must be signed in to change notification settings - Fork 2
170 lines (142 loc) · 4.53 KB
/
analyses.yml
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
name: analyses
# Trigger workflow on push and pull request events targeting the main branch.
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
# Step 1: Install dependencies and cache node_modules
install:
runs-on: ubuntu-latest
steps:
# Check out the code from the repository
- uses: actions/checkout@v2
# Install project dependencies using npm ci for clean install
- name: Install Dependencies
run: npm ci
# Cache node_modules for future jobs to speed up workflow
- name: Cache node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ github.sha }}
build:
needs: install
runs-on: ubuntu-latest
steps:
# Check out the code from the repository
- uses: actions/checkout@v2
# Use cached node_modules to avoid reinstalling dependencies
- name: Cached node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ github.sha }}
# Run the build command
- name: Build
run: npm run build
# Step 2: Run lint checks with ESLint
lint:
needs: install # Depends on the install job
runs-on: ubuntu-latest
steps:
# Check out the code from the repository
- uses: actions/checkout@v2
# Use cached node_modules to avoid reinstalling dependencies
- name: Cached node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ github.sha }}
# Run ESLint to check for code quality issues
- name: ESLint
run: npm run lint:check
# Step 3: Run Prettier to check code formatting
prettier:
needs: install # Depends on the install job
runs-on: ubuntu-latest
steps:
# Check out the code from the repository
- uses: actions/checkout@v2
# Use cached node_modules to avoid reinstalling dependencies
- name: Cached node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ github.sha }}
# Run Prettier to check code formatting
- name: Prettier
run: npm run prettier:check
# Step 4: Run TypeScript checks to ensure there are no type errors
typescript:
needs: install # Depends on the install job
runs-on: ubuntu-latest
steps:
# Check out the code from the repository
- uses: actions/checkout@v2
# Use cached node_modules to avoid reinstalling dependencies
- name: Cached node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ github.sha }}
# Run TypeScript checks
- name: TypeScript
run: npm run ts:check
# Step 5: Run unit tests
unit_tests:
needs: install # Depends on the install job
runs-on: ubuntu-latest
steps:
# Check out the code from the repository
- uses: actions/checkout@v2
# Use cached node_modules to avoid reinstalling dependencies
- name: Cached node modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ github.sha }}
# Run unit tests
- name: Unit tests
run: npm run test:unit
# Generate coverage report
- name: Generate Coverage Report
run: npm run coverage
# Upload coverage report
- name: Upload coverage Report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage
# Step 6: Run SonarQube analysis
sonarqube:
name: SonarQube Analysis
needs: [build, unit_tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
#Download coverage report
- name: Download coverage Report
uses: actions/download-artifact@v3
with:
name: coverage-report
path: coverage
# Run SonarQube analysis
- uses: sonarsource/sonarqube-scan-action@v3
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
with:
args: |
-Dsonar.projectKey=Webank-Userapp
-Dsonar.source=src
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
-Dsonar.qualitygate.wait=true
#If you wish to fail your job when the Quality Gate is red
- uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}