From 5f29a1968b3e26dc72a839b873f23dd11603b60f Mon Sep 17 00:00:00 2001 From: Fabio Ribeiro Date: Sat, 19 May 2018 11:08:19 -0300 Subject: [PATCH] update: Improve makefile commands and fix lint Improved the makefile for making the development more easy and fixed the issue returned by linter. Added the contributing file. --- .travis.yml | 11 +++------ CONTRIBUTING.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 54 +++++++++++++++++++++++++++++++--------- README.md | 30 +++++++++++++++------- sqlite3_test.go | 4 +-- 5 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/.travis.yml b/.travis.yml index f4c71c3..e8ed231 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,18 +11,15 @@ services: - redis-server - mongodb -env: - - DEP_VERSION="0.4.1" - before_install: - - curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o $GOPATH/bin/dep - - chmod +x $GOPATH/bin/dep - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi install: - - dep ensure + - make depend + - make configure script: - - $HOME/gopath/bin/goveralls -service=travis-ci + - make lint + - $HOME/gopath/bin/goveralls -service=travis-ci diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..8f9da7e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,66 @@ +# Contributing + +By participating to this project, you agree to abide our [code of conduct](/CODE_OF_CONDUCT.md). + +## Setup your machine + +`cachego` is written in [Go](https://golang.org/). + +Prerequisites: + +* `make` +* [Go 1.8+](https://golang.org/doc/install) + +Clone `cachego` from source into `$GOPATH`: + +```sh +$ mkdir -p $GOPATH/src/github.com/fabiorphp +$ cd $_ +$ git clone git@github.com:fabiorphp/cachego.git +$ cd cachego +``` + +Install the build and lint dependencies: +```console +$ make depend +``` + +A good way of making sure everything is all right is running the test suite: +```console +$ make test +``` + +## Formatting the code +Format the code running: +```console +$ make fmt +``` + +## Create a commit + +Commit messages should be well formatted. +Start your commit message with the type. Choose one of the following: +`feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`, `revert`, `add`, `remove`, `move`, `bump`, `update`, `release` + +After a colon, you should give the message a title, starting with uppercase and ending without a dot. +Keep the width of the text at 72 chars. +The title must be followed with a newline, then a more detailed description. + +Please reference any GitHub issues on the last line of the commit message (e.g. `See #123`, `Closes #123`, `Fixes #123`). + +An example: + +``` +docs: Add example for --release-notes flag + +I added an example to the docs of the `--release-notes` flag to make +the usage more clear. The example is an realistic use case and might +help others to generate their own changelog. + +See #284 +``` + +## Submit a pull request + +Push your branch to your `cachego` fork and open a pull request against the +master branch. diff --git a/Makefile b/Makefile index 985fa99..838fc8f 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,49 @@ -.PHONY: clean configure test test-coverage - .DEFAULT_GOAL := test +# Clean up clean: - @rm -fR vendor/ cover.* - @docker-compose stop - @docker-compose rm -f + rm -fR ./vendor/ ./cover.* +.PHONY: clean +# Download dependencies configure: - @dep ensure -v - @docker-compose up -d + dep ensure -v +.PHONY: configure -test: - @go test -v . +# Run tests and generates html coverage file +cover: test + go tool cover -html=./cover.out -o ./cover.html +.PHONY: cover + +# Download dependencies +depend: + go get -u gopkg.in/alecthomas/gometalinter.v2 + gometalinter.v2 --install + go get -u github.com/golang/dep/... +.PHONY: depend + +# Up the docker container for testing +docker: + docker-compose up -d +.PHONY: docker -test-coverage: - @go test -coverprofile=cover.out -v . - @go tool cover -html=cover.out -o cover.html +# Format all go files +fmt: + gofmt -s -w -l $(shell go list -f {{.Dir}} ./... | grep -v /vendor/) +.PHONY: fmt + +# Run linters +lint: + gometalinter.v2 \ + --vendor \ + --disable-all \ + --enable=golint \ + --enable=gofmt \ + --enable=misspell \ + --enable=vet ./... +.PHONY: lint + +# Run tests +test: + go test -v -race -coverprofile=./cover.out $(shell go list ./... | grep -v /vendor/) +.PHONY: test diff --git a/README.md b/README.md index 7a32078..ed9e9e5 100644 --- a/README.md +++ b/README.md @@ -208,19 +208,31 @@ Read the full documentation at [https://godoc.org/github.com/fabiorphp/cachego]( - Install [docker](https://docs.docker.com/install/) and [docker-compose](https://docs.docker.com/compose/install/) - Install [go dep](https://github.com/golang/dep) -### Run tests +### Makefile ```sh -// tests -$ make test - -// test with coverage -$ make test-coverage - -// clean-up +// Clean up $ make clean -// configure (download dependencies and run docker containers) +// Creates folders and download dependencies $ make configure + +//Run tests and generates html coverage file +make cover + +// Download project dependencies +make depend + +// Up the docker containers for testing +make docker + +// Format all go files +make fmt + +//Run linters +make lint + +// Run tests +make test ``` ## License diff --git a/sqlite3_test.go b/sqlite3_test.go index f2c2828..91e0994 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -20,8 +20,8 @@ type Sqlite3TestSuite struct { } var ( - cacheTable string = "cache" - dbPath string = "./cache.db" + cacheTable = "cache" + dbPath = "./cache.db" ) func (s *Sqlite3TestSuite) SetupTest() {