Browse Source

chore: Add makefile and use in `gitlab-ci.yml`

Gives an easy possibility to execute the same commands as in the pipeline.
tablepad
Andreas Bieber 9 months ago
parent
commit
474a8c1a27
2 changed files with 50 additions and 4 deletions
  1. +3
    -4
      .gitlab-ci.yml
  2. +47
    -0
      Makefile

+ 3
- 4
.gitlab-ci.yml View File

@ -7,15 +7,14 @@ stages:
fmt:
stage: validate
script:
- gofmt -l -s -e .
- exit $(gofmt -l -s -e . | wc -l)
- make check-fmt
vet:
stage: validate
script:
- go vet -composites=false ./...
- make vet
test:
stage: validate
script:
- go test -race -v ./...
- make test

+ 47
- 0
Makefile View File

@ -0,0 +1,47 @@
# kernel-style V=1 build verbosity
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE = $(V)
endif
ifeq ($(BUILD_VERBOSE),1)
Q =
else
Q = @
endif
define go_get
$(Q)command -v $(1) > /dev/null || GO111MODULE=off go get $(2)
endef
export CGO_ENABLED := 1
.DEFAULT_GOAL := help
.PHONY: validate
validate: check-fmt test vet ## Validates the go code format, runs tests and executes vet.
.PHONY: test
test: ## Run tests
$(Q)echo "running tests..."
$(Q)go test -race -v ./...
.PHONY: vet
vet: ## Run go vet
$(Q)echo "running go vet..."
$(Q)go vet -composites=false ./...
.PHONY: check-fmt
check-fmt: ## Check go format
$(Q)echo "checking format..."
@gofmt_out=$$(gofmt -d -e . 2>&1) && [ -z "$${gofmt_out}" ] || (echo "$${gofmt_out}" 1>&2; exit 1)
.PHONY: fmt
fmt: ## Formats the go code
$(Q)echo "formatting go code..."
$(Q)set -e
$(call go_get,goimports,golang.org/x/tools/cmd/goimports)
$(Q)goimports -w .
.PHONY: help
help: ## Shows this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

Loading…
Cancel
Save