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

Always look up task definition, but limit when it's added to traversa… #3951

Merged
merged 6 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 22 additions & 2 deletions cli/integration_tests/basic_monorepo/filter-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ Setup
$ . ${TESTDIR}/../setup.sh
$ . ${TESTDIR}/setup.sh $(pwd)

# Running with --filter works and exits
$ ${TURBO} run build --filter=main
# Running with --filter works and exits with success
$ git branch
* main

$ ${TURBO} run build --filter="[main]"
\xe2\x80\xa2 Packages in scope: (esc)
\xe2\x80\xa2 Running build in 0 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
Expand All @@ -13,4 +16,21 @@ Setup
Tasks: 0 successful, 0 total
Cached: 0 cached, 0 total
Time:\s*[\.0-9]+m?s (re)


# with unstaged changes
$ echo "new file contents" >> bar.txt
$ git branch
* main

$ ${TURBO} run build --filter="[main]"
\xe2\x80\xa2 Packages in scope: // (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)

No tasks were executed as part of this run.

Tasks: 0 successful, 0 total
Cached: 0 cached, 0 total
Time:\s*[\.0-9]+m?s (re)

1 change: 1 addition & 0 deletions cli/integration_tests/basic_monorepo/monorepo/bar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
other file, not a global dependency
46 changes: 29 additions & 17 deletions cli/internal/core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,39 @@ func (e *Engine) Prepare(options *EngineBuildingOptions) error {
// We do this by taking the input taskNames, and pkgs
// and creating a queue of taskIDs that we can traverse and gather dependencies from.
for _, pkg := range pkgs {
isRootPkg := pkg == util.RootPkgName
for _, taskName := range taskNames {
// If it's not a task from the root workspace (i.e. tasks from every other workspace)
// or if it's a task that we know is rootEnabled task, add it to the traversal queue.
if !isRootPkg || e.rootEnabledTasks.Includes(taskName) {
taskID := util.GetTaskId(pkg, taskName)
// Skip tasks that don't have a definition
if _, err := e.getTaskDefinition(pkg, taskName, taskID); err != nil {
var e *MissingTaskError
if errors.As(err, &e) {
// Initially, non-package tasks are not required to exist, as long as some
// package in the list packages defines it as a package-task. Dependencies
// *are* required to have a definition.
continue
}

return err
taskID := util.GetTaskId(pkg, taskName)

// Look up the task in the package
foundTask, err := e.getTaskDefinition(pkg, taskName, taskID)

// We can skip MissingTaskErrors because we'll validate against them later
// Return all other errors
if err != nil {
var e *MissingTaskError
if errors.As(err, &e) {
// Initially, non-package tasks are not required to exist, as long as some
// package in the list packages defines it as a package-task. Dependencies
// *are* required to have a definition.
continue
}

return err
}

// If we found a task definition, remove it from the msising list
mehulkar marked this conversation as resolved.
Show resolved Hide resolved
if foundTask != nil {
// delete taskName if it was found
missing.Delete(taskName)
traversalQueue = append(traversalQueue, taskID)

// Even if a task definition was found, we _only_ want to add it as an entry point to
// the task graph (i.e. the traversalQueue), if it's:
// - A task from the non-root workspace (i.e. tasks from every other workspace)
// - A task that we *know* is rootEnabled task (in which case, the root workspace is acceptable)
isRootPkg := pkg == util.RootPkgName
if !isRootPkg || e.rootEnabledTasks.Includes(taskName) {
traversalQueue = append(traversalQueue, taskID)
}
}
}
}
Expand Down