-
Notifications
You must be signed in to change notification settings - Fork 0
326 lines (310 loc) · 10.4 KB
/
cicd.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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
---
name: CI + CD
on:
push:
branches:
- "**"
env:
DEV_PORT: 50505
STAGING_PORT: 50506
PROD_PORT: 50507
SONAR_PROJECT_KEY: "bas-kirill_muse-project_c40bc999-8826-433b-bb84-8871688b1ab1"
jobs:
openapi-linter:
name: "[OpenAPI] Linter"
runs-on: kiryuxa-1
steps:
- uses: actions/checkout@v1
- name: Run Spectral Linter
run: ./tools/scripts/openapi/runLinter.sh
credentials-check:
name: "[PR] GitGuardian scan"
if: false # or in another case, there will be "Error: Server is not responding as expected."
runs-on: kiryuxa-1
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch all history so multiple commits can be scanned
- name: GitGuardian scan
uses: GitGuardian/ggshield-action@v1
env:
GITHUB_PUSH_BEFORE_SHA: ${{ github.event.before }}
GITHUB_PUSH_BASE_SHA: ${{ github.event.base }}
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
client-linter:
name: "[CLIENT] Linter"
runs-on: kiryuxa-1
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Run linter
run: ./tools/scripts/client/runLinter.sh
client-static-analyzer:
name: "[CLIENT] Static Analyzer"
runs-on: kiryuxa-2
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Install dependencies
run: cd ./client && npm install
- name: Run Static Analyzer
run: ./tools/scripts/client/runStaticAnalyzer.sh
server-linter:
name: "[SERVER] Linter"
runs-on: kiryuxa-2
steps:
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Checkout Code
uses: actions/checkout@v4
- name: Run linter
run: ./tools/scripts/server/runLinter.sh
server-static-analyzer:
name: "[SERVER] Static Analyzer"
runs-on: kiryuxa-2
steps:
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Checkout Code
uses: actions/checkout@v4
- name: Run static analyzer
run: ./tools/scripts/server/runStaticAnalyzer.sh
server-sonarqube:
name: "[SERVER] Run SonarQube"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Run sonarqube
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_PROJECT_KEY: ${{ env.SONAR_PROJECT_KEY }}
- name: Wait for quality gate result
run: sleep 5
- uses: phwt/sonarqube-quality-gate-action@v1
id: quality-gate-check
with:
sonar-project-key: "bas-kirill_muse-project_c40bc999-8826-433b-bb84-8871688b1ab1"
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
github-token: ${{ secrets.GH_TOKEN }}
- name: Output result
run: |
echo "${{ steps.quality-gate-result.outputs.project-status }}"
echo "${{ steps.quality-gate-result.outputs.quality-gate-result }}"
server-unit-tests:
name: "[SERVER] Unit Tests"
runs-on: kiryuxa-3
permissions:
contents: read
issues: read
checks: write
pull-requests: write
steps:
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Checkout Code
uses: actions/checkout@v4
- name: Run Unit Tests
env:
MUSE_JWT_SECRET_KEY: ${{ secrets.MUSE_JWT_SECRET_KEY }}
run: ./tools/scripts/server/runUnitTests.sh
# - name: Publish Unit Test Results
# if: always()
# uses: EnricoMi/[email protected]
# with:
# files: ./**/**/build/test-results/**/*.xml
# report_individual_runs: true
- name: Gather reports
uses: actions/upload-artifact@v2
if: always()
with:
name: reports
path: ./**/**/build/reports
deploy-dev:
name: "[SERVER] Deploy to Dev"
# needs:
# - openapi-linter
# - client-linter
# - client-static-analyzer
# - server-linter
# - server-static-analyzer
# - server-unit-tests
# - server-sonarqube
runs-on: ubuntu-22.04
environment:
name: dev
url: http://dev.muse.kiryuxa.com
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: myshx
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/setup-node@v4
with:
node-version: "20.16.0"
- name: "Install `Redocly`"
run: npm i -g @redocly/cli@latest
- name: Cache npm dependencies
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
run: npm install --prefix client
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.DEPLOY_SERVER_SSH_PRIVATE_KEY }}
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
- name: Adding Known Hosts
run: ssh-keyscan -H kiryuxa.com >> ~/.ssh/known_hosts
- name: Deploy at home lab
run: echo "$(pwd)" && ./tools/scripts/deploy.sh dev
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
MUSE_DOCKER_DEFAULT_CONTEXT: default
MUSE_JWT_SECRET_KEY: ${{ secrets.MUSE_JWT_SECRET_KEY }}
CI: false # https://stackoverflow.com/questions/34917977/disable-npm-warnings-as-errors-build-definition-tfs
deploy-staging:
name: "[SERVER] Deploy to Staging"
if: github.event.ref == 'refs/heads/main'
needs:
- openapi-linter
- client-linter
- client-static-analyzer
- server-linter
- server-static-analyzer
- server-unit-tests
- server-sonarqube
runs-on: ubuntu-22.04
environment:
name: staging
url: http://staging.muse.kiryuxa.com
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: myshx
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/setup-node@v4
with:
node-version: "20.16.0"
- name: "Install `Redocly`"
run: npm i -g @redocly/cli@latest
- name: Cache npm dependencies
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
run: npm install --prefix client
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.DEPLOY_SERVER_SSH_PRIVATE_KEY }}
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
- name: Adding Known Hosts
run: ssh-keyscan -H kiryuxa.com >> ~/.ssh/known_hosts
- name: Deploy at home lab
run: echo "$(pwd)" && ./tools/scripts/deploy.sh staging
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
MUSE_DOCKER_DEFAULT_CONTEXT: default
MUSE_JWT_SECRET_KEY: ${{ secrets.MUSE_JWT_SECRET_KEY }}
CI: false # https://stackoverflow.com/questions/34917977/disable-npm-warnings-as-errors-build-definition-tfs
deploy-prod:
name: "[SERVER] Deploy to Prod"
needs:
- deploy-staging
runs-on: ubuntu-22.04
environment:
name: prod
url: http://prod.muse.kiryuxa.com
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: myshx
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/setup-node@v4
with:
node-version: "20.16.0"
- name: "Install `Redocly`"
run: npm i -g @redocly/cli@latest
- name: Cache npm dependencies
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
run: npm install --prefix client
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.DEPLOY_SERVER_SSH_PRIVATE_KEY }}
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
- name: Adding Known Hosts
run: ssh-keyscan -H kiryuxa.com >> ~/.ssh/known_hosts
- name: Deploy at home lab
run: echo "$(pwd)" && ./tools/scripts/deploy.sh prod
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
MUSE_DOCKER_DEFAULT_CONTEXT: default
MUSE_JWT_SECRET_KEY: ${{ secrets.MUSE_JWT_SECRET_KEY }}
CI: false # https://stackoverflow.com/questions/34917977/disable-npm-warnings-as-errors-build-definition-tfs