Skip to content

Commit

Permalink
chore: add tools.go and gobin (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerman authored Nov 6, 2020
1 parent 92d998f commit 18be7a1
Show file tree
Hide file tree
Showing 18 changed files with 420 additions and 61 deletions.
28 changes: 8 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ setup_env: &setup_env
command: |
env | sort > /tmp/env.old
export DOCKERIZE_VER=0.12.0
export HADOLINT_VER=1.18.0
export SHELLCHECK_VER=0.7.1
export GOLANGCI_LINT_VER=1.31.0
export GOTESTSUM_VER=0.5.3
export GOSWAGGER_VER=0.25.0
export GOVERALLS_VER=0.0.7
env | sort > /tmp/env.new
! diff -u /tmp/env.old /tmp/env.new | sed -n '/^+[^+]/s/^./export /p' >> $BASH_ENV
Expand Down Expand Up @@ -45,28 +40,19 @@ jobs:
- *setup_env
- restore_cache:
keys:
- v1-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-{{ .Branch }}
- v1-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-
- v1-{{ checksum "/tmp/tools.ver" }}-
- v2-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-{{ .Branch }}
- v2-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-
- v2-{{ checksum "/tmp/tools.ver" }}-
- run:
name: Install tools
environment:
GO111MODULE: "on"
command: |
cd /tmp # Protect go.mod for modifications by `go get`.
dockerize --version | tee /dev/stderr | grep -wq v$DOCKERIZE_VER ||
curl -sSfL https://github.com/powerman/dockerize/releases/download/v${DOCKERIZE_VER}/dockerize-$(uname)-x86_64 | install /dev/stdin $(go env GOPATH)/bin/dockerize
GO111MODULE=off go get -u github.com/myitcv/gobin
hadolint --version | tee /dev/stderr | grep -wq v$HADOLINT_VER ||
curl -sSfL https://github.com/hadolint/hadolint/releases/download/v${HADOLINT_VER}/hadolint-$(uname)-x86_64 | install /dev/stdin $(go env GOPATH)/bin/hadolint
shellcheck --version | tee /dev/stderr | grep -wq $SHELLCHECK_VER ||
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VER}/shellcheck-v${SHELLCHECK_VER}.$(uname).x86_64.tar.xz | tar xJf - -C $(go env GOPATH)/bin --strip-components=1 shellcheck-v${SHELLCHECK_VER}/shellcheck
golangci-lint version | tee /dev/stderr | grep -wq $GOLANGCI_LINT_VER ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v$GOLANGCI_LINT_VER
gotestsum --version | tee /dev/stderr | grep -wq $GOTESTSUM_VER ||
curl -sSfL https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VER}/gotestsum_${GOTESTSUM_VER}_linux_amd64.tar.gz | tar xzf - -C $(go env GOPATH)/bin gotestsum
swagger version | tee /dev/stderr | grep -wq v$GOSWAGGER_VER ||
curl -sSfL https://github.com/go-swagger/go-swagger/releases/download/v${GOSWAGGER_VER}/swagger_$(uname)_amd64 | install /dev/stdin $(go env GOPATH)/bin/swagger
go get github.com/mattn/goveralls@v${GOVERALLS_VER}
- run:
name: Ensure API spec match auto-generated code
command: |
Expand All @@ -77,16 +63,18 @@ jobs:
name: Report code coverage
command: |
scripts/cover
# goveralls -coverprofile=cover.out -service=CircleCI
# gobin -m -run github.com/mattn/goveralls -coverprofile=cover.out -service=CircleCI
- save_cache:
when: always
key: v1-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-{{ .Branch }}
key: v2-{{ checksum "/tmp/tools.ver" }}-{{ checksum "go.mod" }}-{{ .Branch }}
paths:
- ~/go/bin/
- ~/go/pkg/
- ~/go/src/
- ~/.cache/go-build/
- ~/.cache/golangci-lint/
- ~/.cache/gobin/
- .gobincache/

