| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | // Package engine defines the runner execution boundary. |
| 4 | package engine |
| 5 | |
| 6 | import ( |
| 7 | "context" |
| 8 | "encoding/json" |
| 9 | "time" |
| 10 | ) |
| 11 | |
| 12 | const ( |
| 13 | ConclusionSuccess = "success" |
| 14 | ConclusionFailure = "failure" |
| 15 | ConclusionCancelled = "cancelled" |
| 16 | ConclusionTimedOut = "timed_out" |
| 17 | ) |
| 18 | |
| 19 | type Engine interface { |
| 20 | Execute(ctx context.Context, job Job) (Outcome, error) |
| 21 | StreamLogs(ctx context.Context, jobID int64) (<-chan LogChunk, error) |
| 22 | Cancel(ctx context.Context, jobID int64) error |
| 23 | } |
| 24 | |
| 25 | // EventStreamer is an optional engine capability for preserving runner API |
| 26 | // ordering between final log chunks and step completion updates. |
| 27 | type EventStreamer interface { |
| 28 | StreamEvents(ctx context.Context, jobID int64) (<-chan Event, error) |
| 29 | } |
| 30 | |
| 31 | type Job struct { |
| 32 | ID int64 |
| 33 | RunID int64 |
| 34 | RepoID int64 |
| 35 | RunIndex int64 |
| 36 | WorkflowFile string |
| 37 | WorkflowName string |
| 38 | HeadSHA string |
| 39 | HeadRef string |
| 40 | Event string |
| 41 | EventPayload map[string]any |
| 42 | JobKey string |
| 43 | JobName string |
| 44 | RunsOn string |
| 45 | Needs []string |
| 46 | If string |
| 47 | TimeoutMinutes int32 |
| 48 | Permissions json.RawMessage |
| 49 | Env map[string]string |
| 50 | Steps []Step |
| 51 | WorkspaceDir string |
| 52 | Image string |
| 53 | MaskValues []string |
| 54 | } |
| 55 | |
| 56 | type Step struct { |
| 57 | ID int64 |
| 58 | Index int32 |
| 59 | StepID string |
| 60 | Name string |
| 61 | If string |
| 62 | Run string |
| 63 | Uses string |
| 64 | WorkingDirectory string |
| 65 | Env map[string]string |
| 66 | With map[string]string |
| 67 | ContinueOnError bool |
| 68 | } |
| 69 | |
| 70 | type Outcome struct { |
| 71 | Conclusion string |
| 72 | StartedAt time.Time |
| 73 | CompletedAt time.Time |
| 74 | StepOutcomes []StepOutcome |
| 75 | } |
| 76 | |
| 77 | type StepOutcome struct { |
| 78 | StepID int64 |
| 79 | Status string |
| 80 | Conclusion string |
| 81 | StartedAt time.Time |
| 82 | CompletedAt time.Time |
| 83 | } |
| 84 | |
| 85 | type LogChunk struct { |
| 86 | JobID int64 |
| 87 | StepID int64 |
| 88 | Seq int32 |
| 89 | Chunk []byte |
| 90 | } |
| 91 | |
| 92 | type Event struct { |
| 93 | Log *LogChunk |
| 94 | Step *StepOutcome |
| 95 | } |
| 96 |