forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.star
1453 lines (1298 loc) · 47 KB
/
lib.star
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
This module is a library of Drone steps and other pipeline components.
"""
load(
"scripts/drone/steps/rgm.star",
"rgm_build_backend_step",
)
load(
"scripts/drone/utils/images.star",
"images",
)
load(
"scripts/drone/variables.star",
"grabpl_version",
)
load(
"scripts/drone/vault.star",
"from_secret",
"gcp_grafanauploads",
"gcp_grafanauploads_base64",
"gcp_upload_artifacts_key",
"npm_token",
"prerelease_bucket",
)
trigger_oss = {
"repo": [
"grafana/grafana",
],
}
def yarn_install_step():
return {
"name": "yarn-install",
"image": images["node"],
"commands": [
"yarn install --immutable || yarn install --immutable",
],
"depends_on": [],
}
def wire_install_step():
return {
"name": "wire-install",
"image": images["go"],
"commands": [
"apk add --update make",
"make gen-go",
],
"depends_on": [
"verify-gen-cue",
],
}
def identify_runner_step():
return {
"name": "identify-runner",
"image": images["alpine"],
"commands": [
"echo $DRONE_RUNNER_NAME",
],
}
def enterprise_setup_step(source = "${DRONE_SOURCE_BRANCH}", canFail = True, isPromote = False):
"""Setup the enterprise source into the ./grafana-enterprise directory.
Args:
source: controls which revision of grafana-enterprise is checked out, if it exists. The name 'source' derives from the 'source branch' of a pull request.
canFail: controls whether the step can fail. This is useful for pull requests where the enterprise source may not exist.
isPromote: controls whether or not this step is being used in a promote pipeline. If it is, then the clone enterprise step will not check if the pull request is a fork.
Returns:
Drone step.
"""
step = clone_enterprise_step_pr(source = source, target = "${DRONE_TARGET_BRANCH}", canFail = canFail, location = "../grafana-enterprise", isPromote = isPromote)
step["commands"] += [
"cd ../",
"ln -s src grafana",
"cd ./grafana-enterprise",
"./build.sh",
]
return step
def clone_enterprise_step_pr(source = "${DRONE_COMMIT}", target = "main", canFail = False, location = "grafana-enterprise", isPromote = False):
"""Clone the enterprise source into the ./grafana-enterprise directory.
Args:
source: controls which revision of grafana-enterprise is checked out, if it exists. The name 'source' derives from the 'source branch' of a pull request.
target: controls which revision of grafana-enterprise is checked out, if it 'source' does not exist. The name 'target' derives from the 'target branch' of a pull request. If this does not exist, then 'main' will be checked out.
canFail: controls whether or not this step is allowed to fail. If it fails and this is true, then the pipeline will continue. canFail is used in pull request pipelines where enterprise may be cloned but may not clone in forks.
location: the path where grafana-enterprise is cloned.
isPromote: controls whether or not this step is being used in a promote pipeline. If it is, then the step will not check if the pull request is a fork.
Returns:
Drone step.
"""
if isPromote:
check = []
else:
check = [
'is_fork=$(curl --retry 5 "https://$GITHUB_TOKEN@api.github.com/repos/grafana/grafana/pulls/$DRONE_PULL_REQUEST" | jq .head.repo.fork)',
'if [ "$is_fork" != false ]; then return 1; fi', # Only clone if we're confident that 'fork' is 'false'. Fail if it's also empty.
]
step = {
"name": "clone-enterprise",
"image": images["git"],
"environment": {
"GITHUB_TOKEN": from_secret("github_token"),
},
"commands": [
"apk add --update curl jq bash",
] + check + [
'git clone "https://$${GITHUB_TOKEN}@github.com/grafana/grafana-enterprise.git" ' + location,
"cd {}".format(location),
'if git checkout {0}; then echo "checked out {0}"; elif git checkout {1}; then echo "git checkout {1}"; else git checkout main; fi'.format(source, target),
],
}
if canFail:
step["failure"] = "ignore"
return step
def download_grabpl_step():
return {
"name": "grabpl",
"image": images["curl"],
"commands": [
"mkdir -p bin",
"curl -fL -o bin/grabpl https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/{}/grabpl".format(
grabpl_version,
),
"chmod +x bin/grabpl",
],
}
def lint_drone_step():
return {
"name": "lint-drone",
"image": images["curl"],
"commands": [
"./bin/build verify-drone",
],
"depends_on": [
"compile-build-cmd",
],
}
def lint_starlark_step():
return {
"name": "lint-starlark",
"image": images["go"],
"commands": [
"go install github.com/bazelbuild/buildtools/buildifier@latest",
"buildifier --lint=warn -mode=check -r .",
],
"depends_on": [
"compile-build-cmd",
],
}
def enterprise_downstream_step(ver_mode):
"""Triggers a downstream pipeline in the grafana-enterprise repository.
Args:
ver_mode: indirectly controls the revision used for downstream pipelines.
It also used to allow the step to fail for pull requests without blocking merging.
Returns:
Drone step.
"""
repo = "grafana/grafana-enterprise@"
if ver_mode == "pr" or ver_mode == "rrc":
repo += "${DRONE_SOURCE_BRANCH}"
else:
repo += "main"
step = {
"name": "trigger-enterprise-downstream",
"image": images["drone_downstream"],
"settings": {
"server": "https://drone.grafana.net",
"token": from_secret("drone_token"),
"repositories": [
repo,
],
"params": [
"SOURCE_BUILD_NUMBER=${DRONE_COMMIT}",
"SOURCE_COMMIT=${DRONE_COMMIT}",
],
},
}
if ver_mode == "pr":
step.update({"failure": "ignore"})
step["settings"]["params"].append("OSS_PULL_REQUEST=${DRONE_PULL_REQUEST}")
if ver_mode == "rrc":
step["settings"]["params"].append("SOURCE_TAG=${DRONE_TAG}")
return step
def validate_modfile_step():
return {
"name": "validate-modfile",
"image": images["go"],
"commands": [
"go run scripts/modowners/modowners.go check go.mod",
],
}
def validate_openapi_spec_step():
return {
"name": "validate-openapi-spec",
"image": images["go"],
"commands": [
"apk add --update make",
"make swagger-validate",
],
}
def dockerize_step(name, hostname, port, canFail = False):
step = {
"name": name,
"image": images["dockerize"],
"commands": [
"dockerize -wait tcp://{}:{} -timeout 120s".format(hostname, port),
],
}
if canFail:
step["failure"] = "ignore"
return step
def build_storybook_step(ver_mode):
return {
"name": "build-storybook",
"image": images["node"],
"depends_on": [
# Best to ensure that this step doesn't mess with what's getting built and packaged
"rgm-package",
"build-frontend-packages",
],
"environment": {
"NODE_OPTIONS": "--max_old_space_size=4096",
},
"commands": [
"yarn storybook:build",
"./bin/build verify-storybook",
],
"when": get_trigger_storybook(ver_mode),
}
def store_storybook_step(ver_mode, trigger = None):
"""Publishes the Grafana UI components storybook.
Args:
ver_mode: controls whether a release or canary version is published.
trigger: a Drone trigger for the step.
Defaults to None.
Returns:
Drone step.
"""
commands = []
if ver_mode == "release":
commands.extend(
[
"./bin/build store-storybook --deployment latest",
"./bin/build store-storybook --deployment ${DRONE_TAG}",
],
)
else:
# main pipelines should deploy storybook to grafana-storybook/canary public bucket
commands = [
"./bin/build store-storybook --deployment canary",
]
step = {
"name": "store-storybook",
"image": images["publish"],
"depends_on": [
"build-storybook",
] +
end_to_end_tests_deps(),
"environment": {
"GCP_KEY": from_secret(gcp_grafanauploads),
"PRERELEASE_BUCKET": from_secret(prerelease_bucket),
},
"commands": commands,
"when": get_trigger_storybook(ver_mode),
}
if trigger and ver_mode in ("release-branch", "main"):
# no dict merge operation available, https://github.com/harness/drone-cli/pull/220
when_cond = {
"repo": [
"grafana/grafana",
],
"paths": {
"include": [
"packages/grafana-ui/**",
],
},
}
step = dict(step, when = when_cond)
return step
def e2e_tests_artifacts():
return {
"name": "e2e-tests-artifacts-upload",
"image": images["cloudsdk"],
"depends_on": [
"end-to-end-tests-dashboards-suite",
"end-to-end-tests-panels-suite",
"end-to-end-tests-smoke-tests-suite",
"end-to-end-tests-various-suite",
],
"failure": "ignore",
"when": {
"status": [
"success",
"failure",
],
},
"environment": {
"GCP_GRAFANA_UPLOAD_ARTIFACTS_KEY": from_secret(gcp_upload_artifacts_key),
"E2E_TEST_ARTIFACTS_BUCKET": "releng-pipeline-artifacts-dev",
"GITHUB_TOKEN": from_secret("github_token"),
},
"commands": [
# if no videos found do nothing
"if [ -z `find ./e2e -type f -name *spec.ts.mp4` ]; then echo 'missing videos'; false; fi",
"apt-get update",
"apt-get install -yq zip",
"printenv GCP_GRAFANA_UPLOAD_ARTIFACTS_KEY > /tmp/gcpkey_upload_artifacts.json",
"gcloud auth activate-service-account --key-file=/tmp/gcpkey_upload_artifacts.json",
# we want to only include files in e2e folder that end with .spec.ts.mp4
'find ./e2e -type f -name "*spec.ts.mp4" | zip e2e/videos.zip -@',
"gsutil cp e2e/videos.zip gs://$${E2E_TEST_ARTIFACTS_BUCKET}/${DRONE_BUILD_NUMBER}/artifacts/videos/videos.zip",
"export E2E_ARTIFACTS_VIDEO_ZIP=https://storage.googleapis.com/$${E2E_TEST_ARTIFACTS_BUCKET}/${DRONE_BUILD_NUMBER}/artifacts/videos/videos.zip",
'echo "E2E Test artifacts uploaded to: $${E2E_ARTIFACTS_VIDEO_ZIP}"',
'curl -X POST https://api.github.com/repos/${DRONE_REPO}/statuses/${DRONE_COMMIT_SHA} -H "Authorization: token $${GITHUB_TOKEN}" -d ' +
'"{\\"state\\":\\"success\\",\\"target_url\\":\\"$${E2E_ARTIFACTS_VIDEO_ZIP}\\", \\"description\\": \\"Click on the details to download e2e recording videos\\", \\"context\\": \\"e2e_artifacts\\"}"',
],
}
def playwright_e2e_report_upload():
return {
"name": "playwright-e2e-report-upload",
"image": images["cloudsdk"],
"depends_on": [
"playwright-plugin-e2e",
],
"failure": "ignore",
"when": {
"status": [
"success",
"failure",
],
},
"environment": {
"GCP_GRAFANA_UPLOAD_ARTIFACTS_KEY": from_secret(gcp_upload_artifacts_key),
},
"commands": [
"apt-get update",
"apt-get install -yq zip",
"printenv GCP_GRAFANA_UPLOAD_ARTIFACTS_KEY > /tmp/gcpkey_upload_artifacts.json",
"gcloud auth activate-service-account --key-file=/tmp/gcpkey_upload_artifacts.json",
"gsutil cp -r ./playwright-report/. gs://releng-pipeline-artifacts-dev/${DRONE_BUILD_NUMBER}/playwright-report",
"export E2E_PLAYWRIGHT_REPORT_URL=https://storage.googleapis.com/releng-pipeline-artifacts-dev/${DRONE_BUILD_NUMBER}/playwright-report/index.html",
'echo "E2E Playwright report uploaded to: \n $${E2E_PLAYWRIGHT_REPORT_URL}"',
],
}
def playwright_e2e_report_post_link():
return {
"name": "playwright-e2e-report-post-link",
"image": images["curl"],
"depends_on": [
"playwright-e2e-report-upload",
],
"failure": "ignore",
"when": {
"status": [
"success",
"failure",
],
},
"environment": {
"GITHUB_TOKEN": from_secret("github_token"),
},
"commands": [
# if the trace doesn't folder exists, it means that there are no failed tests.
"if [ ! -d ./playwright-report/trace ]; then echo 'all tests passed'; exit 0; fi",
# if it exists, we will post a comment on the PR with the link to the report
"export E2E_PLAYWRIGHT_REPORT_URL=https://storage.googleapis.com/releng-pipeline-artifacts-dev/${DRONE_BUILD_NUMBER}/playwright-report/index.html",
"curl -L " +
"-X POST https://api.github.com/repos/grafana/grafana/issues/${DRONE_PULL_REQUEST}/comments " +
'-H "Accept: application/vnd.github+json" ' +
'-H "Authorization: Bearer $${GITHUB_TOKEN}" ' +
'-H "X-GitHub-Api-Version: 2022-11-28" -d ' +
'"{\\"body\\":\\"❌ Failed to run Playwright plugin e2e tests. <br /> <br /> Click [here]($${E2E_PLAYWRIGHT_REPORT_URL}) to browse the Playwright report and trace viewer. <br /> For information on how to run Playwright tests locally, refer to the [Developer guide](https://github.com/grafana/grafana/blob/main/contribute/developer-guide.md#to-run-the-playwright-tests). \\"}"',
],
}
def upload_cdn_step(ver_mode, trigger = None):
"""Uploads CDN assets using the Grafana build tool.
Args:
ver_mode: only uses the step trigger when ver_mode == 'release-branch' or 'main'
trigger: a Drone trigger for the step.
Defaults to None.
Returns:
Drone step.
"""
step = {
"name": "upload-cdn-assets",
"image": images["publish"],
"depends_on": [
"grafana-server",
],
"environment": {
"GCP_KEY": from_secret(gcp_grafanauploads),
"PRERELEASE_BUCKET": from_secret(prerelease_bucket),
},
"commands": [
"./bin/build upload-cdn --edition oss",
],
}
if trigger and ver_mode in ("release-branch", "main"):
step = dict(step, when = trigger)
return step
def build_backend_step(distros = "linux/amd64,linux/arm64"):
"""Build the backend code using the Grafana build tool.
Args:
distros: a list of distributes to be built. For a full list, see `go tool dist list`.
Returns:
Drone step.
"""
return rgm_build_backend_step(distros)
def build_frontend_step():
"""Build the frontend code to ensure it's compilable
Returns:
Drone step.
"""
return {
"name": "build-frontend",
"image": images["node"],
"environment": {
"NODE_OPTIONS": "--max_old_space_size=8192",
},
"depends_on": [
"compile-build-cmd",
"yarn-install",
],
"commands": [
"yarn build",
],
}
def build_test_plugins_step():
"""Build the test plugins used in e2e tests
Returns:
Drone step.
"""
return {
"name": "build-test-plugins",
"image": images["node"],
"environment": {
"NODE_OPTIONS": "--max_old_space_size=8192",
},
"depends_on": [
"yarn-install",
],
"commands": [
"yarn e2e:plugin:build",
],
}
def update_package_json_version():
"""Updates the packages/ to use a version that has the build ID in it: 10.0.0pre -> 10.0.0-5432pre
Returns:
Drone step that updates the 'version' key in package.json
"""
return {
"name": "update-package-json-version",
"image": images["node"],
"depends_on": [
"yarn-install",
],
"commands": [
"apk add --update jq",
"new_version=$(cat package.json | jq -r .version | sed s/pre/${DRONE_BUILD_NUMBER}/g)",
"echo \"New version: $new_version\"",
"yarn run lerna version $new_version --exact --no-git-tag-version --no-push --force-publish -y",
"yarn install --mode=update-lockfile",
],
}
def build_frontend_package_step(depends_on = []):
"""Build the frontend packages using the Grafana build tool.
Args:
depends_on: a list of step names (strings) that must complete before this step runs.
Returns:
Drone step.
"""
cmds = [
"apk add --update jq bash", # bash is needed for the validate-npm-packages.sh script since it has a 'bash'
# shebang.
"yarn packages:build",
"yarn packages:pack",
"./scripts/validate-npm-packages.sh",
]
return {
"name": "build-frontend-packages",
"image": images["node"],
"environment": {
"NODE_OPTIONS": "--max_old_space_size=8192",
},
"depends_on": [
"yarn-install",
] + depends_on,
"commands": cmds,
}
def build_plugins_step(ver_mode):
if ver_mode != "pr":
env = {
"GRAFANA_API_KEY": from_secret("grafana_api_key"),
}
else:
env = None
return {
"name": "build-plugins",
"image": images["node"],
"environment": env,
"depends_on": [
"yarn-install",
],
"commands": [
"apk add --update findutils", # Replaces the busybox 'find' with the GNU one.
"yarn plugins:build",
],
}
def test_backend_step():
return {
"name": "test-backend",
"image": images["go"],
"depends_on": [
"wire-install",
],
"commands": [
# shared-mime-info and shared-mime-info-lang is used for exactly 1 test for the
# mime.TypeByExtension function.
"apk add --update build-base shared-mime-info shared-mime-info-lang",
"go list -f '{{.Dir}}/...' -m | xargs go test -short -covermode=atomic -timeout=5m",
],
}
def test_backend_integration_step():
return {
"name": "test-backend-integration",
"image": images["go"],
"depends_on": [
"wire-install",
],
"commands": [
"apk add --update build-base",
"go test -count=1 -covermode=atomic -timeout=5m -run '^TestIntegration' $(find ./pkg -type f -name '*_test.go' -exec grep -l '^func TestIntegration' '{}' '+' | grep -o '\\(.*\\)/' | sort -u)",
],
}
def betterer_frontend_step():
"""Run betterer on frontend code.
Returns:
Drone step.
"""
return {
"name": "betterer-frontend",
"image": images["node"],
"depends_on": [
"yarn-install",
],
"commands": [
"apk add --update git bash",
"yarn betterer ci",
],
}
def test_frontend_step():
"""Runs tests on frontend code.
Returns:
Drone step.
"""
return {
"name": "test-frontend",
"image": images["node"],
"environment": {
"TEST_MAX_WORKERS": "50%",
},
"depends_on": [
"yarn-install",
],
"commands": [
"yarn run ci:test-frontend",
],
}
def lint_frontend_step():
return {
"name": "lint-frontend",
"image": images["node"],
"environment": {
"TEST_MAX_WORKERS": "50%",
},
"depends_on": [
"yarn-install",
],
"commands": [
"yarn run prettier:check",
"yarn run lint",
"yarn run typecheck",
],
}
def verify_i18n_step():
extract_error_message = "\nExtraction failed. Make sure that you have no dynamic translation phrases, such as 't(\\`preferences.theme.\\$${themeID}\\`, themeName)' and that no translation key is used twice. Search the output for '[warning]' to find the offending file."
uncommited_error_message = "\nTranslation extraction has not been committed. Please run 'make i18n-extract', commit the changes and push again."
return {
"name": "verify-i18n",
"image": images["node_deb"],
"depends_on": [
"yarn-install",
],
"commands": [
"make i18n-extract || (echo \"{}\" && false)".format(extract_error_message),
# Verify that translation extraction has been committed
'''
file_diff=$(git diff --dirstat public/locales)
if [ -n "$file_diff" ]; then
echo $file_diff
echo "{}"
exit 1
fi
'''.format(uncommited_error_message),
],
}
def test_a11y_frontend_step(ver_mode, port = 3001):
"""Runs automated accessiblity tests against the frontend.
Args:
ver_mode: controls whether the step is blocking or just reporting.
If ver_mode == 'pr', the step causes the pipeline to fail.
port: which port to grafana-server is expected to be listening on.
Defaults to 3001.
Returns:
Drone step.
"""
commands = [
# Note - this runs in a container running node 14, which does not support the -y option to npx
"npx wait-on@7.0.1 http://$HOST:$PORT",
]
failure = "ignore"
if ver_mode == "pr":
commands.extend(
[
"pa11y-ci --config .pa11yci-pr.conf.js",
],
)
failure = "always"
else:
commands.extend(
[
"pa11y-ci --config .pa11yci.conf.js --json > pa11y-ci-results.json",
],
)
return {
"name": "test-a11y-frontend",
# TODO which image should be used?
"image": images["docker_puppeteer"],
"depends_on": [
"grafana-server",
],
"environment": {
"GRAFANA_MISC_STATS_API_KEY": from_secret("grafana_misc_stats_api_key"),
"HOST": "grafana-server",
"PORT": port,
},
"failure": failure,
"commands": commands,
}
def frontend_metrics_step(trigger = None):
"""Reports frontend metrics to Grafana Cloud.
Args:
trigger: a Drone trigger for the step.
Defaults to None.
Returns:
Drone step.
"""
step = {
"name": "publish-frontend-metrics",
"image": images["node"],
"depends_on": [
"test-a11y-frontend",
],
"environment": {
"GRAFANA_MISC_STATS_API_KEY": from_secret("grafana_misc_stats_api_key"),
},
"failure": "ignore",
"commands": [
"apk add --update bash grep git",
"./scripts/ci-frontend-metrics.sh ./grafana/public/build | ./bin/build publish-metrics $$GRAFANA_MISC_STATS_API_KEY",
],
}
if trigger:
step = dict(step, when = trigger)
return step
def codespell_step():
return {
"name": "codespell",
"image": images["python"],
"commands": [
"pip3 install codespell",
"codespell -I docs/.codespellignore docs/",
],
}
def grafana_server_step():
"""Runs the grafana-server binary as a service.
Returns:
Drone step.
"""
environment = {
"GF_SERVER_HTTP_PORT": "3001",
"GF_SERVER_ROUTER_LOGGING": "1",
"GF_APP_MODE": "development",
}
return {
"name": "grafana-server",
"image": images["alpine"],
"detach": True,
"depends_on": [
"rgm-package",
],
"environment": environment,
"commands": [
"apk add --update tar bash",
"mkdir grafana",
"tar --strip-components=1 -xvf ./dist/*amd64.tar.gz -C grafana",
"cp -r devenv scripts tools grafana && cd grafana && ./scripts/grafana-server/start-server",
],
}
def e2e_tests_step(suite, port = 3001, tries = None):
cmd = "./bin/build e2e-tests --port {} --suite {}".format(port, suite)
if tries:
cmd += " --tries {}".format(tries)
return {
"name": "end-to-end-tests-{}".format(suite),
"image": images["cypress"],
"depends_on": [
"grafana-server",
"build-test-plugins",
],
"environment": {
"HOST": "grafana-server",
},
"commands": [
cmd,
],
}
def start_storybook_step():
return {
"name": "start-storybook",
"image": images["node"],
"depends_on": [
"yarn-install",
],
"commands": [
"yarn storybook --quiet",
],
"detach": True,
}
def e2e_storybook_step():
return {
"name": "end-to-end-tests-storybook-suite",
"image": images["cypress"],
"depends_on": [
"start-storybook",
],
"environment": {
"HOST": "start-storybook",
"PORT": "9001",
},
"commands": [
"npx wait-on@7.2.0 -t 1m http://$HOST:$PORT",
"yarn e2e:storybook",
],
}
def cloud_plugins_e2e_tests_step(suite, cloud, trigger = None):
"""Run cloud plugins end-to-end tests.
Args:
suite: affects the pipeline name.
TODO: check if this actually affects step behavior.
cloud: used to determine cloud provider specific tests.
trigger: a Drone trigger for the step.
Defaults to None.
Returns:
Drone step.
"""
environment = {}
when = {}
if trigger:
when = trigger
if cloud == "azure":
environment = {
"CYPRESS_CI": "true",
"HOST": "grafana-server",
"GITHUB_TOKEN": from_secret("github_token"),
"AZURE_SP_APP_ID": from_secret("azure_sp_app_id"),
"AZURE_SP_PASSWORD": from_secret("azure_sp_app_pw"),
"AZURE_TENANT": from_secret("azure_tenant"),
}
when = dict(
when,
paths = {
"include": [
"pkg/tsdb/azuremonitor/**",
"public/app/plugins/datasource/azuremonitor/**",
"e2e/cloud-plugins-suite/azure-monitor.spec.ts",
],
},
)
branch = "${DRONE_SOURCE_BRANCH}".replace("/", "-")
step = {
"name": "end-to-end-tests-{}-{}".format(suite, cloud),
"image": "us-docker.pkg.dev/grafanalabs-dev/cloud-data-sources/e2e-13.10.0:1.0.0",
"depends_on": [
"grafana-server",
],
"environment": environment,
"commands": ["cd /", "./cpp-e2e/scripts/ci-run.sh {} {}".format(cloud, branch)],
}
step = dict(step, when = when)
return step
def playwright_e2e_tests_step():
return {
"environment": {
"PORT": "3001",
"HOST": "grafana-server",
"PROV_DIR": "/grafana/scripts/grafana-server/tmp/conf/provisioning",
},
"name": "playwright-plugin-e2e",
"image": images["node_deb"],
"depends_on": [
"grafana-server",
"build-test-plugins",
],
"commands": [
"npx wait-on@7.0.1 http://$HOST:$PORT",
"yarn playwright install --with-deps chromium",
"yarn e2e:playwright",
],
}
def build_docs_website_step():
return {
"name": "build-docs-website",
# Use latest revision here, since we want to catch if it breaks
"image": images["docs"],
"pull": "always",
"commands": [
"mkdir -p /hugo/content/docs/grafana/latest",
"echo -e '---\\nredirectURL: /docs/grafana/latest/\\ntype: redirect\\nversioned: true\\n---\\n' > /hugo/content/docs/grafana/_index.md",
"cp -r docs/sources/* /hugo/content/docs/grafana/latest/",
"cd /hugo && make prod",
],
}
def fetch_images_step():
return {
"name": "fetch-images",
"image": images["cloudsdk"],
"environment": {
"GCP_KEY": from_secret(gcp_grafanauploads),
"DOCKER_USER": from_secret("docker_username"),
"DOCKER_PASSWORD": from_secret("docker_password"),
},
"commands": ["./bin/build artifacts docker fetch --edition oss"],
"depends_on": ["compile-build-cmd"],
"volumes": [{"name": "docker", "path": "/var/run/docker.sock"}],
}
def publish_images_step(ver_mode, docker_repo, trigger = None):
"""Generates a step for publishing public Docker images with grabpl.
Args:
ver_mode: controls whether the image needs to be built or retrieved from a previous build.
If ver_mode == 'release', the previously built image is fetched instead of being built again.
docker_repo: the Docker image name.
It is combined with the 'grafana/' library prefix.
trigger: a Drone trigger for the pipeline.
Defaults to None.
Returns:
Drone step.
"""
name = docker_repo
docker_repo = "grafana/{}".format(docker_repo)
environment = {
"GCP_KEY": from_secret(gcp_grafanauploads),
"DOCKER_USER": from_secret("docker_username"),
"DOCKER_PASSWORD": from_secret("docker_password"),
"GITHUB_APP_ID": from_secret("delivery-bot-app-id"),
"GITHUB_APP_INSTALLATION_ID": from_secret("delivery-bot-app-installation-id"),
"GITHUB_APP_PRIVATE_KEY": from_secret("delivery-bot-app-private-key"),
}
cmd = "./bin/grabpl artifacts docker publish --dockerhub-repo {}".format(
docker_repo,
)
deps = ["rgm-build-docker"]
if ver_mode == "release":
deps = ["fetch-images"]
cmd += " --version-tag ${DRONE_TAG}"
if ver_mode == "pr":
environment = {
"DOCKER_USER": from_secret("docker_username"),
"DOCKER_PASSWORD": from_secret("docker_password"),
"GITHUB_APP_ID": from_secret("delivery-bot-app-id"),
"GITHUB_APP_INSTALLATION_ID": from_secret("delivery-bot-app-installation-id"),
"GITHUB_APP_PRIVATE_KEY": from_secret("delivery-bot-app-private-key"),
}
step = {
"name": "publish-images-{}".format(name),
"image": images["cloudsdk"],
"environment": environment,
"commands": [cmd],
"depends_on": deps,
"volumes": [{"name": "docker", "path": "/var/run/docker.sock"}],
}
if trigger and ver_mode in ("release-branch", "main"):
step = dict(step, when = trigger)
if ver_mode == "pr":
step = dict(step, failure = "ignore")
return step
def integration_tests_steps(name, cmds, hostname = None, port = None, environment = None, canFail = False):
"""Integration test steps
Args:
name: the name of the step.
cmds: the commands to run to perform the integration tests.
hostname: the hostname where the remote server is available.
port: the port where the remote server is available.
environment: Any extra environment variables needed to run the integration tests.