Skip to content

Commit

Permalink
fix: run go mod tidy on _ftl/go/modules too (#1108)
Browse files Browse the repository at this point in the history
This isn't necessary to build, but VSCode doesn't like it.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
alecthomas and github-actions[bot] authored Mar 18, 2024
1 parent c42cc85 commit 1a461c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
34 changes: 26 additions & 8 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/TBD54566975/scaffolder"
"golang.design/x/reflect"
"golang.org/x/mod/modfile"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/proto"

"github.com/TBD54566975/ftl"
Expand Down Expand Up @@ -97,11 +98,6 @@ func Build(ctx context.Context, moduleDir string, sch *schema.Schema) error {
return err
}

logger.Debugf("Tidying go.mod")
if err := exec.Command(ctx, log.Debug, moduleDir, "go", "mod", "tidy").RunBuffered(ctx); err != nil {
return fmt.Errorf("failed to tidy go.mod: %w", err)
}

logger.Debugf("Extracting schema")
nativeNames, main, err := ExtractModuleSchema(moduleDir)
if err != nil {
Expand Down Expand Up @@ -145,12 +141,34 @@ func Build(ctx context.Context, moduleDir string, sch *schema.Schema) error {
return err
}

logger.Debugf("Compiling")
wg, wgctx := errgroup.WithContext(ctx)

logger.Debugf("Tidying go.mod files")
wg.Go(func() error {
if err := exec.Command(ctx, log.Debug, moduleDir, "go", "mod", "tidy").RunBuffered(ctx); err != nil {
return fmt.Errorf("%s: failed to tidy go.mod: %w", moduleDir, err)
}
return nil
})
mainDir := filepath.Join(buildDir, "go", "main")
if err := exec.Command(ctx, log.Debug, mainDir, "go", "mod", "tidy").RunBuffered(ctx); err != nil {
return fmt.Errorf("failed to tidy go.mod: %w", err)
wg.Go(func() error {
if err := exec.Command(wgctx, log.Debug, mainDir, "go", "mod", "tidy").RunBuffered(wgctx); err != nil {
return fmt.Errorf("%s: failed to tidy go.mod: %w", mainDir, err)
}
return nil
})
wg.Go(func() error {
modulesDir := filepath.Join(buildDir, "go", "modules")
if err := exec.Command(wgctx, log.Debug, modulesDir, "go", "mod", "tidy").RunBuffered(wgctx); err != nil {
return fmt.Errorf("%s: failed to tidy go.mod: %w", modulesDir, err)
}
return nil
})
if err := wg.Wait(); err != nil {
return err
}

logger.Debugf("Compiling")
return exec.Command(ctx, log.Debug, mainDir, "go", "build", "-o", "../../main", ".").RunBuffered(ctx)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/model/deployment_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ParseDeploymentKey(input string) (DeploymentKey, error) {
}, nil
}

func (d *DeploymentKey) String() string {
func (d DeploymentKey) String() string {
return fmt.Sprintf("%s-%s", d.module, d.hash)
}

Expand Down

0 comments on commit 1a461c6

Please sign in to comment.