@@ -35,7 +35,7 @@ type RunContext struct {
3535 Env map [string ]string
3636 ExtraPath []string
3737 CurrentStep string
38- StepResults map [string ]* stepResult
38+ StepResults map [string ]* model. StepResult
3939 ExprEval ExpressionEvaluator
4040 JobContainer container.Container
4141 OutputMappings map [MappableOutput ]MappableOutput
@@ -53,7 +53,7 @@ func (rc *RunContext) Clone() *RunContext {
5353 clone .CurrentStep = ""
5454 clone .Composite = nil
5555 clone .Inputs = nil
56- clone .StepResults = make (map [string ]* stepResult )
56+ clone .StepResults = make (map [string ]* model. StepResult )
5757 clone .Parent = rc
5858 return & clone
5959}
@@ -67,46 +67,6 @@ func (rc *RunContext) String() string {
6767 return fmt .Sprintf ("%s/%s" , rc .Run .Workflow .Name , rc .Name )
6868}
6969
70- type stepStatus int
71-
72- const (
73- stepStatusSuccess stepStatus = iota
74- stepStatusFailure
75- )
76-
77- var stepStatusStrings = [... ]string {
78- "success" ,
79- "failure" ,
80- }
81-
82- func (s stepStatus ) MarshalText () ([]byte , error ) {
83- return []byte (s .String ()), nil
84- }
85-
86- func (s * stepStatus ) UnmarshalText (b []byte ) error {
87- str := string (b )
88- for i , name := range stepStatusStrings {
89- if name == str {
90- * s = stepStatus (i )
91- return nil
92- }
93- }
94- return fmt .Errorf ("invalid step status %q" , str )
95- }
96-
97- func (s stepStatus ) String () string {
98- if int (s ) >= len (stepStatusStrings ) {
99- return ""
100- }
101- return stepStatusStrings [s ]
102- }
103-
104- type stepResult struct {
105- Outputs map [string ]string `json:"outputs"`
106- Conclusion stepStatus `json:"conclusion"`
107- Outcome stepStatus `json:"outcome"`
108- }
109-
11070// GetEnv returns the env for the context
11171func (rc * RunContext ) GetEnv () map [string ]string {
11272 if rc .Env == nil {
@@ -349,16 +309,16 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
349309 }
350310 return func (ctx context.Context ) error {
351311 rc .CurrentStep = sc .Step .ID
352- rc .StepResults [rc .CurrentStep ] = & stepResult {
353- Outcome : stepStatusSuccess ,
354- Conclusion : stepStatusSuccess ,
312+ rc .StepResults [rc .CurrentStep ] = & model. StepResult {
313+ Outcome : model . StepStatusSuccess ,
314+ Conclusion : model . StepStatusSuccess ,
355315 Outputs : make (map [string ]string ),
356316 }
357317
358318 runStep , err := sc .isEnabled (ctx )
359319 if err != nil {
360- rc .StepResults [rc .CurrentStep ].Conclusion = stepStatusFailure
361- rc .StepResults [rc .CurrentStep ].Outcome = stepStatusFailure
320+ rc .StepResults [rc .CurrentStep ].Conclusion = model . StepStatusFailure
321+ rc .StepResults [rc .CurrentStep ].Outcome = model . StepStatusFailure
362322 return err
363323 }
364324
@@ -380,13 +340,13 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
380340 } else {
381341 common .Logger (ctx ).Errorf (" \u274C Failure - %s" , sc .Step )
382342
383- rc .StepResults [rc .CurrentStep ].Outcome = stepStatusFailure
343+ rc .StepResults [rc .CurrentStep ].Outcome = model . StepStatusFailure
384344 if sc .Step .ContinueOnError {
385345 common .Logger (ctx ).Infof ("Failed but continue next step" )
386346 err = nil
387- rc .StepResults [rc .CurrentStep ].Conclusion = stepStatusSuccess
347+ rc .StepResults [rc .CurrentStep ].Conclusion = model . StepStatusSuccess
388348 } else {
389- rc .StepResults [rc .CurrentStep ].Conclusion = stepStatusFailure
349+ rc .StepResults [rc .CurrentStep ].Conclusion = model . StepStatusFailure
390350 }
391351 }
392352 return err
@@ -522,31 +482,20 @@ func trimToLen(s string, l int) string {
522482 return s
523483}
524484
525- type jobContext struct {
526- Status string `json:"status"`
527- Container struct {
528- ID string `json:"id"`
529- Network string `json:"network"`
530- } `json:"container"`
531- Services map [string ]struct {
532- ID string `json:"id"`
533- } `json:"services"`
534- }
535-
536- func (rc * RunContext ) getJobContext () * jobContext {
485+ func (rc * RunContext ) getJobContext () * model.JobContext {
537486 jobStatus := "success"
538487 for _ , stepStatus := range rc .StepResults {
539- if stepStatus .Conclusion == stepStatusFailure {
488+ if stepStatus .Conclusion == model . StepStatusFailure {
540489 jobStatus = "failure"
541490 break
542491 }
543492 }
544- return & jobContext {
493+ return & model. JobContext {
545494 Status : jobStatus ,
546495 }
547496}
548497
549- func (rc * RunContext ) getStepsContext () map [string ]* stepResult {
498+ func (rc * RunContext ) getStepsContext () map [string ]* model. StepResult {
550499 return rc .StepResults
551500}
552501
@@ -561,35 +510,8 @@ func (rc *RunContext) getNeedsTransitive(job *model.Job) []string {
561510 return needs
562511}
563512
564- type githubContext struct {
565- Event map [string ]interface {} `json:"event"`
566- EventPath string `json:"event_path"`
567- Workflow string `json:"workflow"`
568- RunID string `json:"run_id"`
569- RunNumber string `json:"run_number"`
570- Actor string `json:"actor"`
571- Repository string `json:"repository"`
572- EventName string `json:"event_name"`
573- Sha string `json:"sha"`
574- Ref string `json:"ref"`
575- HeadRef string `json:"head_ref"`
576- BaseRef string `json:"base_ref"`
577- Token string `json:"token"`
578- Workspace string `json:"workspace"`
579- Action string `json:"action"`
580- ActionPath string `json:"action_path"`
581- ActionRef string `json:"action_ref"`
582- ActionRepository string `json:"action_repository"`
583- Job string `json:"job"`
584- JobName string `json:"job_name"`
585- RepositoryOwner string `json:"repository_owner"`
586- RetentionDays string `json:"retention_days"`
587- RunnerPerflog string `json:"runner_perflog"`
588- RunnerTrackingID string `json:"runner_tracking_id"`
589- }
590-
591- func (rc * RunContext ) getGithubContext () * githubContext {
592- ghc := & githubContext {
513+ func (rc * RunContext ) getGithubContext () * model.GithubContext {
514+ ghc := & model.GithubContext {
593515 Event : make (map [string ]interface {}),
594516 EventPath : ActPath + "/workflow/event.json" ,
595517 Workflow : rc .Run .Workflow .Name ,
@@ -685,7 +607,7 @@ func (rc *RunContext) getGithubContext() *githubContext {
685607 return ghc
686608}
687609
688- func (ghc * githubContext ) isLocalCheckout ( step * model.Step ) bool {
610+ func isLocalCheckout (ghc * model. GithubContext , step * model.Step ) bool {
689611 if step .Type () == model .StepTypeInvalid {
690612 // This will be errored out by the executor later, we need this here to avoid a null panic though
691613 return false
@@ -839,7 +761,7 @@ func setActionRuntimeVars(rc *RunContext, env map[string]string) {
839761func (rc * RunContext ) localCheckoutPath () (string , bool ) {
840762 ghContext := rc .getGithubContext ()
841763 for _ , step := range rc .Run .Job ().Steps {
842- if ghContext . isLocalCheckout (step ) {
764+ if isLocalCheckout (ghContext , step ) {
843765 return step .With ["path" ], true
844766 }
845767 }
0 commit comments