-
Notifications
You must be signed in to change notification settings - Fork 124
/
project.go
2324 lines (2084 loc) · 80.9 KB
/
project.go
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
package model
import (
"context"
"fmt"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"time"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/db"
mgobson "github.com/evergreen-ci/evergreen/db/mgo/bson"
"github.com/evergreen-ci/evergreen/model/build"
"github.com/evergreen-ci/evergreen/model/host"
"github.com/evergreen-ci/evergreen/model/manifest"
"github.com/evergreen-ci/evergreen/model/patch"
"github.com/evergreen-ci/evergreen/model/task"
"github.com/evergreen-ci/evergreen/thirdparty"
"github.com/evergreen-ci/evergreen/util"
"github.com/evergreen-ci/utility"
"github.com/mongodb/anser/bsonutil"
"github.com/mongodb/grip"
"github.com/mongodb/grip/message"
"github.com/pkg/errors"
ignore "github.com/sabhiram/go-gitignore"
"gopkg.in/yaml.v3"
)
const (
// DefaultCommandType is a system configuration option that is used to
// differentiate between setup related commands and actual testing commands.
DefaultCommandType = evergreen.CommandTypeTest
waterfallTasksQueryMaxTime = 90 * time.Second
)
// Project represents the fully hydrated project configuration after translating
// the ParserProject.
type Project struct {
Stepback bool `yaml:"stepback,omitempty" bson:"stepback"`
PreTimeoutSecs int `yaml:"pre_timeout_secs,omitempty" bson:"pre_timeout_secs,omitempty"`
PostTimeoutSecs int `yaml:"post_timeout_secs,omitempty" bson:"post_timeout_secs,omitempty"`
PreErrorFailsTask bool `yaml:"pre_error_fails_task,omitempty" bson:"pre_error_fails_task,omitempty"`
PostErrorFailsTask bool `yaml:"post_error_fails_task,omitempty" bson:"post_error_fails_task,omitempty"`
OomTracker bool `yaml:"oom_tracker,omitempty" bson:"oom_tracker"`
BatchTime int `yaml:"batchtime,omitempty" bson:"batch_time"`
Identifier string `yaml:"identifier,omitempty" bson:"identifier"`
DisplayName string `yaml:"display_name,omitempty" bson:"display_name"`
CommandType string `yaml:"command_type,omitempty" bson:"command_type"`
Ignore []string `yaml:"ignore,omitempty" bson:"ignore"`
Parameters []ParameterInfo `yaml:"parameters,omitempty" bson:"parameters,omitempty"`
Pre *YAMLCommandSet `yaml:"pre,omitempty" bson:"pre"`
Post *YAMLCommandSet `yaml:"post,omitempty" bson:"post"`
Timeout *YAMLCommandSet `yaml:"timeout,omitempty" bson:"timeout"`
CallbackTimeout int `yaml:"callback_timeout_secs,omitempty" bson:"callback_timeout_secs"`
Modules ModuleList `yaml:"modules,omitempty" bson:"modules"`
Containers []Container `yaml:"containers,omitempty" bson:"containers"`
BuildVariants BuildVariants `yaml:"buildvariants,omitempty" bson:"build_variants"`
Functions map[string]*YAMLCommandSet `yaml:"functions,omitempty" bson:"functions"`
TaskGroups []TaskGroup `yaml:"task_groups,omitempty" bson:"task_groups"`
Tasks []ProjectTask `yaml:"tasks,omitempty" bson:"tasks"`
ExecTimeoutSecs int `yaml:"exec_timeout_secs,omitempty" bson:"exec_timeout_secs"`
TimeoutSecs int `yaml:"timeout_secs,omitempty" bson:"timeout_secs"`
Loggers *LoggerConfig `yaml:"loggers,omitempty" bson:"loggers,omitempty"`
// Flag that indicates a project as requiring user authentication
Private bool `yaml:"private,omitempty" bson:"private"`
// Number of includes in the project cached for validation
NumIncludes int `yaml:"-" bson:"-"`
}
type ProjectInfo struct {
Ref *ProjectRef
Project *Project
IntermediateProject *ParserProject
Config *ProjectConfig
}
type PatchConfig struct {
PatchedParserProjectYAML string
PatchedParserProject *ParserProject
PatchedProjectConfig string
}
func (p *ProjectInfo) NotPopulated() bool {
return p.Ref == nil || p.IntermediateProject == nil
}
// Unmarshalled from the "tasks" list in an individual build variant. Can be either a task or task group
type BuildVariantTaskUnit struct {
// Name has to match the name field of one of the tasks or groups specified at
// the project level, or an error will be thrown
Name string `yaml:"name,omitempty" bson:"name"`
// IsGroup indicates that it is a task group. This is always populated for
// task groups after project translation.
IsGroup bool `yaml:"-" bson:"-"`
// IsPartOfGroup indicates that this unit is a task within a task group. If
// this is set, then GroupName is also set.
// Note that project translation does not expand task groups into their
// individual tasks, so this is only set for special functions that
// explicitly expand task groups into individual task units (such as
// FindAllBuildVariantTasks).
IsPartOfGroup bool `yaml:"-" bson:"-"`
// GroupName is the task group name if this is a task in a task group. This
// is only set if the task unit is a task within a task group (i.e.
// IsPartOfGroup is set). If the task unit is the task group itself, it is
// not populated (Name is the task group name).
// Note that project translation does not expand task groups into their
// individual tasks, so this is only set for special functions that
// explicitly expand task groups into individual task units (such as
// FindAllBuildVariantTasks).
GroupName string `yaml:"-" bson:"-"`
// Variant is the build variant that the task unit is part of. This is
// always populated after translating the parser project to the project.
Variant string `yaml:"-" bson:"-"`
// fields to overwrite ProjectTask settings.
Patchable *bool `yaml:"patchable,omitempty" bson:"patchable,omitempty"`
PatchOnly *bool `yaml:"patch_only,omitempty" bson:"patch_only,omitempty"`
Disable *bool `yaml:"disable,omitempty" bson:"disable,omitempty"`
AllowForGitTag *bool `yaml:"allow_for_git_tag,omitempty" bson:"allow_for_git_tag,omitempty"`
GitTagOnly *bool `yaml:"git_tag_only,omitempty" bson:"git_tag_only,omitempty"`
AllowedRequesters []evergreen.UserRequester `yaml:"allowed_requesters,omitempty" bson:"allowed_requesters,omitempty"`
Priority int64 `yaml:"priority,omitempty" bson:"priority"`
DependsOn []TaskUnitDependency `yaml:"depends_on,omitempty" bson:"depends_on"`
// the distros that the task can be run on
RunOn []string `yaml:"run_on,omitempty" bson:"run_on"`
Stepback *bool `yaml:"stepback,omitempty" bson:"stepback,omitempty"`
CommitQueueMerge bool `yaml:"commit_queue_merge,omitempty" bson:"commit_queue_merge"`
// Use a *int for 2 possible states
// nil - not overriding the project setting
// non-nil - overriding the project setting with this BatchTime
BatchTime *int `yaml:"batchtime,omitempty" bson:"batchtime,omitempty"`
// If CronBatchTime is not empty, then override the project settings with cron syntax,
// with BatchTime and CronBatchTime being mutually exclusive.
CronBatchTime string `yaml:"cron,omitempty" bson:"cron,omitempty"`
// If Activate is set to false, then we don't initially activate the task.
Activate *bool `yaml:"activate,omitempty" bson:"activate,omitempty"`
// TaskGroup is set if an inline task group is defined on the build variant.
TaskGroup *TaskGroup `yaml:"task_group,omitempty" bson:"task_group,omitempty"`
// CreateCheckRun will create a check run on GitHub if set.
CreateCheckRun *CheckRun `yaml:"create_check_run,omitempty" bson:"create_check_run,omitempty"`
}
func (b BuildVariant) Get(name string) (BuildVariantTaskUnit, error) {
for idx := range b.Tasks {
if b.Tasks[idx].Name == name {
return b.Tasks[idx], nil
}
}
return BuildVariantTaskUnit{}, errors.Errorf("could not find task '%s' in build variant '%s'", name, b.Name)
}
func (b BuildVariant) GetDisplayTask(name string) *patch.DisplayTask {
for _, dt := range b.DisplayTasks {
if dt.Name == name {
return &dt
}
}
return nil
}
type BuildVariants []BuildVariant
func (b BuildVariants) Len() int { return len(b) }
func (b BuildVariants) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b BuildVariants) Less(i, j int) bool { return b[i].DisplayName < b[j].DisplayName }
func (b BuildVariants) Get(name string) (BuildVariant, error) {
for idx := range b {
if b[idx].Name == name {
return b[idx], nil
}
}
return BuildVariant{}, errors.Errorf("could not find build variant named '%s'", name)
}
// Populate updates the base fields of the BuildVariantTaskUnit with
// fields from the project task definition and build variant definition. When
// there are conflicting settings defined at different levels, the priority of
// settings are (from highest to lowest):
// * Task settings within a build variant's list of tasks
// * Task settings within a task group's list of tasks
// * Project task's settings
// * Build variant's settings
func (bvt *BuildVariantTaskUnit) Populate(pt ProjectTask, bv BuildVariant) {
// We never update "Name" or "Commands"
if len(bvt.DependsOn) == 0 {
bvt.DependsOn = pt.DependsOn
}
if len(bvt.RunOn) == 0 {
bvt.RunOn = pt.RunOn
}
if bvt.Priority == 0 {
bvt.Priority = pt.Priority
}
if bvt.Patchable == nil {
bvt.Patchable = pt.Patchable
}
if bvt.PatchOnly == nil {
bvt.PatchOnly = pt.PatchOnly
}
if bvt.Disable == nil {
bvt.Disable = pt.Disable
}
if bvt.AllowForGitTag == nil {
bvt.AllowForGitTag = pt.AllowForGitTag
}
if bvt.GitTagOnly == nil {
bvt.GitTagOnly = pt.GitTagOnly
}
if len(bvt.AllowedRequesters) == 0 {
bvt.AllowedRequesters = pt.AllowedRequesters
}
if bvt.Stepback == nil {
bvt.Stepback = pt.Stepback
}
// Build variant level settings are lower priority than project task level
// settings.
if bvt.Patchable == nil {
bvt.Patchable = bv.Patchable
}
if bvt.PatchOnly == nil {
bvt.PatchOnly = bv.PatchOnly
}
if bvt.AllowForGitTag == nil {
bvt.AllowForGitTag = bv.AllowForGitTag
}
if bvt.GitTagOnly == nil {
bvt.GitTagOnly = bv.GitTagOnly
}
if len(bvt.AllowedRequesters) == 0 {
bvt.AllowedRequesters = bv.AllowedRequesters
}
if bvt.Disable == nil {
bvt.Disable = bv.Disable
}
}
// BuildVariantsByName represents a slice of project config build variants that
// can be sorted by name.
type BuildVariantsByName []BuildVariant
func (b BuildVariantsByName) Len() int { return len(b) }
func (b BuildVariantsByName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b BuildVariantsByName) Less(i, j int) bool { return b[i].Name < b[j].Name }
// ProjectTasksByName represents a slice of project config tasks that can be
// sorted by name.
type ProjectTasksByName []ProjectTask
func (pt ProjectTasksByName) Len() int { return len(pt) }
func (pt ProjectTasksByName) Swap(i, j int) { pt[i], pt[j] = pt[j], pt[i] }
func (pt ProjectTasksByName) Less(i, j int) bool { return pt[i].Name < pt[j].Name }
// TaskGroupsByName represents a slice of project config task grups that can be
// sorted by name.
type TaskGroupsByName []TaskGroup
func (tg TaskGroupsByName) Len() int { return len(tg) }
func (tg TaskGroupsByName) Swap(i, j int) { tg[i], tg[j] = tg[j], tg[i] }
func (tg TaskGroupsByName) Less(i, j int) bool { return tg[i].Name < tg[j].Name }
// UnmarshalYAML allows tasks to be referenced as single selector strings.
// This works by first attempting to unmarshal the YAML into a string
// and then falling back to the BuildVariantTaskUnit struct.
func (bvt *BuildVariantTaskUnit) UnmarshalYAML(unmarshal func(interface{}) error) error {
// first, attempt to unmarshal just a selector string
var onlySelector string
if err := unmarshal(&onlySelector); err == nil {
bvt.Name = onlySelector
return nil
}
// we define a new type so that we can grab the yaml struct tags without the struct methods,
// preventing infinte recursion on the UnmarshalYAML() method.
type bvtCopyType BuildVariantTaskUnit
var bvtc bvtCopyType
err := unmarshal(&bvtc)
if err != nil {
return err
}
*bvt = BuildVariantTaskUnit(bvtc)
return nil
}
func (bvt *BuildVariantTaskUnit) SkipOnRequester(requester string) bool {
if len(bvt.AllowedRequesters) != 0 {
return !utility.StringSliceContains(evaluateRequesters(bvt.AllowedRequesters), requester)
}
return evergreen.IsPatchRequester(requester) && bvt.SkipOnPatchBuild() ||
!evergreen.IsPatchRequester(requester) && bvt.SkipOnNonPatchBuild() ||
evergreen.IsGitTagRequester(requester) && bvt.SkipOnGitTagBuild() ||
!evergreen.IsGitTagRequester(requester) && bvt.SkipOnNonGitTagBuild()
}
func (bvt *BuildVariantTaskUnit) SkipOnPatchBuild() bool {
if len(bvt.AllowedRequesters) != 0 {
allowed := utility.StringSliceIntersection(evaluateRequesters(bvt.AllowedRequesters), evergreen.PatchRequesters)
return len(allowed) == 0
}
return !utility.FromBoolTPtr(bvt.Patchable)
}
func (bvt *BuildVariantTaskUnit) SkipOnNonPatchBuild() bool {
if len(bvt.AllowedRequesters) != 0 {
allowed, _ := utility.StringSliceSymmetricDifference(evaluateRequesters(bvt.AllowedRequesters), evergreen.PatchRequesters)
return len(allowed) == 0
}
return utility.FromBoolPtr(bvt.PatchOnly)
}
func (bvt *BuildVariantTaskUnit) SkipOnGitTagBuild() bool {
if len(bvt.AllowedRequesters) != 0 {
return !utility.StringSliceContains(evaluateRequesters(bvt.AllowedRequesters), evergreen.GitTagRequester)
}
return !utility.FromBoolTPtr(bvt.AllowForGitTag)
}
func (bvt *BuildVariantTaskUnit) SkipOnNonGitTagBuild() bool {
if len(bvt.AllowedRequesters) != 0 {
allowed, _ := utility.StringSliceSymmetricDifference(evaluateRequesters(bvt.AllowedRequesters), []string{evergreen.GitTagRequester})
return len(allowed) == 0
}
return utility.FromBoolPtr(bvt.GitTagOnly)
}
// IsDisabled returns whether or not this build variant task is disabled.
func (bvt *BuildVariantTaskUnit) IsDisabled() bool {
return utility.FromBoolPtr(bvt.Disable)
}
func (bvt *BuildVariantTaskUnit) toTaskNode() task.TaskNode {
return task.TaskNode{
Name: bvt.Name,
Variant: bvt.Variant,
}
}
func (bvt *BuildVariantTaskUnit) ToTVPair() TVPair {
return TVPair{
TaskName: bvt.Name,
Variant: bvt.Variant,
}
}
type BuildVariant struct {
Name string `yaml:"name,omitempty" bson:"name"`
DisplayName string `yaml:"display_name,omitempty" bson:"display_name"`
Expansions map[string]string `yaml:"expansions,omitempty" bson:"expansions"`
Modules []string `yaml:"modules,omitempty" bson:"modules"`
Tags []string `yaml:"tags,omitempty" bson:"tags"`
// Use a *int for 2 possible states
// nil - not overriding the project setting
// non-nil - overriding the project setting with this BatchTime
BatchTime *int `yaml:"batchtime,omitempty" bson:"batchtime,omitempty"`
// If CronBatchTime is not empty, then override the project settings with cron syntax,
// with BatchTime and CronBatchTime being mutually exclusive.
CronBatchTime string `yaml:"cron,omitempty" bson:"cron,omitempty"`
// If Activate is set to false, then we don't initially activate the build
// variant. By default, the build variant is activated.
Activate *bool `yaml:"activate,omitempty" bson:"activate,omitempty"`
// Disable will disable tasks in the build variant, preventing them from
// running and omitting them if they're dependencies. By default, the build
// variant is not disabled.
Disable *bool `yaml:"disable,omitempty" bson:"disable"`
// Patchable will prevent tasks in this build variant from running in
// patches when set to false. By default, the build variant runs in patches.
Patchable *bool `yaml:"patchable,omitempty" bson:"patchable,omitempty"`
// PatchOnly will only allow tasks in the build variant to run in patches
// when set to true. By default, the build variant runs for non-patches.
PatchOnly *bool `yaml:"patch_only,omitempty" bson:"patch_only,omitempty"`
// AllowForGitTag will prevent tasks in this build variant from running in
// git tag versions when set to false. By default, the build variant runs in
// git tag versions.
AllowForGitTag *bool `yaml:"allow_for_git_tag,omitempty" bson:"allow_for_git_tag,omitempty"`
// GitTagOnly will only allow tasks in the build variant to run in git tag
// versions when set to true. By default, the build variant runs in non-git
// tag versions.
GitTagOnly *bool `yaml:"git_tag_only,omitempty" bson:"git_tag_only,omitempty"`
// AllowedRequesters lists all internal requester types which can run a
// task. If set, the allowed requesters take precedence over other
// requester-related filters such as Patchable, PatchOnly, AllowForGitTag,
// and GitTagOnly. By default, all requesters are allowed to run the task.
AllowedRequesters []evergreen.UserRequester `yaml:"allowed_requesters,omitempty" bson:"allowed_requesters,omitempty"`
// Use a *bool so that there are 3 possible states:
// 1. nil = not overriding the project setting (default)
// 2. true = overriding the project setting with true
// 3. false = overriding the project setting with false
Stepback *bool `yaml:"stepback,omitempty" bson:"stepback,omitempty"`
// the default distros. will be used to run a task if no distro field is
// provided for the task
RunOn []string `yaml:"run_on,omitempty" bson:"run_on"`
// all of the tasks/groups to be run on the build variant, compile through tests.
Tasks []BuildVariantTaskUnit `yaml:"tasks,omitempty" bson:"tasks"`
DisplayTasks []patch.DisplayTask `yaml:"display_tasks,omitempty" bson:"display_tasks,omitempty"`
// EmptyTaskSelectors stores task selectors that don't target any tasks for this build variant.
// This is only for validation purposes.
EmptyTaskSelectors []string `yaml:"-" bson:"-"`
}
// CheckRun is used to provide information about a github check run.
type CheckRun struct {
// PathToOutputs is a local file path to an output json file for the checkrun.
PathToOutputs string `yaml:"path_to_outputs" bson:"path_to_outputs"`
}
// ParameterInfo is used to provide extra information about a parameter.
type ParameterInfo struct {
patch.Parameter `yaml:",inline" bson:",inline"`
Description string `yaml:"description" bson:"description"`
}
// Container holds all properties that are configurable when defining a container
// for tasks and build variants to run on in a project YAML file.
type Container struct {
Name string `yaml:"name" bson:"name"`
WorkingDir string `yaml:"working_dir,omitempty" bson:"working_dir"`
Image string `yaml:"image" bson:"image" plugin:"expand"`
Size string `yaml:"size,omitempty" bson:"size"`
Credential string `yaml:"credential,omitempty" bson:"credential"`
Resources *ContainerResources `yaml:"resources,omitempty" bson:"resources"`
System ContainerSystem `yaml:"system,omitempty" bson:"system"`
}
// ContainerSystem specifies the architecture and OS for the running container to use.
type ContainerSystem struct {
CPUArchitecture evergreen.ContainerArch `yaml:"cpu_architecture,omitempty" bson:"cpu_architecture"`
OperatingSystem evergreen.ContainerOS `yaml:"operating_system,omitempty" bson:"operating_system"`
WindowsVersion evergreen.WindowsVersion `yaml:"windows_version,omitempty" bson:"windows_version"`
}
// Module specifies the git details of another git project to be included within a
// given version at runtime. Module fields include the expand plugin tag because they
// need to support project ref variable expansions.
type Module struct {
Name string `yaml:"name,omitempty" bson:"name" plugin:"expand"`
Branch string `yaml:"branch,omitempty" bson:"branch" plugin:"expand"`
Repo string `yaml:"repo,omitempty" bson:"repo" plugin:"expand"`
Owner string `yaml:"owner,omitempty" bson:"owner" plugin:"expand"`
Prefix string `yaml:"prefix,omitempty" bson:"prefix" plugin:"expand"`
Ref string `yaml:"ref,omitempty" bson:"ref" plugin:"expand"`
AutoUpdate bool `yaml:"auto_update,omitempty" bson:"auto_update"`
}
// GetOwnerAndRepo returns the owner and repo for a module
// If the owner is not set, it will attempt to parse the repo URL to get the owner
// and repo.
func (m Module) GetOwnerAndRepo() (string, string, error) {
if m.Owner == "" {
return thirdparty.ParseGitUrl(m.Repo)
}
return m.Owner, m.Repo, nil
}
type Include struct {
FileName string `yaml:"filename,omitempty" bson:"filename,omitempty"`
Module string `yaml:"module,omitempty" bson:"module,omitempty"`
}
type ModuleList []Module
func (l *ModuleList) IsIdentical(m manifest.Manifest) bool {
manifestModules := map[string]manifest.Module{}
for name, module := range m.Modules {
manifestModules[name] = manifest.Module{
Branch: module.Branch,
Repo: module.Repo,
Owner: module.Owner,
}
}
projectModules := map[string]manifest.Module{}
for _, module := range *l {
owner, repo, err := module.GetOwnerAndRepo()
if err != nil {
return false
}
projectModules[module.Name] = manifest.Module{
Branch: module.Branch,
Repo: repo,
Owner: owner,
}
}
return reflect.DeepEqual(manifestModules, projectModules)
}
func GetModuleByName(moduleList ModuleList, moduleName string) (*Module, error) {
for _, module := range moduleList {
if module.Name == moduleName {
return &module, nil
}
}
return nil, errors.Errorf("module '%s' doesn't exist", moduleName)
}
type PluginCommandConf struct {
Function string `yaml:"func,omitempty" bson:"func,omitempty"`
// Type is used to differentiate between setup related commands and actual
// testing commands.
Type string `yaml:"type,omitempty" bson:"type,omitempty"`
// DisplayName is a human readable description of the function of a given
// command.
DisplayName string `yaml:"display_name,omitempty" bson:"display_name,omitempty"`
// Command is a unique identifier for the command configuration. It consists of a
// plugin name and a command name.
Command string `yaml:"command,omitempty" bson:"command,omitempty"`
// Variants is used to enumerate the particular sets of buildvariants to run
// this command configuration on. If it is empty, it is run on all defined
// variants.
Variants []string `yaml:"variants,omitempty" bson:"variants,omitempty"`
// TimeoutSecs indicates the maximum duration the command is allowed to run for.
TimeoutSecs int `yaml:"timeout_secs,omitempty" bson:"timeout_secs,omitempty"`
// Params is used to define params in the yaml and parser project,
// but is not stored in the DB (instead see ParamsYAML).
Params map[string]interface{} `yaml:"params,omitempty" bson:"-"`
// ParamsYAML is the marshalled Params to store in the database, to preserve nested interfaces.
ParamsYAML string `yaml:"params_yaml,omitempty" bson:"params_yaml,omitempty"`
// Vars defines variables that can be used within commands.
Vars map[string]string `yaml:"vars,omitempty" bson:"vars,omitempty"`
// RetryOnFailure indicates whether the task should be retried if this command fails.
RetryOnFailure bool `yaml:"retry_on_failure,omitempty" bson:"retry_on_failure,omitempty"`
Loggers *LoggerConfig `yaml:"loggers,omitempty" bson:"loggers,omitempty"`
}
func (c *PluginCommandConf) resolveParams() error {
out := map[string]interface{}{}
if c == nil {
return nil
}
if c.ParamsYAML != "" {
if err := yaml.Unmarshal([]byte(c.ParamsYAML), &out); err != nil {
return errors.Wrapf(err, "unmarshalling params from YAML")
}
c.Params = out
}
return nil
}
func (c *PluginCommandConf) UnmarshalYAML(unmarshal func(interface{}) error) error {
temp := struct {
Function string `yaml:"func,omitempty" bson:"func,omitempty"`
Type string `yaml:"type,omitempty" bson:"type,omitempty"`
DisplayName string `yaml:"display_name,omitempty" bson:"display_name,omitempty"`
Command string `yaml:"command,omitempty" bson:"command,omitempty"`
Variants []string `yaml:"variants,omitempty" bson:"variants,omitempty"`
TimeoutSecs int `yaml:"timeout_secs,omitempty" bson:"timeout_secs,omitempty"`
Params map[string]interface{} `yaml:"params,omitempty" bson:"params,omitempty"`
ParamsYAML string `yaml:"params_yaml,omitempty" bson:"params_yaml,omitempty"`
Vars map[string]string `yaml:"vars,omitempty" bson:"vars,omitempty"`
RetryOnFailure bool `yaml:"retry_on_failure,omitempty" bson:"retry_on_failure,omitempty"`
Loggers *LoggerConfig `yaml:"loggers,omitempty" bson:"loggers,omitempty"`
}{}
if err := unmarshal(&temp); err != nil {
return errors.Wrap(err, "input fields may not match the command fields")
}
c.Function = temp.Function
c.Type = temp.Type
c.DisplayName = temp.DisplayName
c.Command = temp.Command
c.Variants = temp.Variants
c.TimeoutSecs = temp.TimeoutSecs
c.Vars = temp.Vars
c.Loggers = temp.Loggers
c.ParamsYAML = temp.ParamsYAML
c.Params = temp.Params
c.RetryOnFailure = temp.RetryOnFailure
return c.unmarshalParams()
}
func (c *PluginCommandConf) UnmarshalBSON(in []byte) error {
if err := mgobson.Unmarshal(in, c); err != nil {
return err
}
return c.unmarshalParams()
}
// We read from YAML when available, as the given params could be corrupted from the roundtrip.
// If params is passed, then it means that we haven't yet stored this in the DB.
func (c *PluginCommandConf) unmarshalParams() error {
if c.ParamsYAML != "" {
out := map[string]interface{}{}
if err := yaml.Unmarshal([]byte(c.ParamsYAML), &out); err != nil {
return errors.Wrap(err, "unmarshalling params from YAML")
}
c.Params = out
return nil
}
if len(c.Params) != 0 {
bytes, err := yaml.Marshal(c.Params)
if err != nil {
return errors.Wrap(err, "marshalling params into YAML")
}
c.ParamsYAML = string(bytes)
}
return nil
}
type ArtifactInstructions struct {
Include []string `yaml:"include,omitempty" bson:"include"`
ExcludeFiles []string `yaml:"excludefiles,omitempty" bson:"exclude_files"`
}
type YAMLCommandSet struct {
SingleCommand *PluginCommandConf `yaml:"single_command,omitempty" bson:"single_command,omitempty"`
MultiCommand []PluginCommandConf `yaml:"multi_command,omitempty" bson:"multi_command,omitempty"`
}
func (c *YAMLCommandSet) List() []PluginCommandConf {
if len(c.MultiCommand) > 0 {
return c.MultiCommand
}
if c.SingleCommand != nil && (c.SingleCommand.Command != "" || c.SingleCommand.Function != "") {
return []PluginCommandConf{*c.SingleCommand}
}
return []PluginCommandConf{}
}
func (c *YAMLCommandSet) MarshalYAML() (interface{}, error) {
if c == nil {
return nil, nil
}
res := c.List()
for idx := range res {
if err := res[idx].resolveParams(); err != nil {
return nil, errors.Wrap(err, "resolving params for command set")
}
}
return res, nil
}
func (c *YAMLCommandSet) UnmarshalYAML(unmarshal func(interface{}) error) error {
err1 := unmarshal(&(c.MultiCommand))
err2 := unmarshal(&(c.SingleCommand))
if err1 == nil || err2 == nil {
return nil
}
return err1
}
// TaskUnitDependency holds configuration information about a task/group that must finish before
// the task/group that contains the dependency can run.
type TaskUnitDependency struct {
Name string `yaml:"name,omitempty" bson:"name"`
Variant string `yaml:"variant,omitempty" bson:"variant,omitempty"`
Status string `yaml:"status,omitempty" bson:"status,omitempty"`
PatchOptional bool `yaml:"patch_optional,omitempty" bson:"patch_optional,omitempty"`
OmitGeneratedTasks bool `yaml:"omit_generated_tasks,omitempty" bson:"omit_generated_tasks,omitempty"`
}
// UnmarshalYAML allows tasks to be referenced as single selector strings.
// This works by first attempting to unmarshal the YAML into a string
// and then falling back to the TaskUnitDependency struct.
func (td *TaskUnitDependency) UnmarshalYAML(unmarshal func(interface{}) error) error {
// first, attempt to unmarshal just a selector string
var onlySelector string
if err := unmarshal(&onlySelector); err == nil {
td.Name = onlySelector
return nil
}
// we define a new type so that we can grab the yaml struct tags without the struct methods,
// preventing infinte recursion on the UnmarshalYAML() method.
type tdCopyType TaskUnitDependency
var tdc tdCopyType
err := unmarshal(&tdc)
if err != nil {
return err
}
*td = TaskUnitDependency(tdc)
return nil
}
type TaskGroup struct {
Name string `yaml:"name" bson:"name"`
// data about the task group
MaxHosts int `yaml:"max_hosts" bson:"max_hosts"`
SetupGroup *YAMLCommandSet `yaml:"setup_group" bson:"setup_group"`
SetupGroupCanFailTask bool `yaml:"setup_group_can_fail_task" bson:"setup_group_can_fail_task"`
SetupGroupTimeoutSecs int `yaml:"setup_group_timeout_secs" bson:"setup_group_timeout_secs"`
TeardownGroup *YAMLCommandSet `yaml:"teardown_group" bson:"teardown_group"`
TeardownGroupTimeoutSecs int `yaml:"teardown_group_timeout_secs" bson:"teardown_group_timeout_secs"`
SetupTask *YAMLCommandSet `yaml:"setup_task" bson:"setup_task"`
SetupTaskCanFailTask bool `yaml:"setup_task_can_fail_task,omitempty" bson:"setup_task_can_fail_task,omitempty"`
SetupTaskTimeoutSecs int `yaml:"setup_task_timeout_secs,omitempty" bson:"setup_task_timeout_secs,omitempty"`
TeardownTask *YAMLCommandSet `yaml:"teardown_task" bson:"teardown_task"`
TeardownTaskCanFailTask bool `yaml:"teardown_task_can_fail_task" bson:"teardown_task_can_fail_task"`
TeardownTaskTimeoutSecs int `yaml:"teardown_task_timeout_secs,omitempty" bson:"teardown_task_timeout_secs,omitempty"`
Timeout *YAMLCommandSet `yaml:"timeout,omitempty" bson:"timeout"`
CallbackTimeoutSecs int `yaml:"callback_timeout_secs,omitempty" bson:"callback_timeout_secs,omitempty"`
Tasks []string `yaml:"tasks" bson:"tasks"`
Tags []string `yaml:"tags,omitempty" bson:"tags"`
// ShareProcs causes processes to persist between task group tasks.
ShareProcs bool `yaml:"share_processes" bson:"share_processes"`
}
// Unmarshalled from the "tasks" list in the project file
type ProjectTask struct {
Name string `yaml:"name,omitempty" bson:"name"`
Priority int64 `yaml:"priority,omitempty" bson:"priority"`
ExecTimeoutSecs int `yaml:"exec_timeout_secs,omitempty" bson:"exec_timeout_secs"`
DependsOn []TaskUnitDependency `yaml:"depends_on,omitempty" bson:"depends_on"`
Commands []PluginCommandConf `yaml:"commands,omitempty" bson:"commands"`
Tags []string `yaml:"tags,omitempty" bson:"tags"`
RunOn []string `yaml:"run_on,omitempty" bson:"run_on"`
// Use a *bool so that there are 3 possible states:
// 1. nil = not overriding the project setting (default)
// 2. true = overriding the project setting with true
// 3. false = overriding the project setting with false
Patchable *bool `yaml:"patchable,omitempty" bson:"patchable,omitempty"`
PatchOnly *bool `yaml:"patch_only,omitempty" bson:"patch_only,omitempty"`
Disable *bool `yaml:"disable,omitempty" bson:"disable,omitempty"`
AllowForGitTag *bool `yaml:"allow_for_git_tag,omitempty" bson:"allow_for_git_tag,omitempty"`
GitTagOnly *bool `yaml:"git_tag_only,omitempty" bson:"git_tag_only,omitempty"`
AllowedRequesters []evergreen.UserRequester `yaml:"allowed_requesters,omitempty" bson:"allowed_requesters,omitempty"`
Stepback *bool `yaml:"stepback,omitempty" bson:"stepback,omitempty"`
MustHaveResults *bool `yaml:"must_have_test_results,omitempty" bson:"must_have_test_results,omitempty"`
}
type LoggerConfig struct {
Agent []LogOpts `yaml:"agent,omitempty" bson:"agent,omitempty"`
System []LogOpts `yaml:"system,omitempty" bson:"system,omitempty"`
Task []LogOpts `yaml:"task,omitempty" bson:"task,omitempty"`
}
type LogOpts struct {
Type string `yaml:"type,omitempty" bson:"type,omitempty"`
SplunkServer string `yaml:"splunk_server,omitempty" bson:"splunk_server,omitempty"`
SplunkToken string `yaml:"splunk_token,omitempty" bson:"splunk_token,omitempty"`
LogDirectory string `yaml:"log_directory,omitempty" bson:"log_directory,omitempty"`
}
func (c *LoggerConfig) IsValid() error {
if c == nil {
return nil
}
catcher := grip.NewBasicCatcher()
for _, opts := range c.Agent {
catcher.Wrap(opts.IsValid(), "invalid agent logger config")
}
for _, opts := range c.System {
catcher.Wrap(opts.IsValid(), "invalid system logger config")
if opts.Type == FileLogSender {
catcher.New("file logger is disallowed for system logs; will use Evergreen logger")
}
}
for _, opts := range c.Task {
catcher.Wrap(opts.IsValid(), "invalid task logger config")
}
return catcher.Resolve()
}
func (o *LogOpts) IsValid() error {
catcher := grip.NewBasicCatcher()
if !utility.StringSliceContains(ValidLogSenders, o.Type) {
catcher.Errorf("'%s' is not a valid log sender", o.Type)
}
if o.Type == SplunkLogSender && o.SplunkServer == "" {
catcher.New("Splunk logger requires a server URL")
}
if o.Type == SplunkLogSender && o.SplunkToken == "" {
catcher.New("Splunk logger requires a token")
}
return catcher.Resolve()
}
func mergeAllLogs(main, add *LoggerConfig) *LoggerConfig {
if main == nil {
return add
} else if add == nil {
return main
} else {
main.Agent = append(main.Agent, add.Agent...)
main.System = append(main.System, add.System...)
main.Task = append(main.Task, add.Task...)
}
return main
}
const (
EvergreenLogSender = "evergreen"
FileLogSender = "file"
SplunkLogSender = "splunk"
)
var ValidLogSenders = []string{
EvergreenLogSender,
FileLogSender,
SplunkLogSender,
}
// TaskIdTable is a map of [variant, task display name]->[task id].
type TaskIdTable map[TVPair]string
// TaskIdConfig stores TaskIdTables split by execution and display tasks.
type TaskIdConfig struct {
ExecutionTasks TaskIdTable
DisplayTasks TaskIdTable
}
// TVPair is a helper type for mapping bv/task pairs to ids.
type TVPair struct {
Variant string
TaskName string
}
type TVPairSet []TVPair
// ByVariant returns a list of TVPairs filtered to include only those
// for the given variant
func (tvps TVPairSet) ByVariant(variant string) TVPairSet {
p := []TVPair{}
for _, pair := range tvps {
if pair.Variant != variant {
continue
}
p = append(p, pair)
}
return TVPairSet(p)
}
// TaskNames extracts the unique set of task names for a given variant in the set of task/variant pairs.
func (tvps TVPairSet) TaskNames(variant string) []string {
taskSet := map[string]bool{}
taskNames := []string{}
for _, pair := range tvps {
// skip over any pairs that aren't for the given variant
if pair.Variant != variant {
continue
}
// skip over tasks we already picked up
if _, ok := taskSet[pair.TaskName]; ok {
continue
}
taskSet[pair.TaskName] = true
taskNames = append(taskNames, pair.TaskName)
}
return taskNames
}
// String returns the pair's name in a readable form.
func (p TVPair) String() string {
return fmt.Sprintf("%v/%v", p.Variant, p.TaskName)
}
// AddId adds the Id for the task/variant combination to the table.
func (tt TaskIdTable) AddId(variant, taskName, id string) {
tt[TVPair{variant, taskName}] = id
}
// GetId returns the Id for the given task on the given variant.
// Returns the empty string if the task/variant does not exist.
func (tt TaskIdTable) GetId(variant, taskName string) string {
return tt[TVPair{variant, taskName}]
}
// GetIdsForTaskInAllVariants returns all task Ids for taskName on all variants
func (tt TaskIdTable) GetIdsForTaskInAllVariants(taskName string) []string {
ids := []string{}
for pair, id := range tt {
if pair.TaskName != taskName || id == "" {
continue
}
ids = append(ids, id)
}
return ids
}
// GetIdsForAllTasksInVariant returns all task Ids for all tasks on a variant
func (tt TaskIdTable) GetIdsForAllTasksInVariant(variantName string) []string {
ids := []string{}
for pair, id := range tt {
if pair.Variant != variantName || id == "" {
continue
}
ids = append(ids, id)
}
return ids
}
// GetIdsForAllTasks returns every id in the table
func (tt TaskIdTable) GetIdsForAllTasks() []string {
ids := make([]string, 0, len(tt))
for _, id := range tt {
if id == "" {
continue
}
ids = append(ids, id)
}
return ids
}
func (t TaskIdConfig) Length() int {
return len(t.ExecutionTasks) + len(t.DisplayTasks)
}
// NewTaskIdConfigForRepotrackerVersion creates a special TaskIdTable for a
// repotracker version.
func NewTaskIdConfigForRepotrackerVersion(p *Project, v *Version, sourceRev, defID string) TaskIdConfig {
// init the variant map
execTable := TaskIdTable{}
displayTable := TaskIdTable{}
sort.Stable(p.BuildVariants)
projectIdentifier, err := GetIdentifierForProject(p.Identifier)
if err != nil { // default to ID
projectIdentifier = p.Identifier
}
for _, bv := range p.BuildVariants {
rev := v.Revision
if evergreen.IsPatchRequester(v.Requester) {
rev = fmt.Sprintf("patch_%s_%s", v.Revision, v.Id)
} else if v.Requester == evergreen.TriggerRequester {
rev = fmt.Sprintf("%s_%s", sourceRev, defID)
} else if v.Requester == evergreen.AdHocRequester {
rev = v.Id
} else if v.Requester == evergreen.GitTagRequester {
rev = fmt.Sprintf("%s_%s", sourceRev, v.TriggeredByGitTag.Tag)
}
for _, t := range bv.Tasks {
// omit tasks excluded from the version
if t.IsDisabled() || t.SkipOnRequester(v.Requester) {
continue
}
tg := t.TaskGroup
if tg == nil {
tg = p.FindTaskGroup(t.Name)
}
if tg != nil {
for _, groupTask := range tg.Tasks {
taskId := generateId(groupTask, projectIdentifier, &bv, rev, v)
execTable[TVPair{bv.Name, groupTask}] = util.CleanName(taskId)
}
} else {
// create a unique Id for each task
taskId := generateId(t.Name, projectIdentifier, &bv, rev, v)
execTable[TVPair{bv.Name, t.Name}] = util.CleanName(taskId)
}
}
for _, dt := range bv.DisplayTasks {
name := fmt.Sprintf("display_%s", dt.Name)
taskId := generateId(name, projectIdentifier, &bv, rev, v)
displayTable[TVPair{bv.Name, dt.Name}] = util.CleanName(taskId)
}
}
return TaskIdConfig{ExecutionTasks: execTable, DisplayTasks: displayTable}
}
// NewTaskIdConfig constructs a new set of TaskIdTables (map of [variant, task display name]->[task id])
// split by display and execution tasks.
func NewTaskIdConfig(proj *Project, v *Version, tasks TaskVariantPairs, projectIdentifier string) (TaskIdConfig, error) {
config := TaskIdConfig{ExecutionTasks: TaskIdTable{}, DisplayTasks: TaskIdTable{}}
processedVariants := map[string]bool{}
// resolve task groups to exec tasks
tgMap := map[string]TaskGroup{}
for _, tg := range proj.TaskGroups {
tgMap[tg.Name] = tg
}
for _, variant := range proj.BuildVariants {
for _, t := range variant.Tasks {
if t.TaskGroup != nil {
tgMap[t.Name] = *t.TaskGroup
}
}