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

filter out invalid Pipelines from TurboJSON when running turbo prune #3216

Merged
merged 4 commits into from
Jan 27, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
filter out pruned packages from the turbo.json when running a prune
  • Loading branch information
arlyon committed Jan 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 4ae0782771bb151d8fa8c36d904e3fe0ae55ec20
34 changes: 31 additions & 3 deletions cli/internal/prune/prune.go
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import (
"github.com/vercel/turbo/cli/internal/turbopath"
"github.com/vercel/turbo/cli/internal/turbostate"
"github.com/vercel/turbo/cli/internal/ui"
"github.com/vercel/turbo/cli/internal/util"

"github.com/fatih/color"
"github.com/hashicorp/go-hclog"
@@ -201,9 +202,36 @@ func (p *prune) prune(opts *turbostate.PrunePayload) error {
}
}

if fs.FileExists("turbo.json") {
if err := fs.CopyFile(&fs.LstatCachedFile{Path: p.base.RepoRoot.UntypedJoin("turbo.json")}, fullDir.UntypedJoin("turbo.json").ToStringDuringMigration()); err != nil {
return errors.Wrap(err, "failed to copy root turbo.json")
turboJSON, err := fs.LoadTurboConfig(p.base.RepoRoot, rootPackageJSON, false)
if err != nil {
return errors.Wrap(err, "failed to read turbo.json")
}
if turboJSON != nil {
// when executing a prune, it is not enough to simply copy the file, as
// tasks may refer to scopes that no longer exist. to remedy this, we need
// to remove from the Pipeline the TaskDefinitions that no longer apply
for pipelineTask := range turboJSON.Pipeline {
includeTask := false
for _, includedPackage := range targets {
if util.IsTaskInPackage(pipelineTask, includedPackage) {
includeTask = true
break
}
}

if !includeTask {
delete(turboJSON.Pipeline, pipelineTask)
}
}

bytes, err := turboJSON.MarshalJSON()

if err != nil {
return errors.Wrap(err, "failed to write turbo.json")
arlyon marked this conversation as resolved.
Show resolved Hide resolved
}

if err := fullDir.UntypedJoin("turbo.json").WriteFile(bytes, 0644); err != nil {
return errors.Wrap(err, "failed to prune workspace tasks from turbo.json")
}
}