-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
vercel.go
126 lines (104 loc) · 3.39 KB
/
vercel.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package runsummary
import (
"fmt"
"strings"
"github.com/vercel/turbo/cli/internal/ci"
"github.com/vercel/turbo/cli/internal/util"
)
type vercelRunResponse struct {
ID string
}
type vercelRunPayload struct {
// ID is set by the backend, including it here for completeness, but we never fill this in.
ID string `json:"vercelId,omitempty"`
// StartTime is when this run was started
StartTime int `json:"startTime,omitempty"`
// EndTime is when this run ended. We will never be submitting start and endtime at the same time.
EndTime int `json:"endTime,omitempty"`
// Status is
Status string `json:"status,omitempty"`
// Type should be hardcoded to TURBO
Type string `json:"type,omitempty"`
// ExitCode is the exit code for the full run
ExitCode int `json:"exitCode,omitempty"`
// The command that kicked off the turbo run
Command string `json:"command,omitempty"`
Context string `json:"context,omitempy"`
// TODO: we need to add these in
// originationUser string
// gitBranch string
// gitSha string
// command string
}
type vercelCacheStatus struct {
Status string `json:"status,omitempty"`
Source string `json:"source,omitempty"`
}
type vercelTask struct {
// id string
// log string
// TODO: add in command
Key string `json:"key,omitempty"`
Name string `json:"name,omitempty"`
Workspace string `json:"workspace,omitempty"`
Hash string `json:"hash,omitempty"`
StartTime int `json:"startTime,omitempty"`
EndTime int `json:"endTime,omitempty"`
Cache vercelCacheStatus `json:"cache,omitempty"`
ExitCode int `json:"exitCode,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Dependents []string `json:"dependents,omitempty"`
}
func newVercelRunCreatePayload(runsummary *RunSummary) *vercelRunPayload {
startTime := runsummary.ExecutionSummary.startedAt.UnixMilli()
taskNames := make(util.Set, len(runsummary.Tasks))
for _, task := range runsummary.Tasks {
taskNames.Add(task.Task)
}
return &vercelRunPayload{
StartTime: int(startTime),
Status: "running",
Command: fmt.Sprintf("turbo run %s", strings.Join(taskNames.UnsafeListOfStrings(), " ")),
Type: "TURBO",
Context: getContext(),
}
}
func getContext() string {
name := ci.Constant()
if name == "" {
return "LOCAL"
}
return name
}
func newVercelDonePayload(runsummary *RunSummary) *vercelRunPayload {
endTime := runsummary.ExecutionSummary.endedAt.UnixMilli()
return &vercelRunPayload{
Status: "completed",
EndTime: int(endTime),
ExitCode: runsummary.ExecutionSummary.exitCode,
}
}
func newVercelTaskPayload(taskSummary *TaskSummary) *vercelTask {
hit := taskSummary.CacheState.Local || taskSummary.CacheState.Remote
status := "MISS"
var source string
if hit {
source = "REMOTE"
status = "HIT"
}
return &vercelTask{
Key: taskSummary.TaskID,
Name: taskSummary.Task,
Workspace: taskSummary.Package,
Hash: taskSummary.Hash,
StartTime: int(taskSummary.Execution.startAt.UnixMilli()),
EndTime: int(taskSummary.Execution.startAt.Add(taskSummary.Execution.Duration).UnixMilli()),
Cache: vercelCacheStatus{
Status: status,
Source: source,
},
ExitCode: *taskSummary.Execution.exitCode,
Dependencies: taskSummary.Dependencies,
Dependents: taskSummary.Dependents,
}
}