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

Project build & development toolchain #62

Closed
arcticicestudio opened this issue Jun 24, 2019 · 1 comment
Closed

Project build & development toolchain #62

arcticicestudio opened this issue Jun 24, 2019 · 1 comment

Comments

@arcticicestudio
Copy link
Owner

arcticicestudio commented Jun 24, 2019

Epic: #33
Depends on #58

Mage

The main project development and build toolchain for snowsaw will be Mage, a Make/rake-like build tool using
Go.
The magefile.go file will provide all relevant project tasks - from development and production builds, testing amd linting workflows, benchmarking up to code optimizations and asset handling.

Even though Go comes with a complete development/testing/deployment suite out-of-the-box, a project build tool ensures all commands always executed in the correct order and all necessary information are provided. Under the hood, the magefile file will make use of Go's official toolchain, but ensures consistency and a simple usage through Mage's UI features.

IntelliJ Development Setup

Next to the Mage this ticket will also add file watcher configurations for IntelliJ's official “File Watcher“ plugin.
IntelliJ plus the official Go plugin is the recommended development IDE since it is the most complete and powerful for Go (as well as the most popular IDE for Java), providing a large amount of features. The official Go plugin makes IntelliJ feature-equal to Goland which is a "stripped down" version of IntelliJ's core engine only bundled with Go features.

GolangCI

To ensure a good code quality the Go ecosystem has hundreds of linters, each with a different purpose. Instead of installing and running multiple linters separately GolangCI provides a uniform interface to run most popular and useful linters in parallel and with many additional configuration features. The service is like many other great platforms free for open source projects.
The actual runner golangci-lint is also open source and can be used locally as well in any private CI/CD pipelines. In order to use it for snowsaw, a .golangci.yml configuration file will be added and the runner will be executed through a lin Mage task.

Cross-Compilation

Go comes with all necessary tools to cross-compile out-of-the-box, but instead of running the commands manually gox will be used to also simplify this task as well as running and managing the compilation in parallel. To create distributions with and without binary artifact optimizations new Mage tasks will be added.

Formatting

To adhere to the Go code styleguide and conventions the official goimports tool will be used, executed through a dedicated _Mage task.

Testing

Go comes with all necessary testing tools out-of-the-box that be used through Mage tasks where a distinction is made between unit and integration tests as well as with and without coverage profiling. The coverage reports can be used later on to integrate services like CodeCov into snowsaw's CI/CD pipeline.

@arcticicestudio arcticicestudio added this to the 0.4.0 milestone Jun 24, 2019
@arcticicestudio arcticicestudio self-assigned this Jun 24, 2019
arcticicestudio added a commit that referenced this issue Jun 24, 2019
snowsaw will be build using the latest Go version 1.12.6 (1) (to the
time this commit is written) with Go Modules (2).
This commits initialized snowsaw as Go module by running the
`go mod init` command in order to create the `go.mod` file.
The name of the module is `github.com/arcticicestudio/snowsaw` since
this repository will be used as origin hosted on GitHub.

References:
  (1) https://golang.org/dl/#go1.12.6
  (2) https://github.com/golang/go/wiki/Modules

Epic GH-33
Blocks GH-59 GH-60 GH-61 GH-62
Resolves GH-58
@arcticicestudio arcticicestudio changed the title Mage project build & development toolchain Project build & development toolchain Jun 29, 2019
arcticicestudio added a commit that referenced this issue Jun 29, 2019
>>> Mage

The main project development and build toolchain for snowsaw is
Mage (1), a Make/rake-like build tool using Go.
The `magefile.go` file provides all relevant project tasks - from
development and production builds, testing amd linting workflows,
benchmarking up to code optimizations and asset handling.

Even though Go comes with a complete development/testing/deployment
suite out-of-the-box, a project build tool ensures all commands always
executed in the correct order and all necessary information are
provided. Under the hood, the `magefile` file will make use of Go's
official toolchain, but ensures consistency and a simple usage through
Mage's UI features.

>>> IntelliJ Development Setup

