Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run make lint on new modules #2122

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading