-
-
Notifications
You must be signed in to change notification settings - Fork 119
feat(code-quality): add golangci-lint to CI and lint project #245
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
Changes from all commits
12da984
7f28beb
4e63324
1779fcd
90ab8cb
8f5915c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
run: | ||
timeout: 30s | ||
issues-exit-code: 1 | ||
|
||
linters: | ||
enable: | ||
- gci | ||
- wrapcheck | ||
|
||
linters-settings: | ||
wrapcheck: | ||
ignorePackageGlobs: | ||
# We already make sure your own packages wrap errors properly | ||
- github.com/symfony-cli/* | ||
errcheck: | ||
ignore: github.com/symfony-cli/terminal:^(Ep|P)rint | ||
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -35,7 +35,9 @@ import ( | |||||||||||||
func (b *Book) Checkout(step string) error { | ||||||||||||||
// FIXME: keep vendor/ node_modules/ around before git clean, but them back as they will be updated the right way, less Internet traffic | ||||||||||||||
// FIXME: if the checkout is to a later step, no need to remove the DB, we can just migrate it | ||||||||||||||
os.Chdir(b.Dir) | ||||||||||||||
if err := os.Chdir(b.Dir); err != nil { | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
Comment on lines
+38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'm not saying we have to do it, but we can do it when there's only a single return value, this also better preserve stack traces IIRC |
||||||||||||||
step = strings.Replace(step, ".", "-", -1) | ||||||||||||||
tag := fmt.Sprintf("step-%s", step) | ||||||||||||||
branch := "work-" + tag | ||||||||||||||
|
@@ -80,21 +82,21 @@ func (b *Book) Checkout(step string) error { | |||||||||||||
|
||||||||||||||
printBanner("<comment>[GIT]</> Removing Git ignored files (vendor, cache, ...)", b.Debug) | ||||||||||||||
if err := executeCommand([]string{"git", "clean", "-d", "-f", "-x"}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
printBanner("<comment>[GIT]</> Resetting Git staged files", b.Debug) | ||||||||||||||
if err := executeCommand([]string{"git", "reset", "HEAD", "."}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
printBanner("<comment>[GIT]</> Removing un-tracked Git files", b.Debug) | ||||||||||||||
if err := executeCommand([]string{"git", "checkout", "."}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[WEB]</> Adding .env.local", b.Debug) | ||||||||||||||
emptyFile, err := os.Create(filepath.Join(b.Dir, ".env.local")) | ||||||||||||||
if err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
emptyFile.Close() | ||||||||||||||
if !b.Debug { | ||||||||||||||
|
@@ -110,40 +112,44 @@ func (b *Book) Checkout(step string) error { | |||||||||||||
printBanner("<comment>[WEB]</> Stopping Docker Containers", b.Debug) | ||||||||||||||
if hasDocker { | ||||||||||||||
if err := executeCommand(append(dockerComposeBin(), "down", "--remove-orphans"), b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[WEB]</> Stopping the Local Web Server", b.Debug) | ||||||||||||||
executeCommand([]string{"symfony", "server:stop"}, b.Debug, true, nil) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would tend to think that @fabpot deliberately skip this one |
||||||||||||||
if err = executeCommand([]string{"symfony", "server:stop"}, b.Debug, true, nil); err != nil { | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[WEB]</> Stopping the Platform.sh tunnel", b.Debug) | ||||||||||||||
if err := executeCommand([]string{"symfony", "tunnel:close", "-y"}, b.Debug, true, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[GIT]</> Checking out the step", b.Debug) | ||||||||||||||
if err := executeCommand([]string{"git", "checkout", "-B", branch, tag}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[SPA]</> Stopping the Local Web Server", b.Debug) | ||||||||||||||
if _, err := os.Stat(filepath.Join(b.Dir, "spa")); err == nil { | ||||||||||||||
executeCommand([]string{"symfony", "server:stop", "--dir", filepath.Join(b.Dir, "spa")}, b.Debug, true, nil) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||||||||||||||
if err = executeCommand([]string{"symfony", "server:stop", "--dir", filepath.Join(b.Dir, "spa")}, b.Debug, true, nil); err != nil { | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[WEB]</> Installing Composer dependencies (might take some time)", b.Debug) | ||||||||||||||
if err := executeCommand([]string{"symfony", "composer", "install"}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[WEB]</> Adding .env.local", b.Debug) | ||||||||||||||
if emptyFile, err = os.Create(filepath.Join(b.Dir, ".env.local")); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
emptyFile.Close() | ||||||||||||||
if !b.Debug { | ||||||||||||||
|
@@ -153,7 +159,7 @@ func (b *Book) Checkout(step string) error { | |||||||||||||
printBanner("<comment>[WEB]</> Starting Docker Compose", b.Debug) | ||||||||||||||
if hasDocker { | ||||||||||||||
if err := executeCommand(append(dockerComposeBin(), "up", "-d"), b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
printBanner("<comment>[WEB]</> Waiting for the Containers to be ready", b.Debug) | ||||||||||||||
if _, err := os.Stat(filepath.Join(b.Dir, "src", "MessageHandler", "CommentMessageHandler.php")); err == nil { | ||||||||||||||
|
@@ -179,7 +185,7 @@ func (b *Book) Checkout(step string) error { | |||||||||||||
} | ||||||||||||||
if hasMigrations { | ||||||||||||||
if err := executeCommand([]string{"symfony", "console", "doctrine:migrations:migrate", "-n"}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
|
@@ -188,7 +194,7 @@ func (b *Book) Checkout(step string) error { | |||||||||||||
printBanner("<comment>[WEB]</> Inserting Fixtures", b.Debug) | ||||||||||||||
if _, err := os.Stat(filepath.Join(b.Dir, "src", "DataFixtures")); err == nil { | ||||||||||||||
if err := executeCommand([]string{"symfony", "console", "doctrine:fixtures:load", "-n"}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
|
@@ -202,7 +208,7 @@ func (b *Book) Checkout(step string) error { | |||||||||||||
args = []string{"yarn", "install"} | ||||||||||||||
} | ||||||||||||||
if err := executeCommand(args, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
|
@@ -215,38 +221,42 @@ func (b *Book) Checkout(step string) error { | |||||||||||||
args = []string{"yarn", "encore", "dev"} | ||||||||||||||
} | ||||||||||||||
if err := executeCommand(args, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[WEB]</> Starting the Local Web Server", b.Debug) | ||||||||||||||
if err := executeCommand([]string{"symfony", "server:start", "-d"}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[WEB]</> Starting Message Consumer", b.Debug) | ||||||||||||||
if _, err := os.Stat(filepath.Join(b.Dir, "src", "MessageHandler", "CommentMessageHandler.php")); err == nil { | ||||||||||||||
if err := executeCommand([]string{"symfony", "run", "-d", "--watch", "config,src,templates,vendor", "symfony", "console", "messenger:consume", "async", "-vv"}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[SPA]</> Installing Node dependencies (might take some time)", b.Debug) | ||||||||||||||
if _, err := os.Stat(filepath.Join(b.Dir, "spa")); err == nil { | ||||||||||||||
os.Chdir(filepath.Join(b.Dir, "spa")) | ||||||||||||||
if err = os.Chdir(filepath.Join(b.Dir, "spa")); err != nil { | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
args := []string{"npm", "install"} | ||||||||||||||
if _, err := os.Stat(filepath.Join(b.Dir, "yarn.lock")); err == nil { | ||||||||||||||
// old version of the book using Yarn instead of npm | ||||||||||||||
args = []string{"yarn", "install"} | ||||||||||||||
} | ||||||||||||||
if err := executeCommand(args, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
if err = os.Chdir(b.Dir); err != nil { | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
os.Chdir(b.Dir) | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
} | ||||||||||||||
|
@@ -264,24 +274,28 @@ func (b *Book) Checkout(step string) error { | |||||||||||||
if endpoint.String() == "" { | ||||||||||||||
return errors.Errorf("unable to get the URL of the local web server:\n%s\n%s", stderr.String(), endpoint.String()) | ||||||||||||||
} | ||||||||||||||
os.Chdir(filepath.Join(b.Dir, "spa")) | ||||||||||||||
if err = os.Chdir(filepath.Join(b.Dir, "spa")); err != nil { | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
env := append(os.Environ(), "API_ENDPOINT="+endpoint.String()) | ||||||||||||||
args := []string{"npx", "encore", "dev"} | ||||||||||||||
if _, err := os.Stat(filepath.Join(b.Dir, "yarn.lock")); err == nil { | ||||||||||||||
args = []string{"yarn", "encore", "dev"} | ||||||||||||||
} | ||||||||||||||
if err := executeCommand(args, b.Debug, false, env); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
if err = os.Chdir(b.Dir); err != nil { | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
os.Chdir(b.Dir) | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
printBanner("<comment>[SPA]</> Starting the Local Web Server", b.Debug) | ||||||||||||||
if _, err := os.Stat(filepath.Join(b.Dir, "spa")); err == nil { | ||||||||||||||
if err := executeCommand([]string{"symfony", "server:start", "-d", "--passthru", "index.html", "--dir", filepath.Join(b.Dir, "spa")}, b.Debug, false, nil); err != nil { | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
terminal.Println("Skipped for this step") | ||||||||||||||
|
@@ -322,7 +336,7 @@ func executeCommand(args []string, debug, skipErrors bool, env []string) error { | |||||||||||||
terminal.Println("<error>[ KO ]</>") | ||||||||||||||
} | ||||||||||||||
terminal.Print(buf.String()) | ||||||||||||||
return err | ||||||||||||||
return errors.WithStack(err) | ||||||||||||||
} | ||||||||||||||
if !debug { | ||||||||||||||
terminal.Println("<info>[ OK ]</>") | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing newline at the end of the file