From 7de80ad6581d5d499ee840d311cbcfaa5e7ce717 Mon Sep 17 00:00:00 2001 From: Oleg Kozyrev Date: Wed, 26 Jul 2023 10:16:30 +0300 Subject: [PATCH] add workflow upd. versions fix add module fix fix fix f f f f --- .github/workflows/go.yaml | 67 +++++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ .golangci.pipeline.yaml | 53 +++++++++++++++++++++++++++++++ Makefile | 7 ++++ cmd/main.go | 11 +++++++ go.mod | 10 ++++++ go.sum | 10 ++++++ 7 files changed, 160 insertions(+) create mode 100644 .github/workflows/go.yaml create mode 100644 .gitignore create mode 100755 .golangci.pipeline.yaml create mode 100644 Makefile create mode 100644 cmd/main.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml new file mode 100644 index 00000000..868873e2 --- /dev/null +++ b/.github/workflows/go.yaml @@ -0,0 +1,67 @@ +name: Go + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + cache-dependency-path: go.sum + + - name: Build + run: go build -o ./bin/ -v ./... + + - name: Test + run: go test -v ./... + + linter: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '1.20' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Require: The version of golangci-lint to use. + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. + version: v1.53 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # + # Note: By default, the `.golangci.yml` file should be at the root of the repository. + # The location of the configuration file can be changed by using `--config=` + args: --timeout=30m --config=./.golangci.pipeline.yaml --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true, then all caching functionality will be completely disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. + # skip-build-cache: true + + # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. + # install-mode: "goinstall" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..28a280c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +/bin/ diff --git a/.golangci.pipeline.yaml b/.golangci.pipeline.yaml new file mode 100755 index 00000000..7f0f5d5f --- /dev/null +++ b/.golangci.pipeline.yaml @@ -0,0 +1,53 @@ +# More info on config here: https://golangci-lint.run/usage/configuration/#config-file +run: + concurrency: 8 + timeout: 10m + issues-exit-code: 1 + tests: true + skip-dirs: + - bin + - vendor + - var + - tmp + - .cache + skip-files: + - \.pb\.go$ + - \.pb\.gw\.go$ + +output: + format: colored-line-number + print-issued-lines: true + print-linter-name: true + +linters-settings: + govet: + check-shadowing: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + +linters: + disable-all: true + enable: + # - dupl - it's very slow, enable if you really know why you need it + - errcheck + - goconst + - goimports + - gosec + - govet + - ineffassign + - megacheck # (staticcheck + gosimple + unused in one linter) + - revive + - typecheck + - unused # will be used insted of varcheck + deadcode + structcheck. More info https://github.com/golangci/golangci-lint/issues/1841 + +issues: + exclude-use-default: false + exclude: + # _ instead of err checks + - G104 + - exported func .* returns unexported type .*, which can be annoying to use + - should have a package comment + - don't use an underscore in package name diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..9cbd9f1c --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +LOCAL_BIN:=$(CURDIR)/bin + +install-golangci-lint: + GOBIN=$(LOCAL_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3 + +lint: + GOBIN=$(LOCAL_BIN) golangci-lint run ./... --config .golangci.pipeline.yaml \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 00000000..f48b4405 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + + "github.com/fatih/color" +) + +func main() { + fmt.Println(color.GreenString("Hello, world!")) +} diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..cef66f45 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/olezhek28/microservices_course_boilerplate + +go 1.20 + +require ( + github.com/fatih/color v1.15.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect + golang.org/x/sys v0.6.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..2624c9db --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=