Skip to content

Commit

Permalink
update: Improve makefile commands and fix lint
Browse files Browse the repository at this point in the history
Improved the makefile for making the development more easy and fixed
the issue returned by linter.
Added the contributing file.
  • Loading branch information
faabiosr committed May 19, 2018
1 parent cba0f38 commit 5f29a19
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 30 deletions.
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
66 changes: 66 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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.
54 changes: 42 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Sqlite3TestSuite struct {
}

var (
cacheTable string = "cache"
dbPath string = "./cache.db"
cacheTable = "cache"
dbPath = "./cache.db"
)

func (s *Sqlite3TestSuite) SetupTest() {
Expand Down

0 comments on commit 5f29a19

Please sign in to comment.