workflows:
default:
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# na/**/me - apply (* doesn't match /) to file "na/me", "na/*/me", "na/*/*/me", …
go.sum binary
*.*.go binary
/third_party/*/** binary
/api/**/model/** binary
/api/**/restapi/** binary
/api/**/restapi/configure_*.go -binary
Expand Down
24 changes: 6 additions & 18 deletions .github/workflows/CI&CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ jobs:
ports:
- 3306:3306
env:
DOCKERIZE_VER: '0.12.0'
HADOLINT_VER: '1.18.0'
SHELLCHECK_VER: '0.7.1'
GOLANGCI_LINT_VER: '1.31.0'
GOTESTSUM_VER: '0.5.3'
GOSWAGGER_VER: '0.25.0'
GOVERALLS_VER: '0.0.7'
EXAMPLE_APIKEY_ADMIN: 'admin'
EXAMPLE_MYSQL_ADDR_HOST: 'localhost'
EXAMPLE_MYSQL_AUTH_LOGIN: 'root'
Expand All @@ -55,28 +50,21 @@ jobs:
~/go/src
~/.cache/go-build
~/.cache/golangci-lint
key: v1-test-${{ runner.os }}-${{ hashFiles('/tmp/tools.ver') }}-${{ hashFiles('go.mod') }}
~/.cache/gobin
.gobincache
key: v2-test-${{ runner.os }}-${{ hashFiles('/tmp/tools.ver') }}-${{ hashFiles('go.mod') }}
restore-keys: |
v1-test-${{ runner.os }}-${{ hashFiles('/tmp/tools.ver') }}-
v2-test-${{ runner.os }}-${{ hashFiles('/tmp/tools.ver') }}-
- name: Install tools
env:
GO111MODULE: 'on'
run: |
cd /tmp # Protect go.mod for modifications by `go get`.
dockerize --version | tee /dev/stderr | grep -wq v$DOCKERIZE_VER ||
curl -sSfL https://github.com/powerman/dockerize/releases/download/v${DOCKERIZE_VER}/dockerize-$(uname)-x86_64 | install /dev/stdin $(go env GOPATH)/bin/dockerize
GO111MODULE=off go get -u github.com/myitcv/gobin
hadolint --version | tee /dev/stderr | grep -wq v$HADOLINT_VER ||
curl -sSfL https://github.com/hadolint/hadolint/releases/download/v${HADOLINT_VER}/hadolint-$(uname)-x86_64 | install /dev/stdin $(go env GOPATH)/bin/hadolint
shellcheck --version | tee /dev/stderr | grep -wq $SHELLCHECK_VER ||
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VER}/shellcheck-v${SHELLCHECK_VER}.$(uname).x86_64.tar.xz | tar xJf - -C $(go env GOPATH)/bin --strip-components=1 shellcheck-v${SHELLCHECK_VER}/shellcheck
golangci-lint version | tee /dev/stderr | grep -wq $GOLANGCI_LINT_VER ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v$GOLANGCI_LINT_VER
gotestsum --version | tee /dev/stderr | grep -wq $GOTESTSUM_VER ||
curl -sSfL https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VER}/gotestsum_${GOTESTSUM_VER}_linux_amd64.tar.gz | tar xzf - -C $(go env GOPATH)/bin gotestsum
swagger version | tee /dev/stderr | grep -wq v$GOSWAGGER_VER ||
curl -sSfL https://github.com/go-swagger/go-swagger/releases/download/v${GOSWAGGER_VER}/swagger_$(uname)_amd64 | install /dev/stdin $(go env GOPATH)/bin/swagger
go get github.com/mattn/goveralls@v${GOVERALLS_VER}
- name: Ensure API spec match auto-generated code
run: |
Expand All @@ -91,7 +79,7 @@ jobs:
if: env.COVERALLS_TOKEN
run: |
scripts/cover
goveralls -coverprofile=cover.out -service=GitHub
gobin -m -run github.com/mattn/goveralls -coverprofile=cover.out -service=GitHub
build-and-release:
needs: test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# na/**/me - exclude path (* doesn't match /) to file/dir "na/me", "na/*/me", "na/*/*/me", …
# !name - include previously excluded path …
/.circleci/config-local.yml
/.gobincache/
/bin/
/env.sh
/cover.out
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ linters-settings:
# see https://github.com/kisielk/errcheck#excluding-functions for details
#exclude: .errcheck.excludes
exhaustive:
# check switch statements in generated files also
check-generated: false
# indicates that switch statements are to be considered exhaustive if a
# 'default' case is present, even if all enum members aren't listed in the
# switch
Expand Down Expand Up @@ -345,6 +347,9 @@ linters-settings:
# Choose whether or not to use the extra rules that are disabled
# by default
extra-rules: false
errorlint:
# Report non-wrapping error creation using fmt.Errorf
errorf: true

