-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
spaces.go
96 lines (86 loc) · 3.59 KB
/
spaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package runsummary
import (
"github.com/vercel/turbo/cli/internal/ci"
)
// spacesRunResponse deserialized the response from POST Run endpoint
type spacesRunResponse struct {
ID string
URL string
}
type spacesRunPayload struct {
StartTime int64 `json:"startTime,omitempty"` // when the run was started
EndTime int64 `json:"endTime,omitempty"` // when the run ended. we should never submit start and end at the same time.
Status string `json:"status,omitempty"` // Status is "running" or "completed"
Type string `json:"type,omitempty"` // hardcoded to "TURBO"
ExitCode int `json:"exitCode,omitempty"` // exit code for the full run
Command string `json:"command,omitempty"` // the thing that kicked off the turbo run
RepositoryPath string `json:"repositoryPath,omitempty"` // where the command was invoked from
Context string `json:"context,omitempty"` // the host on which this Run was executed (e.g. Github Action, Vercel, etc)
// TODO: we need to add these in
// originationUser string
// gitBranch string
// gitSha string
}
// spacesCacheStatus is the same as TaskCacheSummary so we can convert
// spacesCacheStatus(cacheSummary), but change the json tags, to omit local and remote fields
type spacesCacheStatus struct {
// omitted fields, but here so we can convert from TaskCacheSummary easily
Local bool `json:"-"`
Remote bool `json:"-"`
Status string `json:"status"` // should always be there
Source string `json:"source,omitempty"`
TimeSaved int `json:"timeSaved"`
}
type spacesTask struct {
Key string `json:"key,omitempty"`
Name string `json:"name,omitempty"`
Workspace string `json:"workspace,omitempty"`
Hash string `json:"hash,omitempty"`
StartTime int64 `json:"startTime,omitempty"`
EndTime int64 `json:"endTime,omitempty"`
Cache spacesCacheStatus `json:"cache,omitempty"`
ExitCode int `json:"exitCode,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Dependents []string `json:"dependents,omitempty"`
Logs string `json:"log"`
}
func (rsm *Meta) newSpacesRunCreatePayload() *spacesRunPayload {
startTime := rsm.RunSummary.ExecutionSummary.startedAt.UnixMilli()
context := "LOCAL"
if name := ci.Constant(); name != "" {
context = name
}
return &spacesRunPayload{
StartTime: startTime,
Status: "running",
Command: rsm.synthesizedCommand,
RepositoryPath: rsm.repoPath.ToString(),
Type: "TURBO",
Context: context,
}
}
func newSpacesDonePayload(runsummary *RunSummary) *spacesRunPayload {
endTime := runsummary.ExecutionSummary.endedAt.UnixMilli()
return &spacesRunPayload{
Status: "completed",
EndTime: endTime,
ExitCode: runsummary.ExecutionSummary.exitCode,
}
}
func newSpacesTaskPayload(taskSummary *TaskSummary) *spacesTask {
startTime := taskSummary.Execution.startAt.UnixMilli()
endTime := taskSummary.Execution.endTime().UnixMilli()
return &spacesTask{
Key: taskSummary.TaskID,
Name: taskSummary.Task,
Workspace: taskSummary.Package,
Hash: taskSummary.Hash,
StartTime: startTime,
EndTime: endTime,
Cache: spacesCacheStatus(taskSummary.CacheSummary), // wrapped so we can remove fields
ExitCode: *taskSummary.Execution.exitCode,
Dependencies: taskSummary.Dependencies,
Dependents: taskSummary.Dependents,
Logs: string(taskSummary.GetLogs()),
}
}