Skip to content

Commit

Permalink
chore: run make lint on new modules (#2122)
Browse files Browse the repository at this point in the history
* chore: run make lint for new modules

* chore: add readability in the generate function

* chore: modify output message to include make lint
  • Loading branch information
mdelapenya committed Jan 17, 2024
1 parent aef83bf commit b6b4e8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
21 changes: 13 additions & 8 deletions modulegen/internal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ func Generate(moduleVar context.TestcontainersModuleVar, isModule bool) error {
}

cmdDir := filepath.Join(ctx.RootDir, tcModule.ParentDir(), tcModule.Lower())
err = tools.GoModTidy(cmdDir)
if err != nil {
return fmt.Errorf(">> error synchronizing the dependencies: %w", err)
lintCmds := []func(string) error{
tools.GoModTidy,
tools.GoVet,
tools.MakeLint,
}
err = tools.GoVet(cmdDir)
if err != nil {
return fmt.Errorf(">> error checking generated code: %w", err)

for _, lintCmd := range lintCmds {
err = lintCmd(cmdDir)
if err != nil {
return err
}
}

fmt.Println("Please go to", cmdDir, "directory to check the results, where 'go mod tidy' and 'go vet' was executed to synchronize the dependencies")
fmt.Println("Commit the modified files and submit a pull request to include them into the project")
fmt.Println("Please go to", cmdDir, "directory to check the results, where 'go mod tidy', 'go vet' and 'make lint' were executed.")
fmt.Println("🙏 Commit the modified files and submit a pull request to include them into the project.")
fmt.Println("Remember to run 'make lint' before submitting the pull request.")
fmt.Println("Thanks!")
return nil
}
Expand Down
24 changes: 22 additions & 2 deletions modulegen/internal/tools/exec.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
package tools

import (
"fmt"
"os/exec"
)

func GoModTidy(cmdDir string) error {
return runGoCommand(cmdDir, "mod", "tidy")
if err := runGoCommand(cmdDir, "mod", "tidy"); err != nil {
return fmt.Errorf(">> error synchronizing the dependencies: %w", err)
}
return nil
}

func GoVet(cmdDir string) error {
return runGoCommand(cmdDir, "vet", "./...")
if err := runGoCommand(cmdDir, "vet", "./..."); err != nil {
return fmt.Errorf(">> error checking generated code: %w", err)
}
return nil
}

func MakeLint(cmdDir string) error {
if err := runMakeCommand(cmdDir, "lint"); err != nil {
return fmt.Errorf(">> error synchronizing the dependencies: %w", err)
}
return nil
}

func runGoCommand(cmdDir string, args ...string) error {
cmd := exec.Command("go", args...)
cmd.Dir = cmdDir
return cmd.Run()
}

func runMakeCommand(cmdDir string, args ...string) error {
cmd := exec.Command("make", args...)
cmd.Dir = cmdDir
return cmd.Run()
}

0 comments on commit b6b4e8c

Please sign in to comment.