add linter and make file (#2)
This commit is contained in:
60
Makefile
Normal file
60
Makefile
Normal file
@ -0,0 +1,60 @@
|
||||
# project variables
|
||||
PROJECT_NAME := mullvad-best-server
|
||||
|
||||
# build variables
|
||||
.DEFAULT_GOAL = lint
|
||||
BUILD_DIR := dist
|
||||
DEV_GOARCH := $(shell go env GOARCH)
|
||||
DEV_GOOS := $(shell go env GOOS)
|
||||
|
||||
|
||||
## tools: Install required tooling.
|
||||
.PHONY: tools
|
||||
tools:
|
||||
ifeq (,$(wildcard ./.bin/golangci-lint*))
|
||||
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b .bin/ v1.44.2
|
||||
else
|
||||
@echo "==> Required tooling is already installed"
|
||||
endif
|
||||
|
||||
## clean: Delete the build directory
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@echo "==> Removing '$(BUILD_DIR)' directory..."
|
||||
@rm -rf $(BUILD_DIR)
|
||||
|
||||
## lint: Lint code with golangci-lint.
|
||||
.PHONY: lint
|
||||
lint: tools
|
||||
@echo "==> Linting code with 'golangci-lint'..."
|
||||
@.bin/golangci-lint run ./...
|
||||
|
||||
## test: Run all unit tests.
|
||||
.PHONY: test
|
||||
test:
|
||||
@echo "==> Running unit tests..."
|
||||
@mkdir -p $(BUILD_DIR)
|
||||
@go test -count=1 -v -cover -coverprofile=$(BUILD_DIR)/coverage.out -parallel=4 ./...
|
||||
|
||||
## build: Build binary for default local system's OS and architecture.
|
||||
.PHONY: build
|
||||
build:
|
||||
@echo "==> Building binary..."
|
||||
@echo " running go build for GOOS=$(DEV_GOOS) GOARCH=$(DEV_GOARCH)"
|
||||
# workaround for missing .exe extension on Windows
|
||||
ifeq ($(OS),Windows_NT)
|
||||
@go build -o $(BUILD_DIR)/$(PROJECT_NAME).$(DEV_GOOS).$(DEV_GOARCH).exe
|
||||
else
|
||||
@go build -o $(BUILD_DIR)/$(PROJECT_NAME).$(DEV_GOOS).$(DEV_GOARCH)
|
||||
endif
|
||||
|
||||
.PHONY: run
|
||||
run:
|
||||
@echo "==> Running $(PROJECT_NAME)"
|
||||
@go run main.go
|
||||
|
||||
help: Makefile
|
||||
@echo "Usage: make <command>"
|
||||
@echo ""
|
||||
@echo "Commands:"
|
||||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
|
Reference in New Issue
Block a user