@@ -30,6 +30,7 @@ import (
3030 notify_service "code.gitea.io/gitea/services/notify"
3131 "gopkg.in/yaml.v3"
3232
33+ "github.com/nektos/act/pkg/exprparser"
3334 "github.com/nektos/act/pkg/jobparser"
3435 "github.com/nektos/act/pkg/model"
3536)
@@ -300,16 +301,14 @@ func handleWorkflows(
300301 }
301302
302303 for _ , dwf := range detectedWorkflows {
303- var yamlData map [string ]any
304- if err := yaml .Unmarshal ([]byte (dwf .Content ), & yamlData ); err != nil {
305- log .Fatal (err .Error ())
306- }
307304 run := & actions_model.ActionRun {
308- Title : yamlData [ "run-name" ].( string ) ,
305+ Title : strings . SplitN ( commit . CommitMessage , " \n " , 2 )[ 0 ] ,
309306 RepoID : input .Repo .ID ,
307+ Repo : input .Repo ,
310308 OwnerID : input .Repo .OwnerID ,
311309 WorkflowID : dwf .EntryName ,
312310 TriggerUserID : input .Doer .ID ,
311+ TriggerUser : input .Doer ,
313312 Ref : ref ,
314313 CommitSHA : commit .ID .String (),
315314 IsForkPullRequest : isForkPullRequest ,
@@ -319,6 +318,11 @@ func handleWorkflows(
319318 Status : actions_model .StatusWaiting ,
320319 }
321320
321+ if err := EvaluateExpressionsForRun (run , dwf ); err != nil {
322+ log .Error ("EvaluateExpressionsForRun: %v" , err )
323+ continue
324+ }
325+
322326 need , err := ifNeedApproval (ctx , run , input .Repo , input .Doer )
323327 if err != nil {
324328 log .Error ("check if need approval for repo %d with user %d: %v" , input .Repo .ID , input .Doer .ID , err )
@@ -523,6 +527,11 @@ func handleSchedules(
523527 Specs : schedules ,
524528 Content : dwf .Content ,
525529 }
530+
531+ if runName , err := parseRunNameFromDetectedWorkflow (dwf ); err == nil {
532+ run .Title = runName
533+ }
534+
526535 crons = append (crons , run )
527536 }
528537
@@ -561,3 +570,56 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository)
561570
562571 return handleSchedules (ctx , scheduleWorkflows , commit , notifyInput , repo .DefaultBranch )
563572}
573+
574+ func newExpressionEvaluatorForRun (r * actions_model.ActionRun ) (* jobparser.ExpressionEvaluator , error ) {
575+ ghCtx := & model.GithubContext {}
576+ gitCtx := GenerateGiteaContext (r , nil )
577+
578+ gitCtxRaw , err := json .Marshal (gitCtx )
579+ if err != nil {
580+ log .Error ("NewInterpolatorForRun: %v" , err )
581+ return nil , err
582+ }
583+
584+ err = json .Unmarshal (gitCtxRaw , ghCtx )
585+ if err != nil {
586+ log .Error ("NewInterpolatorForRun: %v" , err )
587+ return nil , err
588+ }
589+
590+ interp := exprparser .NewInterpeter (& exprparser.EvaluationEnvironment {Github : ghCtx }, exprparser.Config {})
591+ ee := jobparser .NewExpressionEvaluator (interp )
592+ return ee , nil
593+ }
594+
595+ func parseRunNameFromDetectedWorkflow (w * actions_module.DetectedWorkflow ) (string , error ) {
596+ var data map [string ]any
597+ var value string
598+
599+ if err := yaml .Unmarshal ([]byte (w .Content ), & data ); err != nil {
600+ log .Error ("parseRunNameFromDetectedWorkflow: %v" , err )
601+ return "" , err
602+ }
603+
604+ if v , ok := data ["run-name" ]; ! ok {
605+ return "" , fmt .Errorf ("run-name not found in workflow" )
606+ } else {
607+ value = v .(string )
608+ }
609+
610+ return value , nil
611+ }
612+
613+ func EvaluateExpressionsForRun (r * actions_model.ActionRun , w * actions_module.DetectedWorkflow ) error {
614+ if runName , err := parseRunNameFromDetectedWorkflow (w ); err == nil {
615+ ee , err := newExpressionEvaluatorForRun (r )
616+ if err != nil {
617+ log .Error ("newExpressionEvaluatorForRun: %v" , err )
618+ return err
619+ }
620+ r .Title = ee .Interpolate (runName )
621+ } else {
622+ log .Error ("parseRunNameFromDetectedWorkflow: %v" , err )
623+ }
624+ return nil
625+ }
0 commit comments