Skip to content

Commit

Permalink
fix: update studio handlers to bootstrap overflow path from source (#891
Browse files Browse the repository at this point in the history
)
  • Loading branch information
adaam2 authored Aug 28, 2024
1 parent 9d7afa0 commit c1c9955
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
21 changes: 17 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var runCmd = &model.ExecutableCommand[RunFlags]{
Short: "Run all the workflows defined in your workflow.yaml file. This can include multiple SDK generations from different OpenAPI sources",
Long: utils.RenderMarkdown(runLong),
PreRun: preRun,
Run: runFunc,
Run: runNonInteractive,
RunInteractive: runInteractive,
RequiresAuth: true,
UsesWorkflowFile: true,
Expand Down Expand Up @@ -284,13 +284,12 @@ func askForSource(sources []string) (string, error) {
return source, nil
}

func runFunc(ctx context.Context, flags RunFlags) error {
func runNonInteractive(ctx context.Context, flags RunFlags) error {
if flags.GitHub {
return run.RunGitHub(ctx, flags.Target, flags.SetVersion, flags.Force)
}

workflow, err := run.NewWorkflow(
ctx,
opts := []run.Opt{
run.WithTarget(flags.Target),
run.WithSource(flags.Source),
run.WithRepo(flags.Repo),
Expand All @@ -304,7 +303,17 @@ func runFunc(ctx context.Context, flags RunFlags) error {
run.WithRegistryTags(flags.RegistryTags),
run.WithSetVersion(flags.SetVersion),
run.WithFrozenWorkflowLock(flags.FrozenWorkflowLock),
}

if flags.LaunchStudio {
opts = append(opts, run.WithSkipCleanup())
}

workflow, err := run.NewWorkflow(
ctx,
opts...,
)

if err != nil {
return err
}
Expand All @@ -315,6 +324,10 @@ func runFunc(ctx context.Context, flags RunFlags) error {

github.GenerateWorkflowSummary(ctx, workflow.RootStep)

if flags.LaunchStudio {
return studio.LaunchStudio(ctx, workflow)
}

return err
}

Expand Down
25 changes: 12 additions & 13 deletions internal/studio/studioHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,26 @@ type StudioHandlers struct {
Ctx context.Context
}

func NewStudioHandlers(ctx context.Context, workflow *run.Workflow) (*StudioHandlers, error) {
ret := &StudioHandlers{WorkflowRunner: *workflow, Ctx: ctx}
func NewStudioHandlers(ctx context.Context, workflowRunner *run.Workflow) (*StudioHandlers, error) {
ret := &StudioHandlers{WorkflowRunner: *workflowRunner, Ctx: ctx}

sourceID, err := findWorkflowSourceIDBasedOnTarget(*workflow, workflow.Target)
sourceID, err := findWorkflowSourceIDBasedOnTarget(*workflowRunner, workflowRunner.Target)
if err != nil {
return ret, fmt.Errorf("error finding source: %w", err)
}
if sourceID == "" {
return ret, errors.New("unable to find source")
}
ret.SourceID = sourceID
sourceConfig := workflowRunner.GetWorkflowFile().Sources[sourceID]

for _, overlay := range sourceConfig.Overlays {
// If there are multiple modifications overlays - we take the last one
contents, _ := isStudioModificationsOverlay(overlay)
if contents != "" {
ret.OverlayPath = overlay.Document.Location
}
}

return ret, nil
}
Expand Down Expand Up @@ -263,16 +272,6 @@ func (h *StudioHandlers) getSourceInner(ctx context.Context) (*run.SourceResult,
return nil, fmt.Errorf("error running source: %w", err)
}

sourceConfig := workflowRunner.GetWorkflowFile().Sources[sourceID]

for _, overlay := range sourceConfig.Overlays {
// If there are multiple modifications overlays - we take the last one
contents, _ := isStudioModificationsOverlay(overlay)
if contents != "" {
h.OverlayPath = overlay.Document.Location
}
}

return sourceResult, nil
}

Expand Down

0 comments on commit c1c9955

Please sign in to comment.