Skip to content

Commit

Permalink
Initial Makefile (#54)
Browse files Browse the repository at this point in the history
* Initial Makefile

* Create Makefile for Go project
 - Run 'make help' to see the targets.

* Tools as dependencies
  - Introduce tools as dependencies
     Install golang-ci and mispell via tools pkg (tools.go).
     It is running via main.go (as part of go generate).
     This is triggered via 'make setup'.
  - Minor fixes in the Makefile
  - Run `go mod tidy` to replace the indirect modules of golang-ci
    and mispell

Fixes #33
Fixes #20

Co-authored-by: Panagiotis Georgiadis <drpaneas@gmail.com>

* Fix Makefile to work with gmake

Co-authored-by: Panagiotis Georgiadis <drpaneas@gmail.com>
Co-authored-by: Panagiotis Georgiadis <pgeorgia@redhat.com>
  • Loading branch information
3 people committed Oct 8, 2020
1 parent 4e90d4f commit 2dd2b52
Show file tree
Hide file tree
Showing 7 changed files with 713 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode/
coverage.txt
romie
16 changes: 16 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
tests: true

linters:
enable-all: true
disable:
- gomnd
- gocognit
- goerr113
- gofumpt
- gci
- nlreturn
73 changes: 73 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Global variables used later
NAME=romie
GOCMD=LC_ALL=C go
TIMEOUT=5

# go tools
export PATH := ./bin:$(PATH)
export GO111MODULE := on
export GOPROXY = https://proxy.golang.org,direct

# go source files
SRC = $(shell find . -type f -name '*.go')
# The name of the executable (default is current directory name)
TARGET := $(shell echo $${PWD-`pwd`})

.PHONY: all build setup fmt test cover lint ci clean todo run help

## all: Default target, now is build
all: build

## build: Builds the binary
build:
@echo "Building..."
@$(GOCMD) build -o ${NAME}

## setup: Runs mod download and generate
setup:
@echo "Downloading tools and dependencies..."
@$(GOCMD) mod download
@$(GOCMD) generate -v ./...

## fmt: Runs go goimports and go fmt
fmt: setup
@echo "Checking the imports..."
@$(GOCMD)imports -w ${SRC}
@echo "Formating the go files..."
@$(GOCMD)fmt -w -s ${SRC}

## test: Runs the tests with coverage
test:
@echo "Running tests..."
@$(GOCMD) test -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt ./... -run . -timeout $(TIMEOUT)m

## cover: Runs all tests and opens the coverage report in the browser
cover: test
@$(GOCMD) tool cover -html=coverage.txt

## lint: Runs golangci-lint (configuration at .golangci.yml) and misspell
lint: setup
@echo "Running linters..."
@golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 ./...
@misspell ./...

## ci: Runs steup build, test, fmt, lint
ci: setup build test fmt lint

## clean: Runs go clean
clean:
@echo "Cleaning..."
@$(GOCMD) clean

## todo: Shows all TODO strings with line numbers
todo:
@grep -I -R -n TODO * --exclude=Makefile

## run: Runs go run
run: build
@$(GOCMD) run ${TARGET}

## help: Prints this help message
help:
@echo "Usage:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module github.com/drpaneas/romie
module romie

go 1.15

require (
github.com/client9/misspell v0.3.4
github.com/golangci/golangci-lint v1.31.0
golang.org/x/tools v0.0.0-20201001230009-b5b87423c93b // indirect
)
602 changes: 602 additions & 0 deletions go.sum

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//go:generate go install github.com/golangci/golangci-lint/cmd/golangci-lint
//go:generate go install github.com/client9/misspell/cmd/misspell

package main

func main() {
Expand Down
10 changes: 10 additions & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build tools

package tools

import (
// Import golangci-lint
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
// Import misspell
_ "github.com/client9/misspell/cmd/misspell"
)

0 comments on commit 2dd2b52

Please sign in to comment.