-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
71 lines (56 loc) · 2.22 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
## Docker Build Versions
GOLANG_VERSION := $(shell cat go.mod | grep "^go " | cut -d " " -f 2)
DOCKER_BUILD_IMAGE = golang:$(GOLANG_VERSION)
# Hardcode base image to alpine sha for verson 3.16.3
DOCKER_BASE_IMAGE = alpine@sha256:3d426b0bfc361d6e8303f51459f17782b219dece42a1c7fe463b6014b189c86d
MATTERWICK_IMAGE ?= mattermost/matterwick:test
GO ?= $(shell command -v go 2> /dev/null)
DEP ?= $(shell command -v dep 2> /dev/null)
PACKAGES=$(shell go list ./...)
TOOLS_BIN_DIR := $(abspath bin)
GO_INSTALL = ./scripts/go_install.sh
GOFLAGS ?= $(GOFLAGS:)
GOLINT_VER := master
GOLINT_BIN := golint
GOLINT_GEN := $(TOOLS_BIN_DIR)/$(GOLINT_BIN)
## Checks the code style, tests, builds and bundles the plugin.
.PHONY: all
all: check-style test
## Runs govet and gofmt against all packages.
.PHONY: check-style
check-style: lint vet
@echo Checking for style guide compliance
.PHONY: build
build:
@echo Building
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build -gcflags all=-trimpath=$(PWD) -asmflags -a -installsuffix cgo -o build/_output/bin/matterwick
.PHONY: build-image
build-image: ## Build the docker image for matterwick
@echo Building matterwick Image
docker build \
--build-arg DOCKER_BUILD_IMAGE=$(DOCKER_BUILD_IMAGE) \
--build-arg DOCKER_BASE_IMAGE=$(DOCKER_BASE_IMAGE) \
. -f Dockerfile -t $(MATTERWICK_IMAGE) \
--no-cache
## Runs lint against all packages.
.PHONY: lint
lint: $(GOLINT_GEN)
@echo Running lint
$(GOLINT_GEN) -set_exit_status $(PACKAGES)
@echo lint success
## Runs govet against all packages.
.PHONY: vet
vet:
@echo Running govet
$(GO) vet $(GOFLAGS) $(PACKAGES)
@echo Govet success
## Runs tests. For local usage, run `make test CONFIG_TEST="-config=config-matterwick.test-local.json"`
test:
@echo Running Go tests
$(GO) test $(PACKAGES) $(CONFIG_TEST)
@echo test success
$(GOLINT_GEN): ## Build golint.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) golang.org/x/lint/golint $(GOLINT_BIN) $(GOLINT_VER)
# Help documentation à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@cat Makefile | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z_.-]+:.*' | sed -e "s/:.*//" | sed -e "s/^## //" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort