Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename references to spaces #4525

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cli/internal/runsummary/run_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ func (rsm *Meta) Close(exitCode int, workspaceInfos workspace.Catalog) error {
if rsm.spaceID != "" {
if rsm.apiClient.IsLinked() {
if errs := rsm.record(); len(errs) > 0 {
rsm.ui.Warn("Errors recording run to Vercel")
rsm.ui.Warn("Errors recording run to Spaces")
for _, err := range errs {
rsm.ui.Warn(fmt.Sprintf("%v", err))
}
}
} else {
rsm.ui.Warn("Failed to post to space because repo is not linked to Vercel. Run `turbo link` first.")
rsm.ui.Warn("Failed to post to space because repo is not linked to a Space. Run `turbo link` first.")
}
}
}
Expand Down Expand Up @@ -213,28 +213,29 @@ func (rsm *Meta) record() []error {
errs := []error{}

// Right now we'll send the POST to create the Run and the subsequent task payloads
// when everything after all execution is done, but in the future, this first POST request
// can happen when the Run actually starts, so we can send updates to Vercel as the tasks progress.
// after all execution is done, but in the future, this first POST request
// can happen when the Run actually starts, so we can send updates to the associated Space
// as tasks complete.
runsURL := fmt.Sprintf(runsEndpoint, rsm.spaceID)
var runID string
payload := rsm.newVercelRunCreatePayload()
payload := rsm.newSpacesRunCreatePayload()
if startPayload, err := json.Marshal(payload); err == nil {
if resp, err := rsm.apiClient.JSONPost(runsURL, startPayload); err != nil {
errs = append(errs, err)
} else {
vercelRunResponse := &vercelRunResponse{}
if err := json.Unmarshal(resp, vercelRunResponse); err != nil {
spacesRunResponse := &spacesRunResponse{}
if err := json.Unmarshal(resp, spacesRunResponse); err != nil {
errs = append(errs, err)
} else {
runID = vercelRunResponse.ID
runID = spacesRunResponse.ID
}
}
}

if runID != "" {
rsm.postTaskSummaries(runID)

if donePayload, err := json.Marshal(newVercelDonePayload(rsm.RunSummary)); err == nil {
if donePayload, err := json.Marshal(newSpacesDonePayload(rsm.RunSummary)); err == nil {
patchURL := fmt.Sprintf(runsPatchEndpoint, rsm.spaceID, runID)
if _, err := rsm.apiClient.JSONPatch(patchURL, donePayload); err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -271,7 +272,7 @@ func (rsm *Meta) postTaskSummaries(runID string) []error {
defer wg.Done()
for index := range queue {
task := taskSummaries[index]
payload := newVercelTaskPayload(task)
payload := newSpacesTaskPayload(task)
if taskPayload, err := json.Marshal(payload); err == nil {
if _, err := rsm.apiClient.JSONPost(taskURL, taskPayload); err != nil {
errs = append(errs, fmt.Errorf("Eror uploading summary of %s", task.TaskID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import (
"github.com/vercel/turbo/cli/internal/ci"
)

type vercelRunResponse struct {
type spacesRunResponse 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"`

type spacesRunPayload struct {
// StartTime is when this run was started
StartTime int64 `json:"startTime,omitempty"`

Expand All @@ -34,7 +31,7 @@ type vercelRunPayload struct {
// the command was invoked.
RepositoryPath string `json:"repositoryPath,omitempty"`

// Context is the host on which this Run was executed (e.g. Vercel)
// Context is the host on which this Run was executed (e.g. Github Action, Vercel, etc)
Context string `json:"context,omitempty"`

// TODO: we need to add these in
Expand All @@ -43,31 +40,31 @@ type vercelRunPayload struct {
// gitSha string
}

type vercelCacheStatus struct {
type spacesCacheStatus struct {
Status string `json:"status,omitempty"`
Source string `json:"source,omitempty"`
}

type vercelTask struct {
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 vercelCacheStatus `json:"cache,omitempty"`
Cache spacesCacheStatus `json:"cache,omitempty"`
ExitCode int `json:"exitCode,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Dependents []string `json:"dependents,omitempty"`
}

func (rsm *Meta) newVercelRunCreatePayload() *vercelRunPayload {
func (rsm *Meta) newSpacesRunCreatePayload() *spacesRunPayload {
startTime := rsm.RunSummary.ExecutionSummary.startedAt.UnixMilli()
context := "LOCAL"
if name := ci.Constant(); name != "" {
context = name
}
return &vercelRunPayload{
return &spacesRunPayload{
StartTime: startTime,
Status: "running",
Command: rsm.synthesizedCommand,
Expand All @@ -77,16 +74,16 @@ func (rsm *Meta) newVercelRunCreatePayload() *vercelRunPayload {
}
}

func newVercelDonePayload(runsummary *RunSummary) *vercelRunPayload {
func newSpacesDonePayload(runsummary *RunSummary) *spacesRunPayload {
endTime := runsummary.ExecutionSummary.endedAt.UnixMilli()
return &vercelRunPayload{
return &spacesRunPayload{
Status: "completed",
EndTime: endTime,
ExitCode: runsummary.ExecutionSummary.exitCode,
}
}

func newVercelTaskPayload(taskSummary *TaskSummary) *vercelTask {
func newSpacesTaskPayload(taskSummary *TaskSummary) *spacesTask {
// Set the cache source. Local and Remote shouldn't _both_ be true.
var source string
if taskSummary.CacheState.Local {
Expand All @@ -102,14 +99,14 @@ func newVercelTaskPayload(taskSummary *TaskSummary) *vercelTask {
startTime := taskSummary.Execution.startAt.UnixMilli()
endTime := taskSummary.Execution.endTime().UnixMilli()

return &vercelTask{
return &spacesTask{
Key: taskSummary.TaskID,
Name: taskSummary.Task,
Workspace: taskSummary.Package,
Hash: taskSummary.Hash,
StartTime: startTime,
EndTime: endTime,
Cache: vercelCacheStatus{
Cache: spacesCacheStatus{
Status: status,
Source: source,
},
Expand Down