# The custom section can be used to define linter plugins to be loaded at runtime. See README doc
# for more info.
Expand All @@ -366,10 +371,12 @@ linters:
disable:
- dogsled # questionable
- dupl
- exhaustivestruct
- lll
- maligned # premature optimization
- nlreturn
- prealloc
- wrapcheck # enable after implementing https://github.com/tomarrell/wrapcheck/issues/1
- wsl # questionable
#disable-all: false
#presets:
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ adapters":
- `internal/app` - define interfaces ("ports") and implements business-logic
- `internal/srv/*` - adapters for served APIs/UI
- `internal/dal/*` - adapters for data storage
- `internal/migrations/*` - DB migrations (in both SQL and Go)
- `internal/svc/*` - adapters for accessing external services
- `pkg/*` - helper packages, not related to architecture and
business-logic (may be later moved to own modules and/or replaced by
Expand Down Expand Up @@ -111,17 +112,12 @@ adapters":
- [Docker Compose](https://docs.docker.com/compose/install/) 1.25+
- Tools used to build/test project (feel free to install these tools using
your OS package manager or any other way, but please ensure they've
required versions; also note these commands will install some non-Go
tools into `$GOPATH/bin` for the sake of simplicity):
required versions):

```sh
curl -sSfL https://github.com/hadolint/hadolint/releases/download/v1.18.0/hadolint-$(uname)-x86_64 | install /dev/stdin $(go env GOPATH)/bin/hadolint
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.$(uname).x86_64.tar.xz | tar xJf - -C $(go env GOPATH)/bin --strip-components=1 shellcheck-v0.7.1/shellcheck
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0
go get gotest.tools/gotestsum@v0.5.3
go get github.com/golang/mock/mockgen@v1.4.4
go get github.com/cheekybits/genny@master
curl -sSfL https://github.com/go-swagger/go-swagger/releases/download/v0.25.0/swagger_$(uname)_amd64 | install /dev/stdin $(go env GOPATH)/bin/swagger
GO111MODULE=off go get -u github.com/myitcv/gobin
curl -sSfL https://github.com/hadolint/hadolint/releases/download/v1.18.0/hadolint-$(uname)-x86_64 | sudo install /dev/stdin /usr/local/bin/hadolint
curl -sSfL https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.$(uname).x86_64.tar.xz | sudo tar xJf - -C /usr/local/bin --strip-components=1 shellcheck-v0.7.1/shellcheck
```

### Setup
Expand Down
4 changes: 2 additions & 2 deletions api/openapi/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
package api

//go:generate rm -rf model restapi client
//go:generate swagger generate server --api-package op --model-package model --strict-responders --strict-additional-properties --keep-spec-order --principal github.com/powerman/go-service-example/internal/app.Auth --exclude-main
//go:generate swagger generate client --api-package op --model-package model --strict-responders --strict-additional-properties --keep-spec-order --principal github.com/powerman/go-service-example/internal/app.Auth
//go:generate gobin -m -run github.com/go-swagger/go-swagger/cmd/swagger generate server --api-package op --model-package model --strict-responders --strict-additional-properties --keep-spec-order --principal github.com/powerman/go-service-example/internal/app.Auth --exclude-main
//go:generate gobin -m -run github.com/go-swagger/go-swagger/cmd/swagger generate client --api-package op --model-package model --strict-responders --strict-additional-properties --keep-spec-order --principal github.com/powerman/go-service-example/internal/app.Auth
//go:generate find restapi -maxdepth 1 -name "configure_*.go" -exec sed -i -e "/go:generate/d" {} ;
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/powerman/go-service-example
go 1.15

require (
github.com/cheekybits/genny v1.0.1-0.20200709201058-3e22f1a88ff2
github.com/felixge/httpsnoop v1.0.1
github.com/go-openapi/errors v0.19.8
github.com/go-openapi/loads v0.19.5
Expand All @@ -12,11 +13,15 @@ require (
github.com/go-openapi/swag v0.19.11
github.com/go-openapi/validate v0.19.12
github.com/go-sql-driver/mysql v1.5.0
github.com/go-swagger/go-swagger v0.25.0
github.com/golang/mock v1.4.4
github.com/golangci/golangci-lint v1.32.2
github.com/jessevdk/go-flags v1.4.0
github.com/jmoiron/sqlx v1.2.0
github.com/jmoiron/sqlx v1.2.1-0.20190826204134-d7d95172beb5
github.com/mattn/goveralls v0.0.7
github.com/powerman/appcfg v0.5.0
github.com/powerman/check v1.2.1
github.com/powerman/check v1.3.0
github.com/powerman/dockerize v0.12.0
github.com/powerman/getenv v0.1.0
github.com/powerman/goose/v2 v2.7.0
github.com/powerman/must v0.1.0
Expand All @@ -31,4 +36,5 @@ require (
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102
gotest.tools/gotestsum v0.6.0
)
Loading

0 comments on commit 18be7a1

Please sign in to comment.