@@ -70,6 +70,12 @@ func NewAction(
7070 return nil , errors .Errorf ("failed to compile argument %s: %v" , k , err )
7171 }
7272 kwargs [k ] = evaluator
73+ case []string :
74+ evaluator , err := compileArrayExpr (env , val )
75+ if err != nil {
76+ return nil , errors .Errorf ("failed to compile array argument %s: %v" , k , err )
77+ }
78+ kwargs [k ] = evaluator
7379 case map [string ]interface {}:
7480 evaluator , err := compileDictExpr (env , val )
7581 if err != nil {
@@ -203,6 +209,85 @@ func compileDictExpr(env *cel.Env, dict map[string]interface{}) (expressionEvalu
203209 }, nil
204210}
205211
212+ // compileArrayExpr compiles expressions in a string array.
213+ // Each array element can contain embedded CEL expressions like "{scope.files}".
214+ func compileArrayExpr (env * cel.Env , arr []string ) (expressionEvaluator , error ) {
215+ compiledEvaluators := make ([]expressionEvaluator , len (arr ))
216+
217+ for i , element := range arr {
218+ pattern := regexp .MustCompile (`\{\s*(.*?)\s*}` )
219+ matches := pattern .FindAllStringSubmatch (element , - 1 )
220+
221+ switch {
222+ case len (matches ) == 0 :
223+ // If no expressions found, return the constant string
224+ compiledEvaluators [i ] = func (map [string ]interface {}) (interface {}, error ) {
225+ return element , nil
226+ }
227+ case len (matches ) == 1 && matches [0 ][0 ] == element :
228+ // Special case: element is pure expression like "{scope.files}"
229+ // Try to evaluate it as an array expression first
230+ ast , issues := env .Compile (matches [0 ][1 ])
231+ if issues != nil && issues .Err () != nil {
232+ return nil , errors .Errorf ("failed to compile array expression '%s': %v" , matches [0 ][1 ], issues .Err ())
233+ }
234+ program , err := env .Program (ast )
235+ if err != nil {
236+ return nil , errors .Errorf ("failed to create program for array expression '%s': %v" , matches [0 ][1 ], err )
237+ }
238+
239+ compiledEvaluators [i ] = func (activation map [string ]interface {}) (interface {}, error ) {
240+ val , _ , err := program .Eval (activation )
241+ if err != nil {
242+ return nil , errors .Errorf ("failed to evaluate array expression '%s': %v" , matches [0 ][1 ], err )
243+ }
244+ return val .Value (), nil
245+ }
246+ default :
247+ // Element contains mixed content with expressions, treat as string
248+ evaluator , err := compileEmbeddedExpr (env , element )
249+ if err != nil {
250+ return nil , errors .Errorf ("failed to compile embedded expression in array element: %v" , err )
251+ }
252+ compiledEvaluators [i ] = evaluator
253+ }
254+ }
255+
256+ return func (activation map [string ]interface {}) (interface {}, error ) {
257+ result := make ([]string , 0 )
258+
259+ for _ , evaluator := range compiledEvaluators {
260+ value , err := evaluator (activation )
261+ if err != nil {
262+ return nil , err
263+ }
264+
265+ switch v := value .(type ) {
266+ case []interface {}:
267+ // If the expression evaluates to an array, append all elements
268+ for _ , item := range v {
269+ result = append (result , fmt .Sprintf ("%v" , item ))
270+ }
271+ case []string :
272+ // If it's already a string array, append directly
273+ result = append (result , v ... )
274+ case string :
275+ // Single string value
276+ if v != "" {
277+ result = append (result , v )
278+ }
279+ default :
280+ // Convert other types to string
281+ if str := fmt .Sprintf ("%v" , v ); str != "" {
282+ result = append (result , str )
283+ }
284+ }
285+ }
286+
287+ return result , nil
288+ }, nil
289+ }
290+
206291func (a * Action ) String () string {
207292 return fmt .Sprintf ("Action(%s)%v" , a .Name , a .RawKwargs )
208293}
0 commit comments