5
5
"encoding/json"
6
6
"errors"
7
7
"fmt"
8
+ "math"
8
9
"regexp"
10
+ "strconv"
9
11
"strings"
10
12
11
13
"github.com/rhysd/actionlint"
@@ -18,6 +20,8 @@ var workflowSchema string
18
20
//go:embed action_schema.json
19
21
var actionSchema string
20
22
23
+ var functions = regexp .MustCompile (`^([a-zA-Z0-9_]+)\(([0-9]+),([0-9]+|MAX)\)$` )
24
+
21
25
type Schema struct {
22
26
Definitions map [string ]Definition
23
27
}
@@ -138,10 +142,10 @@ func (s *Node) checkSingleExpression(exprNode actionlint.ExprNode) error {
138
142
for _ , v := range * funcs {
139
143
if strings .EqualFold (funcCallNode .Callee , v .name ) {
140
144
if v .min > len (funcCallNode .Args ) {
141
- err = errors .Join (err , fmt .Errorf ("Missing parameters for %s expected > %v got %v" , funcCallNode .Callee , v .min , len (funcCallNode .Args )))
145
+ err = errors .Join (err , fmt .Errorf ("Missing parameters for %s expected >= %v got %v" , funcCallNode .Callee , v .min , len (funcCallNode .Args )))
142
146
}
143
147
if v .max < len (funcCallNode .Args ) {
144
- err = errors .Join (err , fmt .Errorf ("To many parameters for %s expected < %v got %v" , funcCallNode .Callee , v .max , len (funcCallNode .Args )))
148
+ err = errors .Join (err , fmt .Errorf ("Too many parameters for %s expected <= %v got %v" , funcCallNode .Callee , v .max , len (funcCallNode .Args )))
145
149
}
146
150
return
147
151
}
@@ -174,11 +178,22 @@ func (s *Node) GetFunctions() *[]FunctionInfo {
174
178
if i == - 1 {
175
179
continue
176
180
}
177
- fun := FunctionInfo {
178
- name : v [:i ],
179
- }
180
- if n , err := fmt .Sscanf (v [i :], "(%d,%d)" , & fun .min , & fun .max ); n == 2 && err == nil {
181
- * funcs = append (* funcs , fun )
181
+ smatch := functions .FindStringSubmatch (v )
182
+ if len (smatch ) > 0 {
183
+ functionName := smatch [1 ]
184
+ minParameters , _ := strconv .ParseInt (smatch [2 ], 10 , 32 )
185
+ maxParametersRaw := smatch [3 ]
186
+ var maxParameters int64
187
+ if strings .EqualFold (maxParametersRaw , "MAX" ) {
188
+ maxParameters = math .MaxInt32
189
+ } else {
190
+ maxParameters , _ = strconv .ParseInt (maxParametersRaw , 10 , 32 )
191
+ }
192
+ * funcs = append (* funcs , FunctionInfo {
193
+ name : functionName ,
194
+ min : int (minParameters ),
195
+ max : int (maxParameters ),
196
+ })
182
197
}
183
198
}
184
199
return funcs
@@ -220,6 +235,9 @@ func AddFunction(funcs *[]FunctionInfo, s string, i1, i2 int) {
220
235
}
221
236
222
237
func (s * Node ) UnmarshalYAML (node * yaml.Node ) error {
238
+ if node != nil && node .Kind == yaml .DocumentNode {
239
+ return s .UnmarshalYAML (node .Content [0 ])
240
+ }
223
241
def := s .Schema .GetDefinition (s .Definition )
224
242
if s .Context == nil {
225
243
s .Context = def .Context
0 commit comments