-
Notifications
You must be signed in to change notification settings - Fork 26
717 lines (672 loc) · 33.4 KB
/
packages.yaml
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
name: Packages
on:
workflow_dispatch:
inputs:
packages:
description: 'Packages separated by spaces'
required: true
type: string
push:
paths:
- 'packages/**'
pull_request:
paths:
- 'packages/**'
jobs:
common-check:
name: Common checks
uses: ./.github/workflows/common_check.yaml
with:
run_trigger: ${{ github.event_name }}
matrix:
name: Check changes
runs-on: ubuntu-22.04
needs: common-check
if: needs.common-check.outputs.continue == 'true'
outputs:
matrix_publish: ${{ steps.generate-matrix.outputs.matrix_publish }}
publish: ${{ steps.generate-matrix.outputs.publish }}
permissions:
pull-requests: read
steps:
- name: Set git fetch depth
run: |
if [[ ${{ github.event_name }} != 'pull_request' ]]; then
echo "FETCH_DEPTH=2" >> "$GITHUB_ENV"
else
echo "FETCH_DEPTH=0" >> "$GITHUB_ENV"
fi
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
sparse-checkout: |
./packages
- name: Get changed files
uses: tj-actions/changed-files@v42
id: changed-files
with:
files: 'packages/**'
separator: "\n"
dir_names: true
safe_output: false
- name: Generate matrix
id: generate-matrix
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
if [[ "${{ github.event.inputs.packages }}" == "" ]]; then
CHANGED_PACKAGES="$(echo -e "${ALL_CHANGED_FILES}" | awk -F'/' '{print $2}' | sort -u)"
else
CHANGED_PACKAGES="${{ github.event.inputs.packages }}"
fi
MATRIX_PUBLISH_JSON="["
for PACKAGE in $(echo ${CHANGED_PACKAGES} | sort -u); do
DIR="packages/${PACKAGE}"
if [ -f "${DIR}/package.json" ]; then
MATRIX_PUBLISH_JSON+="{\"package\": \"${PACKAGE}\""
current_version="$(jq -r '.version' "${DIR}/package.json")"
MATRIX_PUBLISH_JSON+=", \"version\": \"${current_version}\""
scripts="$(jq '. | select( has("scripts") == true ).scripts' "${DIR}/package.json")"
dependencies="$(jq '(. | select( has("dependencies") == true ).dependencies) * (. | select( has("devDependencies") == true ).devDependencies)' "${DIR}/package.json")"
job_name='Check'
if [ ! -z "$(jq -r '. | select( has("build") == true )' <<< "$scripts")" ]; then
MATRIX_PUBLISH_JSON+=", \"build\": \"build\""
job_name='Build'
fi
unpublished_deps="$(jq -r '. | to_entries | map(select(.value | match("\\.\\./.*")))[] | "\(.key)=\(.value)"' <<<$dependencies | tr '\n' ' ')"
job_test_env=''
if [ -n "$(jq '. | select( has("test") == true )' <<< "$scripts")" ] && \
[[ "$(jq -r '. | select( has("skipCI") == true ).skipCI' "${DIR}/package.json")" != "true" ]] && \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" != "docking" ]]; then
MATRIX_PUBLISH_JSON+=", \"test\": \"test\""
job_name='Build, test'
job_test_env='Datagrok'
grok_deps="$(jq -r '. | select( has("devDependencies") == true ).devDependencies | to_entries[] | .key | select(test("@datagrok/.*")?)' ${DIR}/package.json)"
if [[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" == "chem" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" == "simpkpd" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" == "dendrogram" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" == "cvmtests" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" == "samples" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" == "admetica" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"chem"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"simpkpd"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"cvmtests"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"dendrogram"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"admetica"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"samples"* ]]; then
job_test_env+=',JKG'
fi
if [ -d "${DIR}/dockerfiles" ]; then
job_test_env+=',Spawner'
fi
if [[ "${unpublished_deps}" == "" ]] && [[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" != *"tests"* ]]; then
job_test_env+=' latest version'
else
job_test_env+=' bleeding-edge version'
fi
fi
runner='ubuntu-22.04'
if [[ "${job_test_env}" == *"JKG"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${PACKAGE})" == "admetica" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"admetica"* ]]; then
runner='ubuntu-latest-m'
fi
name="$(jq -r .name "${DIR}/package.json")"
npm_version="$(curl --retry 3 -s "https://registry.npmjs.org/${name}/${current_version}" | jq -r '.? | select( has("version") == true ).version')"
MATRIX_PUBLISH_JSON+=", \"unpublished_deps\": \"$unpublished_deps\""
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
if [[ $npm_version != ${current_version} ]]; then
if [ "$(awk -F. '{print $1}' <<<$current_version)" -gt "0" ]; then
if [[ $unpublished_deps == "" ]]; then
if [[ '${{ github.ref }}' == 'refs/heads/master' ]]; then
publish="publish"
MATRIX_PUBLISH_JSON+=", \"publish\": \"publish\""
job_name+=' and publish to NPM'
else
echo "It is an action for branch other than 'master'. Publish will be skipped."
echo "::notice title=${PACKAGE}::It is an action for branch other than 'master'. Publish will be skipped."
fi
else
echo "Package $PACKAGE version ${current_version} has unpublished dependencies: $unpublished_deps. It is not going to be published"
echo "::notice title=${PACKAGE}::Version ${current_version} has unpublished dependencies and is not going to be published"
fi
else
MATRIX_PUBLISH_JSON+=", \"beta\": \"beta\""
echo "Package $PACKAGE version ${current_version} is under 1.0.0 and is not going to be published"
echo "::notice title=${PACKAGE}::Version ${current_version} is under 1.0.0 and is not going to be published"
fi
else
echo "Package $PACKAGE version ${current_version} already published"
echo "::notice title=${PACKAGE}::Version ${current_version} is already published"
fi
else
echo "It is an actions for PR. Publish will be skipped."
echo "::notice title=${PACKAGE}::It is an actions for PR. Publish will be skipped."
fi
if [[ -d "${DIR}/dockerfiles" ]]; then
build_docker=false
if [[ $publish == "publish" ]] || [[ "${{ github.event.inputs.packages }}" != "" ]]; then
build_docker=true
else
if [[ "${{ steps.changed-files.outputs.all_changed_files }}" == *"${DIR}/dockerfiles"* ]]; then
build_docker=true
fi
fi
MATRIX_PUBLISH_JSON+=", \"build_docker\": \"$build_docker\""
MATRIX_PUBLISH_JSON+=", \"docker\": \"$(find ${DIR}/dockerfiles -type f -name Dockerfile | tr '\n' ' ')\""
fi
if [ -n "${job_test_env}" ]; then
job_name+=": ${job_test_env}"
fi
MATRIX_PUBLISH_JSON+=", \"job_name\": \"${job_name}\""
MATRIX_PUBLISH_JSON+=", \"runner\": \"${runner}\""
MATRIX_PUBLISH_JSON+="}"
fi
done
MATRIX_PUBLISH_JSON="${MATRIX_PUBLISH_JSON//\}\{/\}, \{}"
MATRIX_PUBLISH_JSON+="]"
PUBLISH_JSON="{\"include\": ${MATRIX_PUBLISH_JSON}}"
CONTINUE_PUBLISH_JOB="no"
if [[ "${MATRIX_PUBLISH_JSON}" != "[]" ]]; then
CONTINUE_PUBLISH_JOB="yes"
fi
echo "publish=${CONTINUE_PUBLISH_JOB}" >> $GITHUB_OUTPUT
echo "matrix_publish=${PUBLISH_JSON}" >> $GITHUB_OUTPUT
- name: Output
run: |
echo -e "matrix_publish: ${{ steps.generate-matrix.outputs.matrix_publish }}"
echo -e "publish: ${{ steps.generate-matrix.outputs.publish }}"
publish:
name: "${{ matrix.package }}: ${{ matrix.job_name }}"
needs:
- matrix
- common-check
if: needs.matrix.outputs.publish == 'yes' && needs.common-check.outputs.continue == 'true'
runs-on: ${{ matrix.runner }}
env:
HOST: GitHubAction
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.matrix_publish) }}
permissions:
actions: write
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.WRITE_TOKEN || github.token }}
sparse-checkout: |
./libraries
./packages
./js-api
./.github
./docker
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
scope: '@datagrok'
cache: 'npm'
cache-dependency-path: |
packages/${{ matrix.package }}/package-lock.json
- name: Upgrade npm
run: npm install -g npm@x
- name: npm version
run: npm version
- name: unpublished dependencies in package-lock.json
id: package-lock
if: ${{ matrix.unpublished_deps == '' }}
run: grep -q '\.\./\.\./' package-lock.json && rm -f package-lock.json || true
working-directory: packages/${{ matrix.package }}
- name: npm install
run: npm install
id: install
working-directory: packages/${{ matrix.package }}
- name: Get build info
id: info
run: |
commit_sha=$(echo ${{ github.sha }} | cut -c1-8)
echo "commit_sha=$commit_sha" >> $GITHUB_OUTPUT
- name: Run datagrok stand
id: datagrok-image
if: ${{ matrix.test == 'test' }}
run: |
echo "Find grok dependencies packages"
grok_deps="$(jq -r '. | select( has("devDependencies") == true ).devDependencies | to_entries[] | .key | select(test("@datagrok/.*")?)' packages/${{ matrix.package }}/package.json)"
# if [[ "$(tr '[:upper:]' '[:lower:]' <<<${{ matrix.package }})" == "chem" ]] ||
# [[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"chem"* ]] ||
# [[ "$(tr '[:upper:]' '[:lower:]' <<<${{ matrix.package }})" == "ketchersketcher" ]] ||
# [[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"ketchersketcher"* ]]; then
# if [[ "${{ matrix.unpublished_deps }}" == "" ]]; then
# echo 'Use test stand for tests'
# apiUrl='https://test.datagrok.ai/api'
# alias=test
# else
# echo 'Use dev stand for tests'
# apiUrl='https://dev.datagrok.ai/api'
# alias=dev
# fi
# else
profiles='--profile datagrok --profile db'
echo "Check if Grok Connect is required for the package"
if [ -d "packages/${{ matrix.package }}/connections" ] || [[ -n $(find packages/${{ matrix.package }}/node_modules/@datagrok -type d -name connections) ]] || \
[ -d "packages/${{ matrix.package }}/queries" ] || [[ -n $(find packages/${{ matrix.package }}/node_modules/@datagrok -type d -name queries) ]]; then
profiles+=' --profile grok_connect'
fi
echo "Check if CVM is required for the package"
if [[ "$(tr '[:upper:]' '[:lower:]' <<<${{ matrix.package }})" == "chem" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${{ matrix.package }})" == "simpkpd" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${{ matrix.package }})" == "dendrogram" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${{ matrix.package }})" == "cvmtests" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${{ matrix.package }})" == "samples" ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"chem"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"simpkpd"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"cvmtests"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"dendrogram"* ]] || \
[[ "$(tr '[:upper:]' '[:lower:]' <<<${grok_deps})" == *"samples"* ]]; then
echo "Add Scripting as dependency for package ${{ matrix.package }}"
profiles+=' --profile scripting'
fi
echo "Check if Grok Spawner is required for the package"
if [ -d "packages/${{ matrix.package }}/dockerfiles" ]; then
profiles+=' --profile grok_spawner'
fi
echo "Run datagrok stand with profiles ${profiles}"
# docker system prune -af --volumes
if [[ "${{ matrix.unpublished_deps }}" == "" ]] && [[ "$(tr '[:upper:]' '[:lower:]' <<<${{ matrix.package }})" != *"tests"* ]]; then
DATAGROK_VERSION='latest'
else
DATAGROK_VERSION='bleeding-edge'
export GROK_SPAWNER_VERSION='bleeding-edge'
export GROK_JUPYTER_KERNEL_GATEWAY_VERSION='bleeding-edge'
fi
export DATAGROK_VERSION
# Skip initial setup in CI
sed -i '/"dbServer": "database"/a\ \ \ \ \ \ \ \ \ \ "initialSetupCompleted": true,' docker/localhost.docker-compose.yaml
docker compose -p datagrok -f "docker/localhost.docker-compose.yaml" ${profiles} up -d
echo "Set docker_sha"
docker_sha=$(docker images --quiet "datagrok/datagrok:$DATAGROK_VERSION")
echo "docker_sha=$docker_sha" >> $GITHUB_OUTPUT
echo "Notify about version used for tests"
echo "::notice title=${{ matrix.package }}::datagrok/datagrok:$DATAGROK_VERSION SHA=$docker_sha docker version was used for tests"
df -h
apiUrl='http://127.0.0.1:8080/api'
alias=${HOST}
# fi
echo "apiUrl=$apiUrl" >> $GITHUB_OUTPUT
echo "alias=$alias" >> $GITHUB_OUTPUT
- id: datagrok-tools
run: npm install -g datagrok-tools@latest
- if: ${{ matrix.unpublished_deps != '' }}
run: grok link
working-directory: packages/${{ matrix.package }}
- name: webpack cache
uses: actions/cache@v4
with:
path: packages/${{ matrix.package }}/node_modules/.cache/webpack/
key: ${{ matrix.package }}-${{ github.ref_name }}-webpack-build
restore-keys: |
${{ matrix.package }}-master-webpack-build
- name: Remove GPU from docker configuration
if: matrix.docker != '' && steps.datagrok-image.outcome == 'success'
run: |
for dockerfile in $(echo -e ${{ matrix.docker }}); do
docker_config_file="$(dirname $dockerfile)/container.json"
if [ -f "${docker_config_file}" ]; then
jq 'del(.gpu)' ${docker_config_file} > temp.json && mv temp.json ${docker_config_file}
fi
done
- name: Build package
if: ${{ matrix.build == 'build' }}
id: build
run: |
if [[ $(jq -r '. | select( has("scripts") == true ).scripts | select( has("build") == true ).build' "package.json") == "webpack" ]]; then
npm run build -- --mode=production
else
npm run build
fi
working-directory: packages/${{ matrix.package }}
- name: Wait for Datagrok to become available
if: ${{ matrix.test == 'test' }}
timeout-minutes: 5
run: |
until .github/scripts/check-output.sh "curl -s ${{ steps.datagrok-image.outputs.apiUrl }}/info/server" '"Http Server"'
do
sleep 1
if [[ "${{ steps.datagrok-image.outputs.apiUrl }}" == *"127.0.0.1"* ]]; then
docker compose -p datagrok logs --no-color --timestamps datagrok
fi
echo -e "\nRetrying..."
done
curl -s ${{ steps.datagrok-image.outputs.apiUrl }}/info/server
curl -s ${{ steps.datagrok-image.outputs.apiUrl }}/admin/health
token=$(curl -s -X POST ${{ steps.datagrok-image.outputs.apiUrl }}/users/login/dev/admin | jq -r .token)
curl -s -H "Authorization: $token" -H "Content-Type": "application/json" '${{ steps.datagrok-image.outputs.apiUrl }}/admin/plugins/admin/settings' -X POST -d '{"#type":"AdminPluginSettings", "agreementDate":null}'
- name: Create configuration for grok command-line tool
if: ${{ matrix.test == 'test' }}
id: grok-config
env:
DEV_TEST_DEV_KEY: ${{ secrets.DEV_TEST_DEV_KEY }}
TEST_TEST_DEV_KEY: ${{ secrets.TEST_TEST_DEV_KEY }}
run: |
if [[ "${{ steps.datagrok-image.outputs.alias }}" == "test" ]]; then
key="$TEST_TEST_DEV_KEY"
elif [[ "${{ steps.datagrok-image.outputs.alias }}" == "dev" ]]; then
key="$DEV_TEST_DEV_KEY"
else
key='admin'
fi
grok config add --default --alias ${{ steps.datagrok-image.outputs.alias }} --server '${{ steps.datagrok-image.outputs.apiUrl }}' --key "$key"
- name: Install Grok Dependencies before package publish to Datagrok
if: ${{ matrix.test == 'test' }}
run: |
grok_deps="$(jq -r '. | select( has("devDependencies") == true ).devDependencies | to_entries[] | .key | select(test("@datagrok/.*")?)' package.json)"
if [ -n "$grok_deps" ]; then
for dep in $grok_deps; do
current_dir=$(pwd)
cd node_modules/$dep
count=0
retries=5
echo "Publishing $dep to ${{ steps.datagrok-image.outputs.alias }}..."
until grok publish ${{ steps.datagrok-image.outputs.alias }} --release; do
exit=$?
wait=$((2 ** count))
count=$((count + 1))
if [ $count -lt "$retries" ]; then
echo "Retry $count/$retries exited $exit, retrying 'grok publish ${{ steps.datagrok-image.outputs.alias }}' for $dep in $wait seconds..."
sleep $wait
else
echo "Retry $count/$retries exited $exit, no more retries left for 'grok publish ${{ steps.datagrok-image.outputs.alias }}' for $dep."
exit $exit
fi
done
cd $current_dir
done
fi
working-directory: packages/${{ matrix.package }}
- name: Publish package to Datagrok
if: ${{ matrix.test == 'test' }}
run: |
count=0
retries=5
until grok publish ${{ steps.datagrok-image.outputs.alias }} --release; do
exit=$?
if [[ "${{ steps.datagrok-image.outputs.apiUrl }}" == *"127.0.0.1"* ]]; then
docker compose -p datagrok logs --no-color --timestamps datagrok
fi
wait=$((2 ** count))
count=$((count + 1))
if [ "$count" -lt "$retries" ]; then
echo "Retry $count/$retries exited $exit, retrying 'grok publish ${{ steps.datagrok-image.outputs.alias }}' in $wait seconds..."
sleep $wait
else
echo "Retry $count/$retries exited $exit, no more retries left for 'grok publish ${{ steps.datagrok-image.outputs.alias }}'."
exit $exit
fi
done
working-directory: packages/${{ matrix.package }}
- name: Set required credentials
if: ${{ matrix.test == 'test' }}
env:
CHEMSPACE_APIKEY: ${{ secrets.CHEMSPACE_APIKEY }}
run: |
if [[ "${{ steps.datagrok-image.outputs.apiUrl }}" == *"127.0.0.1"* ]]; then
if [[ "${{ matrix.package }}" == "Chemspace" ]]; then
token=$(curl -s -X POST ${{ steps.datagrok-image.outputs.apiUrl }}/users/login/dev/admin | jq -r .token)
curl -s -H "Authorization: $token" -H "Content-Type": "application/json" '${{ steps.datagrok-image.outputs.apiUrl }}/credentials/for/Chemspace.Chemspace' -X POST -d "{\"apiKey\": \"$CHEMSPACE_APIKEY\"}"
fi
fi
- name: Wait for published docker to become available
id: docker-wait
if: matrix.docker != '' && steps.datagrok-image.outcome == 'success'
env:
DEV_TEST_DEV_KEY: ${{ secrets.DEV_TEST_DEV_KEY }}
TEST_TEST_DEV_KEY: ${{ secrets.TEST_TEST_DEV_KEY }}
timeout-minutes: 20
run: |
check_container=false
for dockerfile in $(echo -e ${{ matrix.docker }}); do
docker_config_file="$(dirname $dockerfile)/container.json"
if [ -f "${docker_config_file}" ]; then
on_demand=$(jq '.on_demand' ${docker_config_file})
if [ "$on_demand" == "true" ]; then
check_container=false
else
check_container=true
break
fi
else
check_container=true
break
fi
done
if [[ "${check_container}" == "true" ]] ; then
if [[ "${{ steps.datagrok-image.outputs.alias }}" == "test" ]]; then
key="$TEST_TEST_DEV_KEY"
elif [[ "${{ steps.datagrok-image.outputs.alias }}" == "dev" ]]; then
key="$DEV_TEST_DEV_KEY"
else
key='admin'
fi
token=$(curl -s -X POST ${{ steps.datagrok-image.outputs.apiUrl }}/users/login/dev/$key | jq -r .token)
long_term_token=$(curl -s -X POST ${{ steps.datagrok-image.outputs.apiUrl }}/users/sessions/current/refresh -H "Authorization: ${token}" | jq -r .token)
until .github/scripts/check-output.sh "curl -s -H 'Authorization: $long_term_token' '${{ steps.datagrok-image.outputs.apiUrl }}/docker/containers'" '${{ matrix.package }}'
do
docker compose -p datagrok -f "docker/localhost.docker-compose.yaml" --profile all exec db psql -U postgres -d datagrok -c "SELECT * FROM docker_containers;"
.github/scripts/check-output.sh "curl -s -H 'Authorization: $token' '${{ steps.datagrok-image.outputs.apiUrl }}/docker/containers'" '${{ matrix.package }}'
sleep 1
echo -e "\nContainer for ${{ matrix.package }} did not start yet..."
echo -e "\nRetrying '/api/docker/containers'..."
done
if [[ "${{ steps.datagrok-image.outputs.apiUrl }}" == *"127.0.0.1"* ]]; then
until .github/scripts/check-output.sh "docker ps" '${{ matrix.package }}'
do
sleep 1
echo -e "\nContainer for ${{ matrix.package }} did not start yet..."
echo -e "\nRetrying 'docker ps'..."
done
fi
fi
- name: Test Package
if: ${{ matrix.test == 'test' }}
continue-on-error: ${{ contains(matrix.package, 'Tests') || matrix.package == 'Chemspace' }}
timeout-minutes: 30
id: test-package
run: npm run test -- --skip-build --skip-publish --record --csv --host ${{ steps.datagrok-image.outputs.alias }} --verbose
working-directory: packages/${{ matrix.package }}
- name: Upload Artifact
if: always() && steps.test-package.outcome != 'skipped'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.package }}.test-results
path: packages/${{ matrix.package }}/test-*
retention-days: 14
if-no-files-found: warn
- name: Create error notification
if: failure() && (steps.test-package.outcome == 'failure' || steps.docker-wait.outcome == 'failure')
run: |
if [[ "${{ steps.datagrok-image.outputs.apiUrl }}" == *"127.0.0.1"* ]]; then
docker compose -p datagrok logs --no-color --timestamps
else
echo 'Check dev logs'
fi
echo "::error title=${{ matrix.package }}: failed tests::Check job output for details"
echo "status=error" >> $GITHUB_OUTPUT
- name: Get docker image version
if: matrix.build_docker == 'true'
id: docker_name_ver
working-directory: packages/${{ matrix.package }}
run: |
image_ver=$(jq -r .version package.json)
if [[ "${{ matrix.publish }}" != "publish" ]]; then
image_ver+="-${{ steps.info.outputs.commit_sha }}"
fi
echo "image_ver=$image_ver" >> $GITHUB_OUTPUT
echo "package_name=$(jq -r .name package.json | sed -e 's,@datagrok/,,g')" >> $GITHUB_OUTPUT
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
if: steps.docker_name_ver.outcome == 'success'
- name: Build package Docker image
if: steps.docker_name_ver.outcome == 'success'
id: build-docker
run: |
for dockerfile in $(echo -e ${{ matrix.docker }}); do
image_name=${{ steps.docker_name_ver.outputs.package_name }}
if [[ $(dirname $dockerfile) != *"dockerfiles" ]]; then
image_name+="-$(dirname $dockerfile | awk -F/ '{print $NF}')"
fi
cache_args="--cache-from type=registry,ref=datagrok/${image_name}:cache"
if [ '${{ github.ref }}' == 'refs/heads/master' ]; then
cache_args+=" --cache-to type=registry,ref=datagrok/${image_name}:cache"
fi
docker buildx create --use
docker buildx build $(dirname $dockerfile) --load \
--tag datagrok/${image_name}:${{ steps.docker_name_ver.outputs.image_ver }} \
$cache_args
images+=" datagrok/${image_name}:${{ steps.docker_name_ver.outputs.image_ver }}"
done
echo "images=$images" >> $GITHUB_OUTPUT
- name: General checks
run: |
if [[ "$(jq '.name' package.json | sed -E 's/(^"|"$)//g')" != "@datagrok/"* ]]; then
echo "::error title=${{ matrix.package }}: failed properties check::Package should be in '@datagrok' scope. Change package name to '@datagrok/<name>' in ${{ matrix.package }}/package.json"
exit 1
fi
if [ ! -z "$(jq '. | select( has("beta") == true ).beta' package.json)" ]; then
echo "::error title=${{ matrix.package }}: failed properties check::Remove beta property in ${{ matrix.package }}/package.json. It is deprecated."
exit 1
fi
id: gen_checks
working-directory: packages/${{ matrix.package }}
- run: grok check
if: ${{ !contains(matrix.package, 'Tests') && !contains(matrix.package, 'Meta') && matrix.beta != 'true' }}
id: check
working-directory: packages/${{ matrix.package }}
- name: Publish to npm
run: npm publish --access public
id: publish
working-directory: packages/${{ matrix.package }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: matrix.publish == 'publish' && (steps.build.outcome == 'success' || steps.build.outcome == 'skipped') && steps.gen_checks.outcome == 'success' && (steps.check.outcome == 'success' || steps.check.outcome == 'skipped') && steps.install.outcome == 'success' && (steps.test-package.outcome == 'success' || steps.test-package.outcome == 'skipped' || (contains(matrix.package, 'Tests') || matrix.package == 'Chemspace'))
- name: Get actors slack
id: actor
uses: ./.github/actions/slack-user-action
with:
slack-token: ${{ secrets.SLACKBOT_TOKEN }}
email-mapping: ${{ secrets.EMAIL_SLACK_ID }}
- name: Get owner email
run: echo "owner=$(jq -r .author.email package.json)" >> $GITHUB_OUTPUT
id: owner-email
working-directory: packages/${{ matrix.package }}
- name: Get owners slack
id: owner
uses: ./.github/actions/slack-user-action
with:
slack-token: ${{ secrets.SLACKBOT_TOKEN }}
emails: ${{ steps.owner-email.outputs.owner }}
- name: Get QA slack
id: qa
uses: ./.github/actions/slack-user-action
if: ${{ (matrix.package == 'Tutorials' || matrix.package == 'Chem' || matrix.package == 'DiffStidio' || matrix.package == 'PowerPack') }}
with:
slack-token: ${{ secrets.SLACKBOT_TOKEN }}
emails: "[email protected]"
- name: Prepare Slack Message
id: slack-prepare
if: ${{ steps.publish.outcome == 'success' && !contains(matrix.package, 'Meta') }}
shell: bash
run: |
mentions=$(echo -e "${{ steps.actor.outputs.user-ids }}\n${{ steps.owner.outputs.user-ids }}\n${{ steps.qa.outputs.user-ids }}" | sort -u)
header="Package *${{ matrix.package }}* version *${{ matrix.version }}* published to <https://www.npmjs.com/package/$(jq -r .name "packages/${{ matrix.package }}/package.json")/v/${{ matrix.version }}|NPM>\n$(for value in $mentions; do echo -n "<@$value> "; done) FYI"
echo "SLACK_MESSAGE_HEADER=$header" >> $GITHUB_ENV
- name: Send to Slack
id: slack
if: steps.slack-prepare.outcome == 'success'
uses: ./.github/actions/slack-post-action
with:
channel: '#build'
slack-token: ${{ secrets.SLACKBOT_TOKEN }}
message: ${{ env.SLACK_MESSAGE_HEADER }}
- name: Save package Docker image to tar archive
if: steps.build-docker.outcome == 'success' && (steps.publish.outcome == 'failure' || steps.publish.outcome == 'skipped')
id: save-docker
run: |
docker save -o /tmp/${{ matrix.package }}.docker.tar ${{ steps.build-docker.outputs.images }}
- uses: actions/upload-artifact@v4
if: steps.save-docker.outcome == 'success'
with:
path: /tmp/${{ matrix.package }}.docker.tar
name: ${{ matrix.package }}.docker.tar
retention-days: 14
if-no-files-found: warn
- name: Publish package Docker image
if: steps.publish.outcome == 'success' && steps.build-docker.outcome == 'success'
id: publish-docker
run: |
for image in $(echo -e ${{ steps.build-docker.outputs.images }}); do
docker push $image
done
- name: Commit package-lock.json
id: git
continue-on-error: true
if: steps.publish.outcome == 'success' || steps.package-lock.outcome == 'success'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git pull
continue=false
if [ -n "$(git status -s packages/${{ matrix.package }}/package-lock.json)" ]; then
git add packages/${{ matrix.package }}/package-lock.json
skip_ci=""
if [ ${{ github.ref }} == 'refs/heads/master' ]; then
skip_ci="[skip ci]"
fi
git commit -m "GitHub Actions: Update packages/${{ matrix.package }}/package-lock.json $skip_ci
Workflow ${{ github.workflow }} ${{ github.run_number }}
https://github.com/datagrok-ai/public/actions/runs/${{ github.run_id }}"
continue=true
fi
if [[ "${continue}" == "true" ]]; then
count=0
retries=10
until git push; do
exit=$?
wait=$((2 ** count))
count=$((count + 1))
if [ $count -lt "$retries" ]; then
echo "Retry $count/$retries exited $exit, retrying 'git push' in $wait seconds..."
sleep $wait
git pull --rebase
else
echo "Retry $count/$retries exited $exit, no more retries left for 'git push'."
exit $exit
fi
done
fi
- name: Trigger help update
continue-on-error: true
if: steps.publish.outcome == 'success'
run: gh workflow run docusaurus.yaml --ref ${{ github.ref }}
env:
GH_TOKEN: ${{ github.token }}
# - name: Slack Notification
# uses: act10ns/[email protected]
# with:
# status: ${{ steps.publish.outcome }}
# steps: ${{ toJson(steps) }}
# matrix: ${{ toJson(matrix) }}
# config: ".github/config/slack.yml"
# webhook-url: ${{ secrets.SLACK_WEBHOOK_REPORT }}
# - name: Slack Failed-Cancelled Notification
# if: failure() || cancelled()
# uses: act10ns/[email protected]
# with:
# status: ${{ job.status }}
# steps: ${{ toJson(steps) }}
# config: ".github/config/slack.yml"
# webhook-url: ${{ secrets.SLACK_WEBHOOK_REPORT }}