Next to Mage this commit also adds file watcher configurations (2) for
IntelliJ's (3) official "File Watcher" plugin (4).
IntelliJ plus the official Go plugin (5) is the recommended development
IDE since it is the most complete and powerful for Go (as well as the
most popular IDE for Java), providing a large amount of features.
The official Go plugin (5) makes IntelliJ feature-equal to Goland (6)
which is a "stripped down" version of IntelliJ's core engine only
bundled with Go features.

>>> GolangCI

To ensure a good code quality the Go ecosystem has hundreds of linters,
each with a different purpose. Instead of installing and running
multiple linters separately GolangCI (7) provides a uniform interface to
run most popular and useful linters in parallel and with many additional
configuration features. The service is like many other great platforms
free for open source projects.
The actual runner golangci-lint (8) is also open source and can be used
locally as well in any private CI/CD pipelines. In order to use it for
snowsaw, a `.golangci.yml` configuration file has been added and the
runner will be executed through the `lint` Mage task.

>>> Cross-Compilation

Go comes with all necessary tools to cross-compile out-of-the-box,
but instead of running the commands manually gox (9) is used to also
simplify this task as well as running and managing the compilation in
parallel. To create distributions with and without binary artifact
optimizations new Mage tasks have also been implemented.

>>> Formatting

To adhere to the Go code styleguide and conventions the official
goimports (10) tool is used and executed through the dedicated `format`
Mage task.

>>> Testing

Go comes with all necessary testing tools out-of-the-box that are used
through Mage tasks where a distinction is made between unit and
integration tests as well as with and without coverage profiling.
The coverage reports can be used later on to integrate services like
CodeCov (11) into snowsaw's CI/CD pipeline.

References:
  (1) https://github.com/magefile/mage
  (2) https://www.jetbrains.com/help/idea/using-file-watchers.html
  (3) https://www.jetbrains.com/idea
  (4) https://plugins.jetbrains.com/plugin/7177-file-watchers
  (5) https://plugins.jetbrains.com/plugin/9568-go
  (6) https://www.jetbrains.com/go
  (7) https://golangci.com
  (8) https://github.com/golangci/golangci-lint
  (9) https://github.com/mitchellh/gox
  (10) https://godoc.org/golang.org/x/tools/cmd/goimports
  (11) https://codecov.io

Epic GH-33
Depends on GH-58
Resolves GH-62
@arcticicestudio
Copy link
Owner Author

Resolved in 1622134

@arcticicestudio arcticicestudio removed their assignment Jun 29, 2019
arcticicestudio added a commit that referenced this issue Jul 20, 2019
The problems in the code base detected by the linters that have been
integrated in GH-62 through GolangCI have been handled by refactoring
the affected implementations.
This helps to improve the overall code quality and prevents possible
errors.

1. Removed unused function parameters detected by unparam (1).
   1. `(*cmdOptions).prepare` - `cmd` is unused:
      cmd/snowsaw/bootstrap/bootstrap.go:51:30 (2)
      ```go
      func (o *cmdOptions) prepare(cmd *cobra.Command, args []string) {
                                   ^
      ```
   2. `(*cmdOptions).run` - `cmd` is unused:
      cmd/snowsaw/bootstrap/bootstrap.go:100:26 (2)
      ```go
      func (o *cmdOptions) run(cmd *cobra.Command, args []string) {
                               ^
      ```
   3. `(*cmdOptions).run` - `args` is unused:
      cmd/snowsaw/bootstrap/bootstrap.go:100:46 (2)
      ```go
      func (o *cmdOptions) run(cmd *cobra.Command, args []string) {
                                                   ^
      ```
