-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtask.yml
More file actions
830 lines (796 loc) · 31.7 KB
/
Copy pathtask.yml
File metadata and controls
830 lines (796 loc) · 31.7 KB
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
# TASK_X_REMOTE_TASKFILES=1 task remote:lint
# - cmd: steps that will be run sequentially.
# - deps: tasks that will be run in parallel.
#
# yamllint disable rule:line-length
# yamllint disable rule:quoted-strings
---
version: 3
vars:
# Variables that have to be defined first as they are used in other variables.
CODE_COVERAGE_EXPECTED:
sh: |
if [ -z "${CODE_COVERAGE_EXPECTED}" ]; then
yq '.jobs.mcvs-golang-action.steps[] | select(.uses | test(".*mcvs-golang-action.*")) | .with.code-coverage-expected' .github/workflows/golang.yml
exit 0
fi
echo ${CODE_COVERAGE_EXPECTED}
CODE_COVERAGE_FILE_EXCLUSIONS:
sh: |
if [ -z "${CODE_COVERAGE_FILE_EXCLUSIONS}" ]; then
yq '.jobs.mcvs-golang-action.steps[] | select(.uses | test(".*mcvs-golang-action.*")) | .with.golang-unit-tests-exclusions' .github/workflows/golang.yml
exit 0
fi
echo ${CODE_COVERAGE_FILE_EXCLUSIONS}
OPA_CODE_COVERAGE_EXPECTED:
sh: |
if [ -z "${OPA_CODE_COVERAGE_EXPECTED}" ]; then
yq '.jobs.mcvs-golang-action.steps[] | select(.uses | test(".*mcvs-golang-action.*")) | .with.code-coverage-opa-expected' .github/workflows/golang.yml
exit 0
fi
echo ${OPA_CODE_COVERAGE_EXPECTED}
GOBIN:
sh: |
if [ -z "${GOBIN}" ]; then
if [ -n "${GITHUB_ACTIONS}" ]; then
echo /home/runner/go/bin
exit 0
fi
echo "GOBIN has not been not set. Ensure that it has been set on the system."
exit 1
fi
# Ensure that GOBIN is set in the context of this Taskfile.
echo ${GOBIN}
OS_TYPE_MAC: Darwin
# Variables that are sorted alphabetically and are used in the tasks.
BUILD_TAGS: '{{ .BUILD_TAGS | default "component,e2e,integration" }}'
CODE_COVERAGE_STRICT: '{{.CODE_COVERAGE_STRICT | default "true"}}'
CODE_COVERAGE_TIMEOUT: '{{.CODE_COVERAGE_TIMEOUT | default "4m0s"}}'
COVERPROFILE: profile.cov
COVERPROFILE_UNIQUE: "unique_{{.COVERPROFILE}}"
GOLANGCI_LINT_CONFIG_PATH: '{{.GOLANGCI_LINT_CONFIG_PATH | default ".golangci.yml"}}'
GOLANGCI_LINT_VERSION: v2.10.1
GOLANGCI_LINT_VERSION_WITHOUT_V_PREFIX: # the version found by the package-version-updater contains a 'v' prefix
sh: echo {{.GOLANGCI_LINT_VERSION}} | sed -e "s|v||"
GOLANGCI_LINT_RUN_TIMEOUT_MINUTES: "{{.GOLANGCI_LINT_RUN_TIMEOUT_MINUTES | default 3}}"
GOLANG_PARALLEL_TESTS:
sh: |
if [ "$(uname -s)" = "{{.OS_TYPE_MAC}}" ]; then
sysctl -n hw.ncpu
else
nproc
fi
GOLINES_BIN: "{{.GOBIN}}/golines"
GOLINES_VERSION: v0.13.0
GO_SWAGGER: "{{.GOBIN}}/swagger"
GO_SWAGGER_VERSION: v0.33.1
OSV_SCANNER_VERSION: v2.3.3
OSV_SCANNER_VERSION_WITHOUT_V_PREFIX: # the version found by the package-version-updater contains a 'v' prefix
sh: echo {{.OSV_SCANNER_VERSION}} | sed -e "s|v||"
OSV_SCANNER_BIN: "{{.GOBIN}}/osv-scanner"
OSV_SCANNER_OUTPUT: /tmp/osv-scanner.txt
GQLGEN_VERSION: v0.17.87
GQLGEN_BIN: "{{.GOBIN}}/gqlgen"
GQLGENC_VERSION: v0.33.1
GQLGENC_BIN: "{{.GOBIN}}/gqlgenc"
GRAPHQL_LINTER_BIN: "{{.GOBIN}}/graphql-linter"
GRAPHQL_LINTER_VERSION: v0.1.0
GTA_BASE_BRANCH: '{{.GTA_BASE_BRANCH | default "main"}}'
GTA_PARTIAL_TESTING: '{{.GTA_PARTIAL_TESTING | default "false"}}'
GTA_VERSION: v0.2.0
HELM_VERSION: v3.16.2
MCVS_TEXTTIDY_BIN: "{{.GOBIN}}/mcvs-texttidy"
MCVS_TEXTTIDY_VERSION: 0.1.0
MOCKERY_BIN: "{{.GOBIN}}/mockery"
MOCKERY_VERSION: v3.6.4
OPA_BIN: "{{.GOBIN}}/opa"
OPA_FMT: "{{.OPA_BIN}} fmt ."
OPA_VERSION: v1.14.0
OPA_VERSION_WITHOUT_V_PREFIX: # the version found by the package-version-updater contains a 'v' prefix
sh: echo {{.OPA_VERSION}} | sed -e "s|v||"
OS_COMMAND: uname
OS_COMMAND_TYPE:
sh: "{{.OS_COMMAND}} -s"
OS_COMMAND_TYPE_ARCHITECTURE:
sh: "{{.OS_COMMAND}} -m"
PRESENT_BIN: "{{.GOBIN}}/present"
PRESENT_VERSION: v0.42.0
PRESENT_PRESENTATIONS_HOME: '{{.PRESENT_PRESENTATIONS_HOME | default "./docs/presentations"}}'
REGAL_BIN: "{{.GOBIN}}/regal"
REGAL_VERSION: v0.39.0
REGAL_VERSION_WITHOUT_V_PREFIX: # the version found by the package-version-updater contains a 'v' prefix
sh: echo {{.REGAL_VERSION}} | sed -e "s|v||"
SED_INSERT_ADDITION:
sh: |
if [ "{{.OS_COMMAND_TYPE}}" = "{{.OS_TYPE_MAC}}" ]; then
echo "\"\""
fi
TEST_TIMEOUT: '{{.TEST_TIMEOUT | default "4m0s"}}'
WSL_BIN: "{{.GOBIN}}/wsl"
WSL_VERSION: v5.6.0
YQ_VERSION: v4.52.4
tasks:
build-golang-download-modules:
cmds:
- |
go mod tidy
desc: download go modules
silent: true
check-docker-networks:
cmds:
- |
get_docker_network_count() {
docker network ls --format "table {{.ID}}\t{{.Name}}\t{{.Driver}}\t{{.Scope}}" | tail -n +2 | wc -l
}
if [ "{{.CHECK_TYPE}}" = "before" ]; then
echo "Checking Docker networks before test..."
networks_count=$(get_docker_network_count)
echo "Docker networks before: ${networks_count}"
echo "${networks_count}" > /tmp/docker_networks_before
fi
if [ "{{.CHECK_TYPE}}" = "after" ]; then
echo "Checking Docker networks after test..."
networks_after=$(get_docker_network_count)
networks_before=$(cat /tmp/docker_networks_before 2>/dev/null || echo "0")
echo "Docker networks after: ${networks_after}"
# Check for both high network count and orphaned networks
show_warning=false
warning_messages=""
if [ "${networks_after}" -gt "4" ]; then
show_warning=true
warning_messages="${warning_messages}# Found ${networks_after} Docker networks, which exceeds the"$'\n'
warning_messages="${warning_messages}# default of three networks: bridge, host and none."$'\n'
warning_messages="${warning_messages}#"$'\n'
fi
if [ "${networks_after}" -gt "${networks_before}" ]; then
show_warning=true
if [ -n "${warning_messages}" ]; then
warning_messages="${warning_messages}# Additionally, found $((networks_after - networks_before)) orphaned Docker"$'\n'
else
warning_messages="${warning_messages}# Found $((networks_after - networks_before)) orphaned Docker"$'\n'
fi
warning_messages="${warning_messages}# networks."$'\n'
warning_messages="${warning_messages}#"$'\n'
warning_messages="${warning_messages}# Note: Orphaned networks were not removed automatically."$'\n'
warning_messages="${warning_messages}# Please check whether they are cleaned by the component"$'\n'
warning_messages="${warning_messages}# and/or integration tests."$'\n'
warning_messages="${warning_messages}#"$'\n'
fi
if [ "${show_warning}" = "true" ]; then
echo
echo "###############################################################"
echo "#"
echo "# WARNING"
echo "#"
echo "###############################################################"
echo "#"
echo -e "${warning_messages}"
echo "# Current Docker networks:"
echo "# $(docker network ls)"
echo "#"
if [ "${networks_after}" -gt "4" ] && [ "${networks_after}" -le "${networks_before}" ]; then
echo "# Please check whether the component and/or integration"
echo "# tests clean up unused Docker networks."
echo "#"
fi
echo "###############################################################"
sleep 5 # to ensure that user will see the message
fi
fi
internal: true
silent: true
coverage:
cmds:
- task: test
vars:
TEST_EXTRA_ARGS: >-
-coverpkg=$(go list --tags={{.TEST_TAGS}} ./... | grep -v '{{.CODE_COVERAGE_FILE_EXCLUSIONS}}' | tr '\n' ',' | sed 's/,$//') -coverprofile={{.COVERPROFILE}} -count=1
TEST_TAGS: integration
TEST_TIMEOUT: "{{.CODE_COVERAGE_TIMEOUT}}"
- |
local_dir_name="$(basename "$PWD")"
awk '!seen[$0]++' {{.COVERPROFILE}} > {{.COVERPROFILE_UNIQUE}}
code_coverage_output=$(go tool cover -func {{.COVERPROFILE_UNIQUE}})
code_coverage_actual=$(echo "${code_coverage_output}" | awk '/total:/ {print $3}' | sed 's/%//')
echo "CODE_COVERAGE_FILE_EXCLUSIONS: {{.CODE_COVERAGE_FILE_EXCLUSIONS}}"
echo "Code coverage overview:"
echo "${code_coverage_output}" | cut -d'/' -f4-
echo "CODE_COVERAGE_STRICT: {{.CODE_COVERAGE_STRICT}}"
if (( $(echo "${code_coverage_actual} < {{.CODE_COVERAGE_EXPECTED}}" | bc -l) )); then
echo "The actual code coverage: '${code_coverage_actual}' is too low. Expected: '{{.CODE_COVERAGE_EXPECTED}}'. Resolve the issue by writing more unit and/or integration tests."
exit 1
elif [ "{{.CODE_COVERAGE_STRICT}}" = "true" ] && (( $(echo "${code_coverage_actual} > {{.CODE_COVERAGE_EXPECTED}}" | bc -l) )); then
echo "The actual code coverage: '${code_coverage_actual}' exceeds the expected coverage. Please adjust the threshold that is defined in the .github/workflows/golang.yml workflow from '{{.CODE_COVERAGE_EXPECTED}}' to '${code_coverage_actual}'."
exit 1
fi
desc: check code coverage
silent: true
coverage-visual:
cmds:
- task: coverage
- |
go tool cover \
-html={{.COVERPROFILE_UNIQUE}} \
-o coverage.html
open ./coverage.html
desc: show code coverage
silent: true
format:
cmds:
- task: golangci-lint-install
- task: golangci-lint-fmt
- go mod tidy
desc: format go files
silent: true
fix-linting-issues:
cmds:
- task: golines-install
- task: wsl-install
- |
{{.GOLINES_BIN}} . -w
{{.WSL_BIN}} -fix ./...
desc: automatically fix linting issues using golines and wsl
silent: true
helm-install:
cmds:
- task: keep-local-and-remote-versions-in-sync
- |
if ! helm version | grep -q "{{.HELM_VERSION}}"; then
echo "Installing Helm version {{.HELM_VERSION}}..."
curl \
-fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 |\
bash -s -- --version {{.HELM_VERSION}}
fi
silent: true
golang-log:
cmds:
- |
echo "GOBIN: {{.GOBIN}}"
echo "GOLANG_PARALLEL_TESTS: {{.GOLANG_PARALLEL_TESTS}}"
golangci-lint-config-verify:
cmds:
- golangci-lint config path
- golangci-lint config verify
silent: true
golangci-lint-install:
cmds:
- task: keep-local-and-remote-versions-in-sync
- |
if ! golangci-lint --version | grep -q "has version {{.GOLANGCI_LINT_VERSION_WITHOUT_V_PREFIX}}"; then
echo "Installing golangci-lint version {{.GOLANGCI_LINT_VERSION_WITHOUT_V_PREFIX}}..."
curl \
-sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh |\
sh -s -- -b {{.GOBIN}} {{.GOLANGCI_LINT_VERSION}}
fi
silent: true
golangci-lint-fmt:
cmds:
- |
golangci-lint fmt \
--verbose
golangci-lint-run:
cmds:
- task: golang-log
- |
golangci-lint run \
--build-tags {{.BUILD_TAGS}} \
--concurrency {{.GOLANG_PARALLEL_TESTS}} \
--config {{.GOLANGCI_LINT_CONFIG_PATH}} \
--timeout {{.GOLANGCI_LINT_RUN_TIMEOUT_MINUTES}}m \
--verbose \
{{.EXTRA_ARGS}}
silent: true
golangci-lint-run-output-json:
cmds:
- task: golangci-lint-run
vars:
EXTRA_ARGS: >-
--output.json.path stdout
silent: true
golangci-lint:
cmds:
- task: golangci-lint-install
- task: golangci-lint-fmt
- task: golangci-lint-run
desc: run golangci-lint
silent: true
golangci-lint-output-json:
cmds:
- task: golangci-lint-install
- task: golangci-lint-fmt
- task: golangci-lint-run-output-json
desc: run golangci-lint with JSON output
silent: true
golangci-lint-run-without-cache:
cmds:
- task: golangci-lint-install
- golangci-lint cache clean
- task: golangci-lint-run
desc: run golangci-lint without cache
golines-install:
cmds:
- task: keep-local-and-remote-versions-in-sync
- |
if ! command -v {{.GOLINES_BIN}} >/dev/null 2>&1 || \
! {{.GOLINES_BIN}} --version | grep -q {{.GOLINES_VERSION}}; then
echo "Installing golines version {{.GOLINES_VERSION}}..."
go install github.com/segmentio/golines@{{.GOLINES_VERSION}}
fi
silent: true
go-swagger-install:
cmds:
- |
if ! {{.GO_SWAGGER}} version | grep -q "{{.GO_SWAGGER_VERSION}}"; then
echo "Installing go-swagger version {{.GO_SWAGGER_VERSION}}..."
go install github.com/go-swagger/go-swagger/cmd/swagger@{{.GO_SWAGGER_VERSION}}
fi
silent: true
gta-install:
cmds:
- |
if ! gta version | grep -q "{{.GTA_VERSION}}"; then
echo "Installing gta version {{.GTA_VERSION}}..."
go install github.com/digitalocean/gta/cmd/gta@{{.GTA_VERSION}}
fi
silent: true
osv-scanner-install:
cmds:
- |
osv_scanner_version=$(echo "{{.OSV_SCANNER_VERSION}}" | cut -d '.' -f 1)
if ! {{.OSV_SCANNER_BIN}} --version 2>/dev/null | grep -q "{{.OSV_SCANNER_VERSION_WITHOUT_V_PREFIX}}"; then
echo "Installing osv-scanner version {{.OSV_SCANNER_VERSION}}..."
go install github.com/google/osv-scanner/${osv_scanner_version}/cmd/osv-scanner@{{.OSV_SCANNER_VERSION}}
fi
silent: true
osv-scanner:
cmds:
- task: osv-scanner-install
- |
echo "Running osv-scanner scan..."
# Run osv-scanner and capture output, allow it to fail
{{.OSV_SCANNER_BIN}} \
--lockfile go.mod \
> {{.OSV_SCANNER_OUTPUT}} 2>&1 || scan_exit_code=$?
# Check if scan found vulnerabilities (exit code 1) or had an error (exit code 128)
if [ -z "${scan_exit_code}" ]; then
echo "No vulnerabilities found."
exit 0
fi
if [ "${scan_exit_code}" -ne 1 ]; then
echo "osv-scanner encountered an error (exit code: ${scan_exit_code})"
cat {{.OSV_SCANNER_OUTPUT}}
exit "${scan_exit_code}"
fi
# Vulnerabilities found, check if they are in the ignore list
echo "Vulnerabilities detected. Checking against ignore list..."
# Check if osv-scanner.toml exists for ignoring vulnerabilities
if [ -f "osv-scanner.toml" ]; then
echo "Found osv-scanner.toml configuration file."
echo "Re-running scan with ignore configuration..."
{{.OSV_SCANNER_BIN}} \
--config osv-scanner.toml \
--lockfile go.mod \
> {{.OSV_SCANNER_OUTPUT}} 2>&1 || final_exit_code=$?
if [ -z "${final_exit_code}" ]; then
echo "All vulnerabilities are in the ignore list."
exit 0
elif [ "${final_exit_code}" -eq 1 ]; then
echo "Vulnerabilities found that are not in the ignore list:"
cat {{.OSV_SCANNER_OUTPUT}}
exit 1
else
echo "osv-scanner encountered an error (exit code: ${final_exit_code})"
cat {{.OSV_SCANNER_OUTPUT}}
exit "${final_exit_code}"
fi
else
echo "No osv-scanner.toml found. All vulnerabilities will cause failure."
cat {{.OSV_SCANNER_OUTPUT}}
exit 1
fi
desc: check for vulnerabilities with osv-scanner
silent: true
gqlgen-install:
cmds:
- |
if ! {{.GQLGEN_BIN}} version | grep -q {{.GQLGEN_VERSION}}; then
echo "Installing gqlgen version {{.GQLGEN_VERSION}}..."
go install github.com/99designs/gqlgen@{{.GQLGEN_VERSION}}
fi
silent: true
gqlgen:
cmds:
- task: gqlgen-install
- find {{.GQLGEN_DIR | default "."}} -name gqlgen.yml -exec echo {} ';' -execdir {{.GQLGEN_BIN}} ';'
desc: find gqlgen.yml files and generate graphql servers based on these schemas
silent: true
gqlgenc-install:
cmds:
- task: keep-local-and-remote-versions-in-sync
- |
if ! {{.GQLGENC_BIN}} version | grep -q {{.GQLGENC_VERSION}}; then
echo "Installing gqlgenc version {{.GQLGENC_VERSION}}..."
go install github.com/Yamashou/gqlgenc@{{.GQLGENC_VERSION}}
fi
graphql-linter-install:
cmds:
- |
if ! {{.GRAPHQL_LINTER_BIN}} --version | grep -q {{.GRAPHQL_LINTER_VERSION}}; then
echo "Installing graphql-linter version {{.GRAPHQL_LINTER_VERSION}}..."
go install github.com/schubergphilis/graphql-linter/cmd/graphql-linter@{{.GRAPHQL_LINTER_VERSION}}
fi
silent: true
graphql-lint:
cmds:
- task: graphql-linter-install
- |
{{.GRAPHQL_LINTER_BIN}}
silent: true
keep-local-task-up-to-date-with-version-defined-in-action:
cmds:
- task: yq-install
- |
if [ -f Taskfile.yml ]; then
expected_task_version=$(curl -s {{.REMOTE_URL}}/{{.REMOTE_URL_REPO}}/{{.REMOTE_URL_REF}}/action.yml | yq '.inputs.task-version.default')
expected_task_major_version=$(echo "${expected_task_version}" | sed -E 's/^([0-9]+).*/\1/')
current_task_version=$(task --version | sed -E 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
if [ -z "${expected_task_version}" ] || [ -z "${current_task_version}" ]; then
echo "Failed to extract the expected (default) or current version or both for Task. Please check the default task-version input parameter in the .github/workflows/golang.yml."
exit 1
fi
if [ "${expected_task_version}" != "${current_task_version}" ]; then
if [ -n "${GITHUB_ACTIONS}" ]; then
echo "The task binary: ${current_task_version} differs from the expected: ${expected_task_version}. Updating it..."
go install github.com/go-task/task/v${expected_task_major_version}/cmd/task@v${expected_task_version}
exit 0
fi
echo
echo "###############################################################"
echo "#"
echo "# WARNING"
echo "#"
echo "###############################################################"
echo "#"
echo "# The version of the local task binary: ${current_task_version}"
echo "# differs from the expected: ${expected_task_version}."
echo "# Resolve the issue by updating the local task binary to"
echo "# version: ${expected_task_version}."
echo "# A remediation option is to run:"
echo "# 'go install github.com/go-task/task/v${expected_task_major_version}/cmd/task@v${expected_task_version}',"
echo "# but the choice of installation method depends on the"
echo "# preferred way to install Task."
echo "#"
echo "###############################################################"
echo
sleep 3 # to ensure that user will see the message
fi
fi
silent: true
keep-mcvs-golang-action-version-local-taskfile-in-sync-with-github-workflow:
cmds:
- task: yq-install
- |
if [ -f .github/workflows/golang.yml ]; then
expected_mcvs_golang_action_version=$(yq '.jobs."mcvs-golang-action".steps[] | select(.uses | test(".*/mcvs-golang-action@.*")) | .uses' .github/workflows/golang.yml | sed -E 's/.*@(.*)/\1/')
current_mcvs_golang_action_version=$(yq '.vars.REMOTE_URL_REF' Taskfile.yml)
if [ -z "${expected_mcvs_golang_action_version}" ] || [ -z "${current_mcvs_golang_action_version}" ]; then
echo "Failed to extract the expected and current version or both for the mcvs-golang-action. Please ensure that the mcvs-golang-action is defined in lower case in the .github/workflows/golang.yml file and the the REMOTE_URL_REF variable is present in the Taskfile.yml."
exit 1
fi
if [ "${expected_mcvs_golang_action_version}" != "${current_mcvs_golang_action_version}" ]; then
if [ -n "${GITHUB_ACTIONS}" ]; then
echo "Expected mcvs-golang-action: ${expected_mcvs_golang_action_version} is different than current version in Taskfile: ${current_mcvs_golang_action_version}, but do not let the pipeline fail otherwise Dependabot cannot update the version of the action."
exit 0
fi
echo
echo "###############################################################"
echo "#"
echo "# WARNING"
echo "#"
echo "###############################################################"
echo "#"
echo "# Expected mcvs-golang-action: ${expected_mcvs_golang_action_version},"
echo "# but current version in Taskfile: ${current_mcvs_golang_action_version}."
echo "#"
echo "# Resolve the issue by updating the REMOTE_URL_REF in the"
echo "# Taskfile.yml variable to: ${expected_mcvs_golang_action_version}."
echo "#"
echo "###############################################################"
echo
sleep 3 # to ensure that user will see the message
fi
fi
desc: |
Ensure that the mcvs-golang-action version in Taskfile.yml matches the
one in .github/workflows/golang.yml. Since Dependabot updates only the
workflow file, the Taskfile must be updated manually. This check ensures
that any version mismatch causes the pipeline to fail, prompting the user
to update the Taskfile to keep the pipeline running successfully.
silent: true
keep-local-and-remote-versions-in-sync:
cmds:
- task: keep-local-task-up-to-date-with-version-defined-in-action
- task: keep-mcvs-golang-action-version-local-taskfile-in-sync-with-github-workflow
lint:
cmds:
- task: golangci-lint
desc: run golangci-lint (alias for golangci-lint)
silent: true
mcvs-texttidy-install:
cmds:
- task: keep-local-and-remote-versions-in-sync
- |
if ! {{.MCVS_TEXTTIDY_BIN}} --version | grep -q {{.MCVS_TEXTTIDY_VERSION}}; then
echo "Installing mcvs-texttidy version {{.MCVS_TEXTTIDY_VERSION}}..."
go install github.com/schubergphilis/mcvs-texttidy/cmd/mcvs-texttidy@{{.MCVS_TEXTTIDY_VERSION}}
fi
silent: true
mcvs-texttidy-run:
cmds:
- "{{.MCVS_TEXTTIDY_BIN}}"
silent: true
mcvs-texttidy:
cmds:
- task: mcvs-texttidy-install
- task: mcvs-texttidy-run
desc: |
Install and run mcvs-texttidy to check for forbidden words in projects.
silent: true
mock-generate:
cmds:
- task: mocks
desc: Alias for `task remote:mocks`
silent: true
mockery-install:
cmds:
- |
mockery_major_version=$(echo "{{.MOCKERY_VERSION}}" | cut -d '.' -f 1)
if ! {{.MOCKERY_BIN}} version | grep "{{.MOCKERY_VERSION}}"; then
echo "Installing mockery version {{.MOCKERY_VERSION}}..."
go install github.com/vektra/mockery/${mockery_major_version}@{{.MOCKERY_VERSION}}
fi
internal: true
silent: true
mocks:
cmds:
- task: mockery-install
- |
{{.MOCKERY_BIN}}
- task: format
silent: true
mocks-tidy:
cmds:
- |
find . -type d -name 'mocks' -exec rm -r {} +
- task: mocks
- |
if [[ -n "$(git status --porcelain)" ]]; then
echo "Uncommitted changes detected. Did you forget to run: 'task remote:mocks'?"
exit 1
fi
silent: true
opa-fmt:
cmds:
- task: opa-install
- "{{.OPA_FMT}}"
desc: check formatting rego files using opa
silent: true
opa-fmt-write:
cmds:
- task: opa-install
- "{{.OPA_FMT}} --write"
desc: apply formatting rego files using opa
silent: true
opa-install:
cmds:
- |
if ! {{.OPA_BIN}} version | grep -q {{.OPA_VERSION_WITHOUT_V_PREFIX}}; then
echo "Installing OPA version {{.OPA_VERSION}}..."
go install github.com/open-policy-agent/opa@{{.OPA_VERSION}}
fi
silent: true
opa-run:
cmds:
- |
opa_cmd="opa test . --ignore \"*.json\""
for dir in $(find . -type f -name '*.rego' -exec dirname {} \; | sort -u); do
echo "Running ${opa_cmd} in directory: $dir"
(cd "$dir" && ${opa_cmd} -v --explain={{.QUERY_EXPLANATION}})
opa_code_coverage_overview=$(cd "$dir" && ${opa_cmd} --coverage)
echo "OPA code coverage overview:"
echo "${opa_code_coverage_overview}"
opa_code_coverage_actual=$(echo "${opa_code_coverage_overview}" | jq .coverage)
echo "opa_code_coverage_actual: ${opa_code_coverage_actual}"
int_number=$(echo "$opa_code_coverage_actual" | bc)
echo "int_number: ${int_number}"
echo "opa_code_coverage_actual: ${opa_code_coverage_actual}"
opa_code_coverage_actual_significance_of_two=$(echo $opa_code_coverage_actual | bc -l | xargs printf "%.2f")
echo "opa_code_coverage_actual_significance_of_two: ${opa_code_coverage_actual_significance_of_two}"
if (( $(echo "{{.OPA_CODE_COVERAGE_EXPECTED}} > ${opa_code_coverage_actual_significance_of_two}" | bc -l) )); then
echo "The actual OPA code coverage: '${opa_code_coverage_actual_significance_of_two}' is too low. Expected: '{{.OPA_CODE_COVERAGE_EXPECTED}}'. Resolve the issue by writing more OPA unit tests."
exit 1
elif (( $(echo "${opa_code_coverage_actual_significance_of_two} > {{.OPA_CODE_COVERAGE_EXPECTED}}" | bc -l) )); then
echo "The actual OPA code coverage: '${opa_code_coverage_actual_significance_of_two}' exceeds the expected coverage. Please adjust the threshold that is defined in the applicable GitHub workflow from '{{.OPA_CODE_COVERAGE_EXPECTED}}' to '${opa_code_coverage_actual_significance_of_two}'."
exit 1
fi
done
silent: true
vars:
QUERY_EXPLANATION: '{{.QUERY_EXPLANATION | default "fails"}}'
opa:
cmds:
- task: opa-install
- task: opa-run
desc: |
Install and run OPA. Issue: 'task remote:opa QUERY_EXPLANATION=full' to
follow the complete policy evaluation.
silent: true
present:
cmds:
- task: present-install
- task: present-config
- task: present-run
present-install:
cmds:
- |
if ! go version -m {{.PRESENT_BIN}} | grep "mod.*\/x\/tools" | awk '{print $3}' | grep -q {{.PRESENT_VERSION}}; then
echo "Installing present version {{.PRESENT_VERSION}}..."
go install golang.org/x/tools/cmd/present@{{.PRESENT_VERSION}}
fi
silent: true
present-config:
cmds:
- |
for dir in static templates; do
cp -R ~/go/pkg/mod/golang.org/x/tools@{{.PRESENT_VERSION}}/cmd/present//"$dir" {{.PRESENT_PRESENTATIONS_HOME}};
chmod -R 744 {{.PRESENT_PRESENTATIONS_HOME}}/${dir};
done
chmod 744 {{.PRESENT_PRESENTATIONS_HOME}}/templates/slides.tmpl
awk '/Thank you/{for(i=NR-1;i<=NR+8;i++) delete a[i]; next} {a[NR]=$0} END {for(i=1;i<=NR;i++) if(i in a) print a[i]}' {{.PRESENT_PRESENTATIONS_HOME}}/templates/slides.tmpl > {{.PRESENT_PRESENTATIONS_HOME}}/templates/slides.tmp
mv {{.PRESENT_PRESENTATIONS_HOME}}/templates/slides.tmp {{.PRESENT_PRESENTATIONS_HOME}}/templates/slides.tmpl
silent: true
present-run:
cmds:
- "{{.PRESENT_BIN}} -base {{.PRESENT_PRESENTATIONS_HOME}} -content {{.PRESENT_PRESENTATIONS_HOME}}"
silent: true
regal-install:
cmds:
- |
if ! {{.REGAL_BIN}} version | grep -q {{.REGAL_VERSION_WITHOUT_V_PREFIX}}; then
# regal version installed using `go install` does not include
# version, see: https://github.com/open-policy-agent/regal/issues/1275
echo "Installing regal version {{.REGAL_VERSION}}..."
curl -L -o {{.REGAL_BIN}} https://github.com/open-policy-agent/regal/releases/download/{{.REGAL_VERSION}}/regal_{{.OS_COMMAND_TYPE}}_{{.OS_COMMAND_TYPE_ARCHITECTURE}}
chmod +x {{.REGAL_BIN}}
fi
silent: true
regal-run:
cmds:
- |
if ! {{.REGAL_BIN}} lint .; then
echo "regal linting failed. Run: 'task remote:opa-fmt-write' to fix the issue"
exit 1
fi
silent: true
regal:
cmds:
- task: regal-install
- task: regal-run
desc: run regal
silent: true
test:
cmds:
- task: golang-log
- |
set -eu
if [ "{{.GTA_PARTIAL_TESTING}}" = true ]; then
echo "Running partial test suite... against origin {{ .GTA_BASE_BRANCH }}"
PKGS="$(gta -include "$(go list -f '{{ .Module.Path }}')/" -base origin/{{ .GTA_BASE_BRANCH }})" \
|| { rc=$?; echo "gta failed (exit $rc)"; exit $rc; }
if [ -z "${PKGS}" ]; then
echo "No packages changed compared to base branch {{ .GTA_BASE_BRANCH }}. Skipping tests."
exit 0;
fi
else
PKGS=./...
fi
# when "if testing.Short() { t.Skip() }" is in the go code then such
# tests will be skipped if -short is used.
go test \
-p {{.GOLANG_PARALLEL_TESTS}} \
-race \
-short \
--tags={{.TEST_TAGS}} \
${PKGS} \
{{.TEST_EXTRA_ARGS}} \
-timeout {{.TEST_TIMEOUT}}
desc: run test
silent: true
test-cicd:
cmds:
- task: test
vars:
TEST_EXTRA_ARGS: >-
-v
TEST_TAGS: "{{.TEST_TAGS}}"
desc: test within CICD should contain verbose logging to facilitate debugging
silent: true
test-component:
cmds:
- task: check-docker-networks
vars:
CHECK_TYPE: before
- task: test
vars:
TEST_TAGS: component
- task: check-docker-networks
vars:
CHECK_TYPE: after
desc: run component tests
silent: true
test-component-cicd:
cmds:
- task: test-cicd
vars:
TEST_TAGS: component
desc: run component tests in CICD
silent: true
test-e2e:
cmds:
- task: test
vars:
TEST_TAGS: e2e
desc: run end-to-end tests
silent: true
test-e2e-cicd:
cmds:
- task: test-cicd
vars:
TEST_TAGS: e2e
desc: run end-to-end tests in CICD
silent: true
test-integration:
cmds:
- task: check-docker-networks
vars:
CHECK_TYPE: before
- task: test
vars:
TEST_TAGS: integration
- task: check-docker-networks
vars:
CHECK_TYPE: after
desc: run integration tests
silent: true
test-integration-cicd:
cmds:
- task: test-cicd
vars:
TEST_TAGS: integration
desc: run integration tests in CICD
silent: true
wsl-install:
cmds:
- task: keep-local-and-remote-versions-in-sync
- |
wsl_major_version=$(echo "{{.WSL_VERSION}}" | cut -d '.' -f 1)
if ! command -v {{.WSL_BIN}} >/dev/null 2>&1 || \
! {{.WSL_BIN}} -V | grep -q {{.WSL_VERSION}}; then
echo "Installing wsl version {{.WSL_VERSION}}..."
go install github.com/bombsimon/wsl/${wsl_major_version}/cmd/wsl@{{.WSL_VERSION}}
fi
silent: true
yq-install:
cmds:
# Enabling the following task as a dependency will create an infinite
# loop, as the yq-install unit is already a dependency within the called
# unit.
# - task: keep-local-and-remote-versions-in-sync
- |
yq_major_version=$(echo "{{.YQ_VERSION}}" | cut -d '.' -f 1)
if ! yq --version | grep -q "version {{.YQ_VERSION}}"; then
echo "Installing yq version {{.YQ_VERSION}}..."
go install \
github.com/mikefarah/yq/${yq_major_version}@{{.YQ_VERSION}}
fi
silent: true