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

fix(spaces): read logs correctly when invoked from subdirectory #5284

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
23 changes: 15 additions & 8 deletions cli/internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package graph
import (
gocontext "context"
"fmt"
"path/filepath"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -124,8 +123,15 @@ func (g *CompleteGraph) GetPackageTaskVisitor(
expandedInputs := g.TaskHashTracker.GetExpandedInputs(packageTask)
framework := g.TaskHashTracker.GetFramework(taskID)

logFile := repoRelativeLogFile(pkgDir, taskName)
packageTask.LogFile = logFile
logFileAbsolutePath := taskLogFile(g.RepoRoot, pkgDir, taskName)

var logFileRelativePath string
if logRelative, err := logFileAbsolutePath.RelativeTo(g.RepoRoot); err == nil {
logFileRelativePath = logRelative.ToString()
}

// Give packageTask a string version of the logFile relative to root.
packageTask.LogFile = logFileRelativePath
packageTask.Command = command

envVarPassThroughMap, err := g.TaskHashTracker.EnvAtExecutionStart.FromWildcards(taskDefinition.PassThroughEnv)
Expand All @@ -146,7 +152,8 @@ func (g *CompleteGraph) GetPackageTaskVisitor(
Dir: pkgDir.ToString(),
Outputs: taskDefinition.Outputs.Inclusions,
ExcludedOutputs: taskDefinition.Outputs.Exclusions,
LogFile: logFile,
LogFileRelativePath: logFileRelativePath,
LogFileAbsolutePath: logFileAbsolutePath,
ResolvedTaskDefinition: taskDefinition,
ExpandedInputs: expandedInputs,
ExpandedOutputs: []turbopath.AnchoredSystemPath{},
Expand Down Expand Up @@ -229,10 +236,10 @@ func (g *CompleteGraph) GetPackageJSONFromWorkspace(workspaceName string) (*fs.P
return nil, fmt.Errorf("No package.json for %s", workspaceName)
}

// repoRelativeLogFile returns the path to the log file for this task execution as a
// relative path from the root of the monorepo.
func repoRelativeLogFile(dir turbopath.AnchoredSystemPath, taskName string) string {
return filepath.Join(dir.ToStringDuringMigration(), ".turbo", fmt.Sprintf("turbo-%v.log", taskName))
// taskLogFile returns the path to the log file for this task execution as an absolute path
func taskLogFile(root turbopath.AbsoluteSystemPath, dir turbopath.AnchoredSystemPath, taskName string) turbopath.AbsoluteSystemPath {
pkgDir := dir.RestoreAnchor(root)
return pkgDir.UntypedJoin(".turbo", fmt.Sprintf("turbo-%v.log", taskName))
}

// getTaskGraphAncestors gets all the ancestors for a given task in the graph.
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/runsummary/format_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (rsm Meta) FormatAndPrintText(workspaceInfos workspace.Catalog) error {

fmt.Fprintln(w, util.Sprintf(" ${GREY}Command\t=\t%s\t${RESET}", task.Command))
fmt.Fprintln(w, util.Sprintf(" ${GREY}Outputs\t=\t%s\t${RESET}", strings.Join(task.Outputs, ", ")))
fmt.Fprintln(w, util.Sprintf(" ${GREY}Log File\t=\t%s\t${RESET}", task.LogFile))
fmt.Fprintln(w, util.Sprintf(" ${GREY}Log File\t=\t%s\t${RESET}", task.LogFileRelativePath))
fmt.Fprintln(w, util.Sprintf(" ${GREY}Dependencies\t=\t%s\t${RESET}", strings.Join(task.Dependencies, ", ")))
fmt.Fprintln(w, util.Sprintf(" ${GREY}Dependendents\t=\t%s\t${RESET}", strings.Join(task.Dependents, ", ")))
fmt.Fprintln(w, util.Sprintf(" ${GREY}Inputs Files Considered\t=\t%d\t${RESET}", len(task.ExpandedInputs)))
Expand Down
9 changes: 4 additions & 5 deletions cli/internal/runsummary/task_summary.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package runsummary

import (
"os"

"github.com/vercel/turbo/cli/internal/cache"
"github.com/vercel/turbo/cli/internal/fs"
"github.com/vercel/turbo/cli/internal/turbopath"
Expand Down Expand Up @@ -67,7 +65,8 @@ type TaskSummary struct {
CommandArguments []string `json:"cliArguments"`
Outputs []string `json:"outputs"`
ExcludedOutputs []string `json:"excludedOutputs"`
LogFile string `json:"logFile"`
LogFileRelativePath string `json:"logFile"`
LogFileAbsolutePath turbopath.AbsoluteSystemPath `json:"-"`
Dir string `json:"directory,omitempty"`
Dependencies []string `json:"dependencies"`
Dependents []string `json:"dependents"`
Expand All @@ -80,9 +79,9 @@ type TaskSummary struct {
Execution *TaskExecutionSummary `json:"execution,omitempty"` // omit when it's not set
}

// GetLogs reads the Logfile and returns the data
// GetLogs reads the log file and returns the data
func (ts *TaskSummary) GetLogs() []byte {
bytes, err := os.ReadFile(ts.LogFile)
bytes, err := ts.LogFileAbsolutePath.ReadFile()
if err != nil {
return []byte{}
}
Expand Down