2. Improved function names and code flows detected by golint (3).
   1. func `NewJsonEncoder` should be `NewJSONEncoder`:
      pkg/config/encoder/json/json.go:34:6 (4)
      ```go
      func NewJsonEncoder() Encoder {
           ^
      ```
   2. var `ExtensionsJson` should be `ExtensionsJSON`:
   pkg/config/encoder/constants.go:26:2 (5)
      ```go
      ExtensionsJson = "json"
      ^
      ```
   3. if block ends with a return statement, so drop this else and
      outdent its block (move short variable declaration to its own line
      if necessary): pkg/prt/printer.go:121:9 (6)
      ```go
      } else {
             ^
      ```
   4. exported func Load returns unexported type *builder.builder, which
      can be annoying to use: pkg/config/builder/builder.go:39:32 (7)
      ```go
      func Load(files ...*file.File) *builder {
                                     ^
      ```
3. Improved code style smells detected by gocritic (8).
   1. assignOp: replace `format = format + "\n"` with `format += "\n"`:
   pkg/prt/printer.go:179:4 (9)
      ```go
      format = format + "\n"
      ^
      ```
   2. paramTypeCombine: `func(v Verbosity, w io.Writer, prefix string,
      format string, args ...interface{})` could be replaced with
      `func(v Verbosity, w io.Writer, prefix, format string, args
      ...interface{})`: pkg/prt/printer.go:176:1 (10)
      ```go
      func (p *printerConfig) withNewLine(v Verbosity, w io.Writer,
      ^
      prefix string, format string, args ...interface{}) {
      ```
   3. emptyStringTest: replace `len(parts[0]) == 0` with `parts[0] ==
      ""`: pkg/snowblock/task/shell/shell.go:165:5 (11)
      ```go
      if len(parts[0]) == 0 {
         ^
      ```
   4. elseif: can replace 'else {if cond {}}' with 'else if cond {}':
   cmd/snowsaw/bootstrap/bootstrap.go:57:9 (12)
      ```go
      } else {
             ^
      ```
4. Remove unnecessary type conversions detected by unconvert (13).
   1. unnecessary conversion: pkg/prt/printer.go:132:16 (14)
      ```go
      *v = Verbosity(l)
                    ^
      ```

References:
  (1) https://github.com/mvdan/unparam
  (2) https://github.com/arcticicestudio/snowsaw/blob/9366c4a9c6d59dd0fccad12fbc413842ea751fa6/cmd/snowsaw/bootstrap/bootstrap.go#L51
  (3) https://github.com/golang/lint
  (4) https://github.com/arcticicestudio/snowsaw/blob/5aa483e7e5e45888254aa4d0143d2afb898b4332/pkg/config/encoder/json/json.go#L34
  (5) https://github.com/arcticicestudio/snowsaw/blob/008edbcb509af2cb5ced942d679fa3845a4ec1e1/pkg/config/encoder/constants.go#L26
  (6) https://github.com/arcticicestudio/snowsaw/blob/79afc12ebc15620fd94e78416e0b49a68bbf2eb6/pkg/prt/printer.go#L121
  (7) https://github.com/arcticicestudio/snowsaw/blob/dea6ab56b7410a8cbc8901818703d5ab1ace5c87/pkg/config/builder/builder.go#L39
  (8) https://github.com/go-critic/go-critic
  (9) https://github.com/arcticicestudio/snowsaw/blob/79afc12ebc15620fd94e78416e0b49a68bbf2eb6/pkg/prt/printer.go#L179
  (10) https://github.com/arcticicestudio/snowsaw/blob/79afc12ebc15620fd94e78416e0b49a68bbf2eb6/pkg/prt/printer.go#L176
  (11) https://github.com/arcticicestudio/snowsaw/blob/a78810b7ccb5ddb8e80929d54fb7c461a1b80a1c/pkg/snowblock/task/shell/shell.go#L165
  (12) https://github.com/arcticicestudio/snowsaw/blob/9366c4a9c6d59dd0fccad12fbc413842ea751fa6/cmd/snowsaw/bootstrap/bootstrap.go#L57
  (13) https://github.com/mdempsky/unconvert
  (14) https://github.com/arcticicestudio/snowsaw/blob/79afc12ebc15620fd94e78416e0b49a68bbf2eb6/pkg/prt/printer.go#L132

Epic: GH-33
Resolves GH-80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant