-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
110 lines (87 loc) · 2.87 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
GO ?= go
GOFMT ?= gofmt
DOCKER ?= docker
PACKAGES ?= $(shell go list ./... | \
grep -v '\(vendor\|mock\|test\)' | \
tr '\n' ,)
DOCFILES := $(wildcard docs/*_api.yml)
ROOTDIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
DOCKERTAG ?= $(shell git rev-parse --abbrev-ref HEAD)
DOCKERTESTTAG ?= prtest
DOCKERIMAGE ?= mendersoftware/deviceconfig
GOFILES := $(shell find . -name "*.go" -type f -not -path './vendor/*')
SRCFILES := $(filter-out _test.go,$(GOFILES))
BINFILE := bin/deviceconfig
COVERFILE := coverage.txt
.PHONY: build
build: $(BINFILE)
.PHONY: all
all: fmt lint docs build
tests/%: docs/%.yml
[ -e $@ ] && rm -r $@; \
docker run --rm -t -v $(ROOTDIR):$(ROOTDIR) -w $(ROOTDIR) \
-u $(shell id -u):$(shell id -g) \
openapitools/openapi-generator-cli:v4.3.1 generate \
-g python -i $< \
-c tests/.openapi-generator.yml \
-o $(dir $@) \
--additional-properties=packageName=$*
$(BINFILE): $(SRCFILES)
$(GO) build -o $@ .
$(BINFILE).test: $(GOFILES)
go test -c -tags main -o $(BINFILE).test \
-cover -covermode atomic \
-coverpkg $(PACKAGES)
$(COVERFILE): $(GOFILES)
$(GO) test -cover -covermode=atomic -coverprofile=$@ ${TEST_FLAGS} ./...
.PHONY: docs
docs: $(patsubst docs/%.yml,tests/%,$(DOCFILES))
.PHONY: build-test
build-test: $(BINFILE).test
.PHONY: test
test: $(COVERFILE)
# Dockerfile targets
bin/deviceconfig.docker: Dockerfile $(SRCFILES)
docker rmi $(DOCKERIMAGE):$(DOCKERTAG) 2>/dev/null; \
docker build . -f Dockerfile -t $(DOCKERIMAGE):$(DOCKERTAG)
docker save $(DOCKERIMAGE):$(DOCKERTAG) -o $@
bin/deviceconfig.acceptance.docker: Dockerfile.acceptance $(GOFILES)
docker rmi $(DOCKERIMAGE):$(DOCKERTESTTAG) 2>/dev/null; \
docker build . -f Dockerfile.acceptance -t $(DOCKERIMAGE):$(DOCKERTESTTAG)
docker save $(DOCKERIMAGE):$(DOCKERTESTTAG) -o $@
.PHONY: docker
docker: bin/deviceconfig.docker
.PHONY: docker-test
docker-test: bin/deviceconfig.acceptance.docker
.PHONY: acceptance-tests-run
acceptance-tests-run: docker-test docs
docker-compose \
-p acceptance \
-f tests/docker-compose.yml \
run tester
.PHONY: acceptance-tests-logs
acceptance-tests-logs: acceptance-tests-run
for service in $(shell docker-compose -f tests/docker-compose.yml -p acceptance ps -a --services); do \
docker-compose -p acceptance -f tests/docker-compose.yml \
logs --no-color $$service > "tests/acceptance.$${service}.logs"; \
done
.PHONY: acceptance-tests-down
acceptance-tests-down:
docker-compose \
-f tests/docker-compose.yml \
-p acceptance down --remove-orphans
.PHONY: acceptance-tests
acceptance-tests: acceptance-tests-logs acceptance-tests-down
.PHONY: fmt
fmt:
$(GOFMT) -s -w $(GOFILES)
.PHONY: lint
lint:
golangci-lint run -v
.PHONY: clean
clean:
$(GO) clean -modcache -x -i ./...
find . -name coverage.txt -delete
rm -f tests/acceptance.*.logs tests/results.xml \
tests/coverage-acceptance.txt coverage.txt
rm -f bin/*