/
pull-requests-custom-branch-console-only.yml
386 lines (380 loc) · 13.2 KB
/
pull-requests-custom-branch-console-only.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# This configuration has been automatically generated by the CircleCI Config SDK.
# For more information, see https://github.com/CircleCI-Public/circleci-config-sdk-ts
# SDK Version: 0.0.0-development
version: 2.1
setup: false
parameters:
gio_action:
type: string
default: pull_requests
description: ""
dry_run:
type: boolean
default: true
description: Run in dry run mode?
docker_tag_as_latest:
type: boolean
default: false
description: Is this version the latest version available?
graviteeio_version:
type: string
default: ""
description: Version of APIM to be used in docker images
apim_version_path:
type: string
default: /home/circleci/project/pom.xml
description: Path to pom.xml with APIM version
commands:
cmd-webui-install:
parameters:
apim-ui-project:
type: string
default: ""
description: the name of the UI project to build
steps:
- restore_cache:
name: Restore NPM cache
keys:
- << parameters.apim-ui-project >>-cache-v1-{{ .Branch }}-{{ checksum "<< parameters.apim-ui-project >>/package-lock.json" }}
- << parameters.apim-ui-project >>-cache-v1-{{ .Branch }}
- run:
name: Install dependencies
command: npm install
working_directory: << parameters.apim-ui-project >>
- save_cache:
name: Save NPM cache
key: << parameters.apim-ui-project >>-cache-v1-{{ .Branch }}-{{ checksum "<< parameters.apim-ui-project >>/package-lock.json" }}
paths:
- ./<< parameters.apim-ui-project >>/node_modules
cmd-notify-on-failure:
steps:
- keeper/env-export:
secret-url: keeper://ZOz4db245GNaETVwmPBk8w/field/password
var-name: SLACK_ACCESS_TOKEN
- slack/notify:
channel: C02JENTV2AX
branch_pattern: master,[0-9]+\.[0-9]+\.x
event: fail
template: basic_fail_1
cmd-create-docker-context:
steps:
- run:
name: Create docker context for buildx
command: |-
docker context create tls-env
docker buildx create tls-env --use
cmd-docker-azure-login:
steps:
- keeper/env-export:
secret-url: keeper://Q721P2LSOPJ9qiXLuf5AHQ/field/login
var-name: AZURE_DOCKER_REGISTRY_USERNAME
- keeper/env-export:
secret-url: keeper://Q721P2LSOPJ9qiXLuf5AHQ/field/password
var-name: AZURE_DOCKER_REGISTRY_PASSWORD
- run:
name: Login to Azure Container Registry
command: echo $AZURE_DOCKER_REGISTRY_PASSWORD | docker login --username $AZURE_DOCKER_REGISTRY_USERNAME --password-stdin graviteeio.azurecr.io
description: Login to Azure Container Registry
cmd-docker-azure-logout:
steps:
- run:
name: Logout from Azure Container Registry
command: docker logout graviteeio.azurecr.io
description: Logout from Azure Container Registry
cmd-build-ui-image:
parameters:
docker-image-name:
type: string
default: ""
description: the name of the image
apim-ui-project:
type: string
default: ""
description: the name of the UI project to build
steps:
- cmd-create-docker-context
- cmd-docker-azure-login
- run:
name: Build UI docker image
command: |-
docker buildx build --push --platform=linux/arm64,linux/amd64 -f docker/Dockerfile \
-t graviteeio.azurecr.io/<< parameters.docker-image-name >>:apim-1234-my-custom-branch-latest \
.
working_directory: << parameters.apim-ui-project >>
- cmd-docker-azure-logout
cmd-restore-maven-job-cache:
parameters:
jobName:
type: string
default: ""
description: The job name
steps:
- restore_cache:
keys:
- gravitee-api-management-v9-<< parameters.jobName >>-{{ .Branch }}-{{ checksum "pom.xml" }}
- gravitee-api-management-v9-<< parameters.jobName >>-{{ .Branch }}
- gravitee-api-management-v9-<< parameters.jobName >>
description: Restore Maven cache for a dedicated job
cmd-save-maven-job-cache:
parameters:
jobName:
type: string
default: ""
description: The job name
steps:
- run:
name: Exclude all APIM artefacts from cache.
command: rm -rf ~/.m2/repository/io/gravitee/apim
- save_cache:
key: gravitee-api-management-v9-<< parameters.jobName >>-{{ .Branch }}-{{ checksum "pom.xml" }}
paths:
- ~/.m2
when: always
description: Save Maven cache for a dedicated job
jobs:
job-webui-lint-test:
parameters:
apim-ui-project:
type: string
default: ""
description: the name of the UI project to build
resource_class:
type: string
default: medium
description: Resource class to use for executor
node_version:
type: string
default: "20.11"
description: Node version to use for executor
docker:
- image: cimg/node:<< parameters.node_version >>
resource_class: << parameters.resource_class >>
steps:
- checkout
- cmd-webui-install:
apim-ui-project: << parameters.apim-ui-project >>
- attach_workspace:
at: .
- run:
name: Check License
command: npm run lint:license
working_directory: << parameters.apim-ui-project >>
- run:
name: Run Prettier and ESLint
command: npm run lint
working_directory: << parameters.apim-ui-project >>
- run:
name: Run unit tests
command: npm run test:coverage
working_directory: << parameters.apim-ui-project >>
- cmd-notify-on-failure
- persist_to_workspace:
root: .
paths:
- << parameters.apim-ui-project >>/coverage/lcov.info
- store_artifacts:
path: << parameters.apim-ui-project >>/coverage/lcov.info
- store_test_results:
path: << parameters.apim-ui-project >>/coverage/junit.xml
job-webui-build:
parameters:
apim-ui-project:
type: string
default: ""
description: the name of the UI project to build
docker-image-name:
type: string
default: ""
description: the name of the image
node_version:
type: string
default: "20.11"
description: Node version to use for executor
docker:
- image: cimg/node:<< parameters.node_version >>
resource_class: large
steps:
- checkout
- attach_workspace:
at: .
- setup_remote_docker:
version: default
- cmd-webui-install:
apim-ui-project: << parameters.apim-ui-project >>
- run:
name: Update Build version
command: "sed -i 's/\"version\": \".*\"/\"version\": \"4.2.0\"/' << parameters.apim-ui-project >>/build.json"
- run:
name: Build
command: npm run build:prod
environment:
NODE_OPTIONS: --max_old_space_size=4086
working_directory: << parameters.apim-ui-project >>
- cmd-build-ui-image:
docker-image-name: << parameters.docker-image-name >>
apim-ui-project: << parameters.apim-ui-project >>
- cmd-notify-on-failure
- persist_to_workspace:
root: .
paths:
- << parameters.apim-ui-project >>/dist
job-console-webui-build-storybook:
parameters:
node_version:
type: string
default: "20.11"
description: Node version to use for executor
docker:
- image: cimg/node:<< parameters.node_version >>
resource_class: large
steps:
- checkout
- cmd-webui-install:
apim-ui-project: gravitee-apim-console-webui
- run:
name: Build
command: npm run build-storybook
working_directory: gravitee-apim-console-webui
environment:
NODE_OPTIONS: --max_old_space_size=8192
- cmd-notify-on-failure
- persist_to_workspace:
root: .
paths:
- gravitee-apim-console-webui/storybook-static
job-console-webui-chromatic-deployment:
parameters:
node_version:
type: string
default: "20.11"
description: Node version to use for executor
docker:
- image: cimg/node:<< parameters.node_version >>
resource_class: small
steps:
- checkout
- attach_workspace:
at: .
- cmd-webui-install:
apim-ui-project: gravitee-apim-console-webui
- keeper/env-export:
secret-url: keeper://TIlcGPFq4rN5GvgnZb9hng/field/password
var-name: GITHUB_TOKEN
- keeper/env-export:
secret-url: keeper://Hp1bFl5s0doxnQgqkMdCdg/field/password
var-name: CHROMATIC_PROJECT_TOKEN
- run:
name: Running Chromatic
command: |-
SB_URL=$(cd gravitee-apim-console-webui && npx chromatic --project-token=$CHROMATIC_PROJECT_TOKEN --exit-once-uploaded -d=storybook-static | grep -o "View your Storybook at https:\/\/[0-9a-z-]*\.chromatic\.com" | grep -o "https:.*")
echo "export SB_URL=$SB_URL" >> $BASH_ENV
- gh/setup
- run:
name: Edit Pull Request Description
command: |-
# First check there is an associated pull request, otherwise just stop the job here
if ! gh pr view --json title;
then
echo "No PR found for this branch, stopping the job here."
exit 0
fi
# If PR state is different from OPEN
if [ "$(gh pr view --json state --jq .state)" != "OPEN" ];
then
echo "PR is not opened, stopping the job here."
exit 0
fi
export PR_BODY_STORYBOOK_SECTION="
<!-- Storybook placeholder -->
---
📚 View the storybook of this branch [here](${SB_URL})
<!-- Storybook placeholder end -->
"
export CLEAN_BODY=$(gh pr view --json body --jq .body | sed '/Storybook placeholder -->/,/Storybook placeholder end -->/d')
gh pr edit --body "$CLEAN_BODY$PR_BODY_STORYBOOK_SECTION"
- cmd-notify-on-failure
job-sonarcloud-analysis:
parameters:
working_directory:
type: string
default: gravitee-apim-rest-api
description: Directory where the Sonarcloud analysis will be run
docker:
- image: sonarsource/sonar-scanner-cli:5.0.1
resource_class: large
steps:
- run:
name: Add SSH tool
command: apk add --no-cache openssh
- checkout
- attach_workspace:
at: .
- restore_cache:
keys:
- gravitee-api-management-v9-sonarcloud-analysis-<< parameters.working_directory >>-{{ .Branch }}-{{ checksum "pom.xml" }}
- gravitee-api-management-v9-sonarcloud-analysis-<< parameters.working_directory >>-{{ .Branch }}
- gravitee-api-management-v9-sonarcloud-analysis-<< parameters.working_directory >>
- keeper/env-export:
secret-url: keeper://9x9YgyU6DWzux4DPoHAzDQ/field/password
var-name: SONAR_TOKEN
- run:
name: Run Sonarcloud Analysis
command: sonar-scanner -Dsonar.projectVersion=4.2.0
working_directory: << parameters.working_directory >>
- cmd-notify-on-failure
- save_cache:
paths:
- /opt/sonar-scanner/.sonar/cache
key: gravitee-api-management-v9-sonarcloud-analysis-<< parameters.working_directory >>-{{ .Branch }}-{{ checksum "pom.xml" }}
when: always
job-validate-workflow-status:
docker:
- image: cimg/base:stable
resource_class: small
steps:
- run:
name: Check workflow jobs
command: echo "Congratulations! If you can read this, everything is OK"
workflows:
pull_requests:
jobs:
- job-webui-lint-test:
name: Lint & test APIM Console
context:
- cicd-orchestrator
apim-ui-project: gravitee-apim-console-webui
resource_class: xlarge
- job-webui-build:
name: Build APIM Console and publish image
context:
- cicd-orchestrator
apim-ui-project: gravitee-apim-console-webui
docker-image-name: apim-management-ui
- job-console-webui-build-storybook:
name: Build Console Storybook
context:
- cicd-orchestrator
node_version: "20.11"
- job-console-webui-chromatic-deployment:
name: Deploy console in chromatic
context:
- cicd-orchestrator
requires:
- Build Console Storybook
node_version: "20.11"
- job-sonarcloud-analysis:
name: Sonar - gravitee-apim-console-webui
context:
- cicd-orchestrator
requires:
- Lint & test APIM Console
working_directory: gravitee-apim-console-webui
- job-validate-workflow-status:
name: Validate workflow status
requires:
- Lint & test APIM Console
- Build APIM Console and publish image
orbs:
keeper: gravitee-io/keeper@0.6.3
slack: circleci/slack@4.12.5
gh: circleci/github-cli@1.0.5