-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Synthesize a command for a Run (#4499)
- Loading branch information
Greg Soltis
authored
Apr 10, 2023
1 parent
823eb41
commit 99a8b68
Showing
9 changed files
with
240 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package run | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/vercel/turbo/cli/internal/scope" | ||
"github.com/vercel/turbo/cli/internal/util" | ||
) | ||
|
||
func TestSynthesizeCommand(t *testing.T) { | ||
testCases := []struct { | ||
filterPatterns []string | ||
legacyFilter scope.LegacyFilter | ||
passThroughArgs []string | ||
parallel bool | ||
continueOnError bool | ||
dryRun bool | ||
dryRunJSON bool | ||
tasks []string | ||
expected string | ||
}{ | ||
{ | ||
filterPatterns: []string{"my-app"}, | ||
tasks: []string{"build"}, | ||
expected: "turbo run build --filter=my-app", | ||
}, | ||
{ | ||
filterPatterns: []string{"my-app"}, | ||
tasks: []string{"build"}, | ||
passThroughArgs: []string{"-v", "--foo=bar"}, | ||
expected: "turbo run build --filter=my-app -- -v --foo=bar", | ||
}, | ||
{ | ||
legacyFilter: scope.LegacyFilter{ | ||
Entrypoints: []string{"my-app"}, | ||
SkipDependents: true, | ||
}, | ||
tasks: []string{"build"}, | ||
passThroughArgs: []string{"-v", "--foo=bar"}, | ||
expected: "turbo run build --filter=my-app -- -v --foo=bar", | ||
}, | ||
{ | ||
legacyFilter: scope.LegacyFilter{ | ||
Entrypoints: []string{"my-app"}, | ||
SkipDependents: true, | ||
}, | ||
filterPatterns: []string{"other-app"}, | ||
tasks: []string{"build"}, | ||
passThroughArgs: []string{"-v", "--foo=bar"}, | ||
expected: "turbo run build --filter=other-app --filter=my-app -- -v --foo=bar", | ||
}, | ||
{ | ||
legacyFilter: scope.LegacyFilter{ | ||
Entrypoints: []string{"my-app"}, | ||
IncludeDependencies: true, | ||
Since: "some-ref", | ||
}, | ||
filterPatterns: []string{"other-app"}, | ||
tasks: []string{"build"}, | ||
expected: "turbo run build --filter=other-app --filter=...my-app...[some-ref]...", | ||
}, | ||
{ | ||
filterPatterns: []string{"my-app"}, | ||
tasks: []string{"build"}, | ||
parallel: true, | ||
continueOnError: true, | ||
expected: "turbo run build --filter=my-app --parallel --continue", | ||
}, | ||
{ | ||
filterPatterns: []string{"my-app"}, | ||
tasks: []string{"build"}, | ||
dryRun: true, | ||
expected: "turbo run build --filter=my-app --dry", | ||
}, | ||
{ | ||
filterPatterns: []string{"my-app"}, | ||
tasks: []string{"build"}, | ||
dryRun: true, | ||
dryRunJSON: true, | ||
expected: "turbo run build --filter=my-app --dry=json", | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(testCase.expected, func(t *testing.T) { | ||
o := Opts{ | ||
scopeOpts: scope.Opts{ | ||
FilterPatterns: testCase.filterPatterns, | ||
LegacyFilter: testCase.legacyFilter, | ||
}, | ||
runOpts: util.RunOpts{ | ||
PassThroughArgs: testCase.passThroughArgs, | ||
Parallel: testCase.parallel, | ||
ContinueOnError: testCase.continueOnError, | ||
DryRun: testCase.dryRun, | ||
DryRunJSON: testCase.dryRunJSON, | ||
}, | ||
} | ||
cmd := o.SynthesizeCommand(testCase.tasks) | ||
if cmd != testCase.expected { | ||
t.Errorf("SynthesizeCommand() got %v, want %v", cmd, testCase.expected) | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
|
@@ -41,14 +40,16 @@ const ( | |
// Meta is a wrapper around the serializable RunSummary, with some extra information | ||
// about the Run and references to other things that we need. | ||
type Meta struct { | ||
RunSummary *RunSummary | ||
ui cli.Ui | ||
repoRoot turbopath.AbsoluteSystemPath // used to write run summary | ||
singlePackage bool | ||
shouldSave bool | ||
apiClient *client.APIClient | ||
spaceID string | ||
runType runType | ||
RunSummary *RunSummary | ||
ui cli.Ui | ||
repoRoot turbopath.AbsoluteSystemPath // used to write run summary | ||
repoPath turbopath.RelativeSystemPath | ||
singlePackage bool | ||
shouldSave bool | ||
apiClient *client.APIClient | ||
spaceID string | ||
runType runType | ||
synthesizedCommand string | ||
} | ||
|
||
// RunSummary contains a summary of what happens in the `turbo run` command and why. | ||
|
@@ -67,11 +68,13 @@ func NewRunSummary( | |
startAt time.Time, | ||
ui cli.Ui, | ||
repoRoot turbopath.AbsoluteSystemPath, | ||
repoPath turbopath.RelativeSystemPath, | ||
turboVersion string, | ||
apiClient *client.APIClient, | ||
runOpts util.RunOpts, | ||
packages []string, | ||
globalHashSummary *GlobalHashSummary, | ||
synthesizedCommand string, | ||
) Meta { | ||
singlePackage := runOpts.SinglePackage | ||
profile := runOpts.Profile | ||
|
@@ -86,7 +89,7 @@ func NewRunSummary( | |
} | ||
} | ||
|
||
executionSummary := newExecutionSummary(startAt, profile) | ||
executionSummary := newExecutionSummary(synthesizedCommand, repoPath, startAt, profile) | ||
|
||
return Meta{ | ||
RunSummary: &RunSummary{ | ||
|
@@ -98,13 +101,14 @@ func NewRunSummary( | |
Tasks: []*TaskSummary{}, | ||
GlobalHashSummary: globalHashSummary, | ||
}, | ||
ui: ui, | ||
runType: runType, | ||
repoRoot: repoRoot, | ||
singlePackage: singlePackage, | ||
shouldSave: shouldSave, | ||
apiClient: apiClient, | ||
spaceID: spaceID, | ||
ui: ui, | ||
runType: runType, | ||
repoRoot: repoRoot, | ||
singlePackage: singlePackage, | ||
shouldSave: shouldSave, | ||
apiClient: apiClient, | ||
spaceID: spaceID, | ||
synthesizedCommand: synthesizedCommand, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mehulkar
Contributor
|
||
} | ||
} | ||
|
||
|
@@ -181,16 +185,6 @@ func (summary *RunSummary) TrackTask(taskID string) (func(outcome executionEvent | |
return summary.ExecutionSummary.run(taskID) | ||
} | ||
|
||
// command returns a best guess command for the entire Run. | ||
// TODO: we should thread this through from the entry point rather than make it up | ||
func (summary *RunSummary) command() string { | ||
taskNames := make(util.Set, len(summary.Tasks)) | ||
for _, task := range summary.Tasks { | ||
taskNames.Add(task.Task) | ||
} | ||
return fmt.Sprintf("turbo run %s", strings.Join(taskNames.UnsafeListOfStrings(), " ")) | ||
} | ||
|
||
// Save saves the run summary to a file | ||
func (rsm *Meta) save() error { | ||
json, err := rsm.FormatJSON() | ||
|
@@ -219,7 +213,7 @@ func (rsm *Meta) record() []error { | |
// can happen when the Run actually starts, so we can send updates to Vercel as the tasks progress. | ||
runsURL := fmt.Sprintf(runsEndpoint, rsm.spaceID) | ||
var runID string | ||
payload := newVercelRunCreatePayload(rsm.RunSummary) | ||
payload := rsm.newVercelRunCreatePayload() | ||
if startPayload, err := json.Marshal(payload); err == nil { | ||
if resp, err := rsm.apiClient.JSONPost(runsURL, startPayload); err != nil { | ||
errs = append(errs, err) | ||
|
Oops, something went wrong.
Does repoPath need to be passed here?