-
Notifications
You must be signed in to change notification settings - Fork 163
/
ast.go
931 lines (838 loc) · 35.9 KB
/
ast.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
package actionlint
import (
"fmt"
"sort"
"strconv"
"strings"
"gopkg.in/yaml.v3"
)
// Pos represents position in the file.
type Pos struct {
// Line is a line number of the position. This value is 1-based.
Line int
// Col is a column number of the position. This value is 1-based.
Col int
}
func (p *Pos) String() string {
return fmt.Sprintf("line:%d,col:%d", p.Line, p.Col)
}
// IsBefore returns if the position is before the other position. If they are equal, this function returns false.
func (p *Pos) IsBefore(other *Pos) bool {
if p.Line < other.Line {
return true
}
if p.Line > other.Line {
return false
}
return p.Col < other.Col
}
// String represents generic string value in YAML file with position.
type String struct {
// Value is a raw value of the string.
Value string
// Quoted represents the string is quoted with ' or " in the YAML source.
Quoted bool
// Pos is a position of the string in source.
Pos *Pos
}
// ContainsExpression checks if the given string contains a ${{ }} placeholder or not. This function
// is identical to String.ContainsExpression method except for taking a standard string value.
func ContainsExpression(s string) bool {
i := strings.Index(s, "${{")
return i >= 0 && i < strings.Index(s, "}}")
}
// ContainsExpression returns whether the string contains at least one ${{ }} expression.
func (s *String) ContainsExpression() bool {
return ContainsExpression(s.Value)
}
func isExprAssigned(s string) bool {
v := strings.TrimSpace(s)
// Do not check `strings.Count(s.Value, "}}") == 1` because it might appear in JSON string
// if: ${{ env.foo == '{"foo": {"bar": true}}' }}
return strings.HasPrefix(v, "${{") &&
strings.HasSuffix(v, "}}") &&
strings.Count(v, "${{") == 1
}
// IsExpressionAssigned returns whether a single expression is assigned to the string.
func (s *String) IsExpressionAssigned() bool {
return isExprAssigned(s.Value)
}
// Bool represents generic boolean value in YAML file with position.
type Bool struct {
// Value is a raw value of the bool string.
Value bool
// Expression is a string when expression syntax ${{ }} is used for this section.
Expression *String
// Pos is a position in source.
Pos *Pos
}
func (b *Bool) String() string {
if b.Expression != nil {
return b.Expression.Value
}
if b.Value {
return "true"
}
return "false"
}
// Int represents generic integer value in YAML file with position.
type Int struct {
// Value is a raw value of the integer string.
Value int
// Expression is a string when expression syntax ${{ }} is used for this section.
Expression *String
// Pos is a position in source.
Pos *Pos
}
// Float represents generic float value in YAML file with position.
type Float struct {
// Value is a raw value of the float string.
Value float64
// Expression is a string when expression syntax ${{ }} is used for this section.
Expression *String
// Pos is a position in source.
Pos *Pos
}
// Event interface represents workflow events in 'on' section
type Event interface {
// EventName returns name of the event to trigger this workflow.
EventName() string
}
// WebhookEventFilter is a filter for Webhook events such as 'branches', 'paths-ignore', ...
// Webhook events are filtered by those filters. Some filters are exclusive.
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#using-filters
type WebhookEventFilter struct {
// Name is a name of filter such like 'branches', 'tags'
Name *String
// Values is a list of filter values.
Values []*String
}
// IsEmpty returns true when it has no value. This may mean the WebhookEventFilter instance itself is nil.
func (f *WebhookEventFilter) IsEmpty() bool {
return f == nil || len(f.Values) == 0
}
// WebhookEvent represents event type based on webhook events.
// Some events can't have 'types' field. Only 'push' and 'pull' events can have 'tags', 'tags-ignore',
// 'paths' and 'paths-ignore' fields. Only 'workflow_run' event can have 'workflows' field.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onevent_nametypes
type WebhookEvent struct {
// Hook is a name of the webhook event.
Hook *String
// Types is list of types of the webhook event. Only the types enumerated here will trigger
// the workflow.
Types []*String
// Branches is 'branches' filter. This value is nil when it is omitted.
Branches *WebhookEventFilter
// BranchesIgnore is 'branches-ignore' filter. This value is nil when it is omitted.
BranchesIgnore *WebhookEventFilter
// Tags is 'tags' filter. This value is nil when it is omitted.
Tags *WebhookEventFilter
// TagsIgnore is 'tags-ignore' filter. This value is nil when it is omitted.
TagsIgnore *WebhookEventFilter
// Paths is 'paths' filter. This value is nil when it is omitted.
Paths *WebhookEventFilter
// PathsIgnore is 'paths-ignore' filter. This value is nil when it is omitted.
PathsIgnore *WebhookEventFilter
// Workflows is list of workflow names which are triggered by 'workflow_run' event.
Workflows []*String
// Pos is a position in source.
Pos *Pos
}
// EventName returns name of the event to trigger this workflow.
func (e *WebhookEvent) EventName() string {
return e.Hook.Value
}
// ScheduledEvent is event scheduled by workflow.
// https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#scheduled-events
type ScheduledEvent struct {
// Cron is list of cron strings which schedules workflow.
Cron []*String
// Pos is a position in source.
Pos *Pos
}
// EventName returns name of the event to trigger this workflow.
func (e *ScheduledEvent) EventName() string {
return "schedule"
}
// WorkflowDispatchEventInputType is a type for input types of workflow_dispatch events.
// https://github.blog/changelog/2021-11-10-github-actions-input-types-for-manual-workflows/
type WorkflowDispatchEventInputType uint8
const (
// WorkflowDispatchEventInputTypeNone represents no type is specified to the input of workflow_dispatch event.
WorkflowDispatchEventInputTypeNone WorkflowDispatchEventInputType = iota
// WorkflowDispatchEventInputTypeString is string type of input of workflow_dispatch event.
WorkflowDispatchEventInputTypeString
// WorkflowDispatchEventInputTypeNumber is number type of input of workflow_dispatch event.
WorkflowDispatchEventInputTypeNumber
// WorkflowDispatchEventInputTypeBoolean is boolean type of input of workflow_dispatch event.
WorkflowDispatchEventInputTypeBoolean
// WorkflowDispatchEventInputTypeChoice is choice type of input of workflow_dispatch event.
WorkflowDispatchEventInputTypeChoice
// WorkflowDispatchEventInputTypeEnvironment is environment type of input of workflow_dispatch event.
WorkflowDispatchEventInputTypeEnvironment
)
// DispatchInput is input specified on dispatching workflow manually.
// https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_dispatch
type DispatchInput struct {
// Name is a name of input value specified on dispatching workflow manually.
Name *String
// Description is a description of input value specified on dispatching workflow manually.
Description *String
// Required is a flag to show if this input is mandatory or not on dispatching workflow manually.
Required *Bool
// Default is a default value of input value on dispatching workflow manually.
Default *String
// Type is a type of the input
// https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_dispatch
Type WorkflowDispatchEventInputType
// Options is list of options of choice type
Options []*String
}
// WorkflowDispatchEvent is event on dispatching workflow manually.
// https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow_dispatch
type WorkflowDispatchEvent struct {
// Inputs is map from input names to input attributes. Keys are in lower case since they are case insensitive.
Inputs map[string]*DispatchInput
// Pos is a position in source.
Pos *Pos
}
// EventName returns name of the event to trigger this workflow.
func (e *WorkflowDispatchEvent) EventName() string {
return "workflow_dispatch"
}
// RepositoryDispatchEvent is repository_dispatch event configuration.
// https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#repository_dispatch
type RepositoryDispatchEvent struct {
// Types is list of types which can trigger workflow.
Types []*String
// Pos is a position in source.
Pos *Pos
}
// EventName returns name of the event to trigger this workflow.
func (e *RepositoryDispatchEvent) EventName() string {
return "repository_dispatch"
}
// WorkflowCallEventInputType is a type of inputs at workflow_call event.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_callinput_idtype
type WorkflowCallEventInputType uint8
const (
// WorkflowCallEventInputTypeInvalid represents invalid type input as default value of the type.
WorkflowCallEventInputTypeInvalid WorkflowCallEventInputType = iota
// WorkflowCallEventInputTypeBoolean represents boolean type input.
WorkflowCallEventInputTypeBoolean
// WorkflowCallEventInputTypeNumber represents number type input.
WorkflowCallEventInputTypeNumber
// WorkflowCallEventInputTypeString represents string type input.
WorkflowCallEventInputTypeString
)
// WorkflowCallEventInput is an input configuration of workflow_call event.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_callinputs
type WorkflowCallEventInput struct {
// Name is a name of the input.
Name *String
// Description is a description of the input.
Description *String
// Default is a default value of the input. Nil means no default value.
Default *String
// Required represents if the input is required or optional. When this value is nil, it was not explicitly specified.
// In the case the default value is 'not required'.
Required *Bool
// Type of the input, which must be one of 'boolean', 'number' or 'string'. This property is required.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_callinput_idtype
Type WorkflowCallEventInputType
// ID is an ID of the input. Input ID is in lower case because it is case-insensitive.
ID string
}
// IsRequired returns if the input is marked as required or not.
// require
func (i *WorkflowCallEventInput) IsRequired() bool {
return i.Required != nil && i.Required.Value
}
// WorkflowCallEventSecret is a secret configuration of workflow_call event.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_callsecrets
type WorkflowCallEventSecret struct {
// Name is a name of the secret.
Name *String
// Description is a description of the secret.
Description *String
// Required represents if the secret is required or optional. When this value is nil, it means optional.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_callsecretssecret_idrequired
Required *Bool
}
// WorkflowCallEventOutput is an output configuration of workflow_call event.
// https://docs.github.com/en/actions/using-workflows/reusing-workflows#using-outputs-from-a-reusable-workflow
type WorkflowCallEventOutput struct {
// Name is a name of the output.
Name *String
// Description is a description of the output.
Description *String
// Value is an expression for the value of the output.
Value *String
}
// WorkflowCallEvent is workflow_call event configuration.
// https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#workflow-reuse-events
type WorkflowCallEvent struct {
// Inputs is an array of inputs of the workflow_call event. This value is not a map unlike other fields of this
// struct since its order is important when checking the default values of inputs.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_callinputs
Inputs []*WorkflowCallEventInput
// Secrets is a map from name of secret to secret configuration. When 'secrets' is omitted, nil is set to this
// field. Keys are in lower case since they are case-insensitive.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onworkflow_callsecrets
Secrets map[string]*WorkflowCallEventSecret
// Outputs is a map from name of output to output configuration. Keys are in lower case since they are case-insensitive.
// https://docs.github.com/en/actions/using-workflows/reusing-workflows#using-outputs-from-a-reusable-workflow
Outputs map[string]*WorkflowCallEventOutput
// Pos is a position in source.
Pos *Pos
}
// EventName returns name of the event to trigger this workflow.
func (e *WorkflowCallEvent) EventName() string {
return "workflow_call"
}
// PermissionScope is struct for respective permission scope like "issues", "checks", ...
// https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
type PermissionScope struct {
// Name is name of the scope.
Name *String
// Value is permission value of the scope.
Value *String
}
// Permissions is set of permission configurations in workflow file. All permissions can be set at
// once. Or each permission can be configured respectively.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#permissions
type Permissions struct {
// All represents a permission value for all the scopes at once.
All *String
// Scopes is mappings from scope name to its permission configuration
Scopes map[string]*PermissionScope
// Pos is a position in source.
Pos *Pos
}
// DefaultsRun is configuration that shell is how to be run.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#defaultsrun
type DefaultsRun struct {
// Shell is shell name to be run.
Shell *String
// WorkingDirectory is a default working directory path.
WorkingDirectory *String
// Pos is a position in source.
Pos *Pos
}
// Defaults is set of default configurations to run shell.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#defaults
type Defaults struct {
// Run is configuration of how to run shell.
Run *DefaultsRun
// Pos is a position in source.
Pos *Pos
}
// Concurrency is a configuration of concurrency of the workflow.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency
type Concurrency struct {
// Group is name of the concurrency group.
Group *String
// CancelInProgress is a flag that shows if canceling this workflow cancels other jobs in progress.
CancelInProgress *Bool
// Pos is a position in source.
Pos *Pos
}
// Environment is a configuration of environment.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idenvironment
type Environment struct {
// Name is a name of environment which the workflow uses.
Name *String
// URL is the URL mapped to 'environment_url' in the deployments API. Empty value means no value was specified.
URL *String
// Pos is a position in source.
Pos *Pos
}
// ExecKind is kind of how the step is executed. A step runs some action or runs some shell script.
type ExecKind uint8
const (
// ExecKindAction is kind for step to run action
ExecKindAction ExecKind = iota
// ExecKindRun is kind for step to run shell script
ExecKindRun
)
// Exec is an interface how the step is executed. Step in workflow runs either an action or a script
type Exec interface {
// Kind returns kind of the step execution.
Kind() ExecKind
}
// ExecRun is configuration how to run shell script at the step.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsrun
type ExecRun struct {
// Run is script to run.
Run *String
// Shell represents optional 'shell' field. Nil means nothing specified.
Shell *String
// WorkingDirectory represents optional 'working-directory' field. Nil means nothing specified.
WorkingDirectory *String
// RunPos is position of 'run' section
RunPos *Pos
}
// Kind returns kind of the step execution.
func (e *ExecRun) Kind() ExecKind {
return ExecKindRun
}
// Input is an input field for running an action.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepswith
type Input struct {
// Name is a name of the input.
Name *String
// Value is a value of the input.
Value *String
}
// ExecAction is configuration how to run action at the step.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsuses
type ExecAction struct {
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsuses
Uses *String
// Inputs represents inputs to the action to execute in 'with' section. Keys are in lower case since they are case-insensitive.
Inputs map[string]*Input
// Entrypoint represents optional 'entrypoint' field in 'with' section. Nil field means nothing specified
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepswithentrypoint
Entrypoint *String
// Args represents optional 'args' field in 'with' section. Nil field means nothing specified
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepswithargs
Args *String
}
// Kind returns kind of the step execution.
func (e *ExecAction) Kind() ExecKind {
return ExecKindAction
}
// RawYAMLValueKind is kind of raw YAML values
type RawYAMLValueKind int
const (
// RawYAMLValueKindObject is kind for an object value of raw YAML value.
RawYAMLValueKindObject = RawYAMLValueKind(yaml.MappingNode)
// RawYAMLValueKindArray is kind for an array value of raw YAML value.
RawYAMLValueKindArray = RawYAMLValueKind(yaml.SequenceNode)
// RawYAMLValueKindString is kind for a string value of raw YAML value.
RawYAMLValueKindString = RawYAMLValueKind(yaml.ScalarNode)
)
// RawYAMLValue is a value at matrix variation. Any value can be put at matrix variations
// including mappings and arrays.
type RawYAMLValue interface {
// Kind returns kind of raw YAML value.
Kind() RawYAMLValueKind
// Equals returns if the other value is equal to the value.
Equals(other RawYAMLValue) bool
// Pos returns the start position of the value in the source file
Pos() *Pos
// String returns string representation of the value
String() string
}
// RawYAMLObject is raw YAML mapping value.
type RawYAMLObject struct {
// Props is map from property names to their values. Keys are in lower case since they are case-insensitive.
Props map[string]RawYAMLValue
pos *Pos
}
// Kind returns kind of raw YAML value.
func (o *RawYAMLObject) Kind() RawYAMLValueKind {
return RawYAMLValueKindObject
}
// Equals returns if the other value is equal to the value.
func (o *RawYAMLObject) Equals(other RawYAMLValue) bool {
switch other := other.(type) {
case *RawYAMLObject:
for n, p1 := range o.Props {
if p2, ok := other.Props[n]; !ok || !p1.Equals(p2) {
return false
}
}
return true
default:
return false
}
}
// Pos returns the start position of the value in the source file
func (o *RawYAMLObject) Pos() *Pos {
return o.pos
}
func (o *RawYAMLObject) String() string {
qs := make([]string, 0, len(o.Props))
for n, p := range o.Props {
qs = append(qs, fmt.Sprintf("%q: %s", n, p.String()))
}
sort.Strings(qs)
return "{" + strings.Join(qs, ", ") + "}"
}
// RawYAMLArray is raw YAML sequence value.
type RawYAMLArray struct {
// Elems is list of elements of the array value.
Elems []RawYAMLValue
pos *Pos
}
// Kind returns kind of raw YAML value.
func (a *RawYAMLArray) Kind() RawYAMLValueKind {
return RawYAMLValueKindArray
}
// Equals returns if the other value is equal to the value.
func (a *RawYAMLArray) Equals(other RawYAMLValue) bool {
switch other := other.(type) {
case *RawYAMLArray:
if len(a.Elems) != len(other.Elems) {
return false
}
for i, e1 := range a.Elems {
if !e1.Equals(other.Elems[i]) {
return false
}
}
return true
default:
return false
}
}
// Pos returns the start position of the value in the source file
func (a *RawYAMLArray) Pos() *Pos {
return a.pos
}
func (a *RawYAMLArray) String() string {
var b strings.Builder
b.WriteRune('[')
comma := false
for _, e := range a.Elems {
if comma {
b.WriteString(", ")
} else {
comma = true
}
b.WriteString(e.String())
}
b.WriteRune(']')
return b.String()
}
// RawYAMLString is raw YAML scalar value.
type RawYAMLString struct {
// Note: Might be useful to add kind to check the string value is int/float/bool/null.
// Value is string representation of the scalar node.
Value string
pos *Pos
}
// Kind returns kind of raw YAML value.
func (s *RawYAMLString) Kind() RawYAMLValueKind {
return RawYAMLValueKindString
}
// Equals returns if the other value is equal to the value.
func (s *RawYAMLString) Equals(other RawYAMLValue) bool {
switch other := other.(type) {
case *RawYAMLString:
return s.Value == other.Value
default:
return false
}
}
// Pos returns the start position of the value in the source file
func (s *RawYAMLString) Pos() *Pos {
return s.pos
}
func (s *RawYAMLString) String() string {
return strconv.Quote(s.Value)
}
// MatrixRow is one row of matrix. One matrix row can take multiple values. Those variations are
// stored as row of values in this struct.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
type MatrixRow struct {
// Name is a name of matrix value.
Name *String
// Values is variations of values which the matrix value can take.
Values []RawYAMLValue
// Expression is a string when expression syntax ${{ }} is used for this section.
Expression *String
}
// MatrixAssign represents which value should be taken in the row of the matrix.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
type MatrixAssign struct {
// Key is a name of the matrix value.
Key *String
// Value is the value selected from values in row.
Value RawYAMLValue
}
// MatrixCombination is combination of matrix value assignments to define one of matrix variations.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
type MatrixCombination struct {
Assigns map[string]*MatrixAssign
// Expression is a string when expression syntax ${{ }} is used for this section.
Expression *String
}
// MatrixCombinations is list of combinations of matrix assignments used for 'include' and 'exclude'
// sections.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
type MatrixCombinations struct {
Combinations []*MatrixCombination
// Expression is a string when expression syntax ${{ }} is used for this section.
Expression *String
}
// ContainsExpression returns if the combinations section includes at least one expression node.
func (cs *MatrixCombinations) ContainsExpression() bool {
if cs.Expression != nil {
return true
}
for _, c := range cs.Combinations {
if c.Expression != nil {
return true
}
}
return false
}
// Matrix is matrix variations configuration of a job.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
type Matrix struct {
// Values stores mappings from name to values. Keys are in lower case since they are case-insensitive.
Rows map[string]*MatrixRow
// Include is list of combinations of matrix values and additional values on running matrix combinations.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#example-including-additional-values-into-combinations
Include *MatrixCombinations
// Exclude is list of combinations of matrix values which should not be run. Combinations in
// this list will be removed from combinations of matrix to run.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#example-excluding-configurations-from-a-matrix
Exclude *MatrixCombinations
// Expression is a string when expression syntax ${{ }} is used for this section.
Expression *String
// Pos is a position in source.
Pos *Pos
}
// Strategy is strategy configuration of how the job is run.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategy
type Strategy struct {
// Matrix is matrix of combinations of values. Each combination will run the job once.
Matrix *Matrix
// FailFast is flag to show if other jobs should stop when one job fails.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategyfail-fast
FailFast *Bool
// MaxParallel is how many jobs should be run at once.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategymax-parallel
MaxParallel *Int
// Pos is a position in source.
Pos *Pos
}
// EnvVar represents key-value of environment variable setup.
type EnvVar struct {
// Name is name of the environment variable.
Name *String
// Value is string value of the environment variable.
Value *String
}
// Env represents set of environment variables.
type Env struct {
// Vars is mapping from env var name to env var value.
Vars map[string]*EnvVar
// Expression is an expression string which contains ${{ ... }}. When this value is not empty,
// Vars should be nil.
Expression *String
}
// Step is step configuration. Step runs one action or one shell script.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idsteps
type Step struct {
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsid
ID *String
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsif
If *String
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsname
Name *String
Exec Exec
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsenv
Env *Env
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepscontinue-on-error
ContinueOnError *Bool
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes
TimeoutMinutes *Float
// Pos is a position in source.
Pos *Pos
}
// Credentials is credentials configuration.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainercredentials
type Credentials struct {
// Username is username for authentication.
Username *String
// Password is password for authentication.
Password *String
// Pos is a position in source.
Pos *Pos
}
// Container is configuration of how to run the container.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainer
type Container struct {
// Image is specification of Docker image.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainerimage
Image *String
// Credentials is credentials configuration of the Docker container.
Credentials *Credentials
// Env is environment variables setup in the container.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainerenv
Env *Env
// Ports is list of port number mappings of the container.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainerports
Ports []*String
// Volumes are list of volumes to be mounted to the container.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainervolumes
Volumes []*String
// Options is options string to run the container.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontaineroptions
Options *String
// Pos is a position in source.
Pos *Pos
}
// Service is configuration to run a service like database.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idservices
type Service struct {
// Name is name of the service.
Name *String
// Container is configuration of container which runs the service.
Container *Container
}
// Services is a mapping from service ID to its configuration.
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idservices
type Services struct {
// Value is a mapping from service ID to its Service instances. Keys are in lower case since
// they are case-insensitive.
Value map[string]*Service
// Expression is an expression assigned to the services mapping by ${{ }} placeholder. Otherwise
// this field is nil.
Expression *String
// Pos is a position in source.
Pos *Pos
}
// Output is output entry of the job.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idoutputs
type Output struct {
// Name is name of output.
Name *String
// Value is value of output.
Value *String
}
// Runner is struct for runner configuration.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on
type Runner struct {
// Labels is list label names to select a runner to run a job. There are preset labels and user
// defined labels. Runner matching to the labels is selected.
Labels []*String
// LabelsExpr is a string when expression syntax ${{ }} is used for this section. Related issue is #164.
LabelsExpr *String
// Group is a group of runners specified in runs-on: section. It is nil when no group is specified.
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-runners-in-a-group
Group *String
}
// WorkflowCallInput is a normal input for workflow call.
type WorkflowCallInput struct {
// Name is a name of the input.
Name *String
// Value is a value of the input.
Value *String
}
// WorkflowCallSecret is a secret input for workflow call.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idwith
type WorkflowCallSecret struct {
// Name is a name of the secret
Name *String
// Value is a value of the secret
Value *String
}
// WorkflowCall is a struct to represent workflow call at jobs.<job_id>.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_iduses
type WorkflowCall struct {
// Uses is a workflow specification to be called. This field is mandatory.
Uses *String
// Inputs is a map from input name to input value at 'with:'. Keys are in lower case since input names
// are case-insensitive.
Inputs map[string]*WorkflowCallInput
// Secrets is a map from secret name to secret value at 'secrets:'. Keys are in lower case since input
// names are case-insensitive.
Secrets map[string]*WorkflowCallSecret
// InheritSecrets is true when 'secrets: inherit' is specified. In this case, Secrets must be empty.
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_callsecretsinherit
InheritSecrets bool
}
// Job is configuration of how to run a job.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobs
type Job struct {
// ID is an ID of the job, which is key of job configuration objects.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_id
ID *String
// Name is a name of job that user can specify freely.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idname
Name *String
// Needs is list of job IDs which should be run before running this job.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idneeds
Needs []*String
// RunsOn is runner configuration which run the job.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on
RunsOn *Runner
// Permissions is permission configuration for running the job.
Permissions *Permissions
// Environment is environment specification where the job runs.
Environment *Environment
// Concurrency is concurrency configuration on running the job.
Concurrency *Concurrency
// Outputs is map from output name to output specifications.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idoutputs
Outputs map[string]*Output
// Env is environment variables setup while running the job.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idenv
Env *Env
// Defaults is default configurations of how to run scripts.
Defaults *Defaults
// If is a condition whether this job should be run.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idif
If *String
// Steps is list of steps to be run in the job.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idsteps
Steps []*Step
// TimeoutMinutes is timeout value of running the job in minutes.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idtimeout-minutes
TimeoutMinutes *Float
// Strategy is strategy configuration of running the job.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstrategy
Strategy *Strategy
// ContinueOnError is a flag to show if execution should continue on error.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontinue-on-error
ContinueOnError *Bool
// Container is container configuration to run the job.
Container *Container
// Services is a services configurations.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idservices
Services *Services
// WorkflowCall is a workflow call by 'uses:'.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_iduses
WorkflowCall *WorkflowCall
// Pos is a position in source.
Pos *Pos
}
// Workflow is root of workflow syntax tree, which represents one workflow configuration file.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
type Workflow struct {
// Name is name of the workflow. This field can be nil when user didn't specify the name explicitly.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#name
Name *String
// RunName is the name of workflow runs. This field can be set dynamically using ${{ }}.
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#run-name
RunName *String
// On is list of events which can trigger this workflow.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#onpushpull_requestbranchestags
On []Event
// Permissions is configuration of permissions of this workflow.
Permissions *Permissions
// Env is a default set of environment variables while running this workflow.
// https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#env
Env *Env
// Defaults is default configuration of how to run scripts.
Defaults *Defaults
// Concurrency is concurrency configuration of entire workflow. Each jobs also can their own
// concurrency configurations.
Concurrency *Concurrency
// Jobs is mappings from job ID to the job object. Keys are in lower case since they are case-insensitive.
Jobs map[string]*Job
}
// FindWorkflowCallEvent returns workflow_call event node if exists
func (w *Workflow) FindWorkflowCallEvent() (*WorkflowCallEvent, bool) {
for _, e := range w.On {
if e, ok := e.(*WorkflowCallEvent); ok {
return e, true
}
}
return nil, false
}