Go · 2062 bytes Raw Blame History
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 Secrets map[string]string
50 Env map[string]string
51 Steps []Step
52 WorkspaceDir string
53 Image string
54 MaskValues []string
55 }
56
57 type Step struct {
58 ID int64
59 Index int32
60 StepID string
61 Name string
62 If string
63 Run string
64 Uses string
65 WorkingDirectory string
66 Env map[string]string
67 With map[string]string
68 ContinueOnError bool
69 }
70
71 type Outcome struct {
72 Conclusion string
73 StartedAt time.Time
74 CompletedAt time.Time
75 StepOutcomes []StepOutcome
76 }
77
78 type StepOutcome struct {
79 StepID int64
80 Status string
81 Conclusion string
82 StartedAt time.Time
83 CompletedAt time.Time
84 }
85
86 type LogChunk struct {
87 JobID int64
88 StepID int64
89 Seq int32
90 Chunk []byte
91 }
92
93 type Event struct {
94 Log *LogChunk
95 Step *StepOutcome
96 }
97