Skip to content

Commit ea60f31

Browse files
feat: Improvements to dependents workflow (#1631)
- Dependents will now see their `out.openapi.yaml` files updated to reflected the input spec - Dependents can now be run from anywhere in the project
1 parent abf31d5 commit ea60f31

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

cmd/run.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,6 @@ func preRun(cmd *cobra.Command, flags *RunFlags) error {
255255
flags.Target = targets[0]
256256
}
257257

258-
// Needed later
259-
if err := cmd.Flags().Set("target", flags.Target); err != nil {
260-
return err
261-
}
262-
263258
// Dependent only allows a single source for now
264259
if flags.Dependent != "" {
265260
if len(sources) == 1 {
@@ -276,6 +271,17 @@ func preRun(cmd *cobra.Command, flags *RunFlags) error {
276271
}
277272
}
278273

274+
// We must set these after prompting for them or else the user will be prompted a second time
275+
if err := cmd.Flags().Set("source", flags.Source); err != nil {
276+
return err
277+
}
278+
if err := cmd.Flags().Set("target", flags.Target); err != nil {
279+
return err
280+
}
281+
if err := cmd.Flags().Set("dependent", flags.Dependent); err != nil {
282+
return err
283+
}
284+
279285
// Gets a proper value for a mapFlag based on the singleFlag value and the mapFlag value
280286
// Helps ensure that the mapFlag ends up with a value for all the targets being run
281287
checkAndGetMapFlagValue := func(flagName, singleFlag string, mapFlag map[string]string, validLangs []string) (map[string]string, error) {

internal/run/dependent.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func RunDependent(ctx context.Context, source, dependent string, flagsString str
2929
return fmt.Errorf("source must be specified")
3030
}
3131

32-
wf, _, err := utils.GetWorkflowAndDir()
32+
wf, projectDir, err := utils.GetWorkflowAndDir()
3333
if err != nil {
3434
return err
3535
}
@@ -45,7 +45,8 @@ func RunDependent(ctx context.Context, source, dependent string, flagsString str
4545
return fmt.Errorf("failed to build source %s: %w", source, err)
4646
}
4747

48-
sourceLocation, err := filepath.Abs(*wf.Sources[source].Output)
48+
sourceLocation := filepath.Join(projectDir, *wf.Sources[source].Output)
49+
sourceLocation, err = filepath.Abs(sourceLocation)
4950
if err != nil {
5051
return fmt.Errorf("failed to get absolute path for source output: %w", err)
5152
}
@@ -64,22 +65,25 @@ func RunDependent(ctx context.Context, source, dependent string, flagsString str
6465

6566
log.From(ctx).Infof("\n\n=== Rebuilding SDK %s ===\n", dependent)
6667

67-
if err := processDependent(ctx, dependent, r, flagsString, sourceLocation); err != nil {
68+
if err := processDependent(ctx, dependent, r, flagsString, sourceLocation, projectDir); err != nil {
6869
return fmt.Errorf("failed to process dependent %s: %w", dependent, err)
6970
}
7071
}
7172

7273
return nil
7374
}
7475

75-
func processDependent(ctx context.Context, dependentName string, dependent workflow.Dependent, flagsString string, sourceLocation string) error {
76+
func processDependent(ctx context.Context, dependentName string, dependent workflow.Dependent, flagsString string, sourceLocation string, projectDir string) error {
7677
logger := log.From(ctx)
7778

7879
location := dependent.Location
7980
if location == "" {
8081
return fmt.Errorf("dependent %s has no location specified", dependentName)
8182
}
8283

84+
// Resolve location relative to projectDir
85+
location = filepath.Join(projectDir, location)
86+
8387
// Check if location exists
8488
if _, err := os.Stat(location); os.IsNotExist(err) {
8589
cloneCommand := dependent.CloneCommand

internal/run/source.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ func (w *Workflow) RunSource(ctx context.Context, parentStep *workflowTracking.W
168168
}
169169
}
170170

171-
if !frozenSource {
171+
// Must not be frozen source check! We DO want to write for source overrides
172+
if !w.FrozenWorkflowLock {
172173
if err := writeToOutputLocation(ctx, currentDocument, outputLocation); err != nil {
173174
return "", nil, fmt.Errorf("failed to write to output location: %w %s", err, outputLocation)
174175
}

0 commit comments

Comments
 (0)