forked from goharbor/xk6-harbor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
106 lines (79 loc) · 2.79 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
IMG ?= heww/k6
GOLANG=golang:1.15.6
SHELL := /bin/bash
GIT_HASH := $(shell git rev-parse --short=8 HEAD)
BUILDPATH=$(CURDIR)
BIN ?= $(CURDIR)/bin
$(BIN):
mkdir -p "$(BIN)"
DOCKERCMD=$(shell which docker)
SWAGGER_IMAGENAME := quay.io/goswagger/swagger
SWAGGER_VERSION := 0.27.0
SWAGGER=$(DOCKERCMD) run --rm -u $(shell id -u):$(shell id -g) -v $(BUILDPATH):$(BUILDPATH) -w $(BUILDPATH) ${SWAGGER_IMAGENAME}:v${SWAGGER_VERSION}
generate-client:
- rm -rf pkg/harbor/{models,client}
$(SWAGGER) generate client -f pkg/harbor/swagger.yaml --target pkg/harbor --template=stratoscale --additional-initialism=CVE --additional-initialism=GC --additional-initialism=OIDC
GOMODIFYTAGS_IMAGENAME := quay.io/heww/gomodifytags
GOMODIFYTAGS_VERSION := 1.13.0
GOMODIFYTAGS=$(DOCKERCMD) run --rm -u $(shell id -u):$(shell id -g) -v $(BUILDPATH):$(BUILDPATH) -w $(BUILDPATH) ${GOMODIFYTAGS_IMAGENAME}:v${GOMODIFYTAGS_VERSION}
modify-tags:
@for f in $(shell ls pkg/harbor/models/*.go); \
do $(GOMODIFYTAGS) -file $${f} -all -add-tags js -transform camelcase --skip-unexported -w ; \
done
@for f in $(shell ls pkg/harbor/client/*/*_parameters.go); \
do $(GOMODIFYTAGS) -file $${f} -all -add-tags js -transform camelcase --skip-unexported -w ; \
done
go-generate: generate-client modify-tags
.PHONY: k6
k6:
CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-w' -i -o k6 ./cmd/k6/main.go
build: k6
docker-build: build
@echo "Beginning build $(GIT_HASH)"
docker build --build-arg GOLANG=$(GOLANG) -f docker/Dockerfile -t $(IMG):$(GIT_HASH) .
docker tag $(IMG):$(GIT_HASH) $(IMG):latest
.PHONY: test
test:
go test ./...
# Run go fmt against code
.PHONY: fmt
fmt:
go fmt ./...
# Run go vet against code
.PHONY: vet
vet:
go vet ./...
# find or download golangci-lint
# download golangci-lint if necessary
GOLANGCI_LINT := $(BIN)/golangci-lint
GOLANGCI_LINT_VERSION := 1.36.0
.PHONY: golangci-lint
golangci-lint:
@$(GOLANGCI_LINT) version --format short 2>&1 \
| grep '$(GOLANGCI_LINT_VERSION)' > /dev/null \
|| rm -f $(GOLANGCI_LINT)
@$(MAKE) $(GOLANGCI_LINT)
$(GOLANGCI_LINT):
$(MAKE) $(BIN)
# https://golangci-lint.run/usage/install/#linux-and-windows
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
| sh -s -- -b $(BIN) 'v$(GOLANGCI_LINT_VERSION)'
# Run go linters
.PHONY: go-lint
go-lint: golangci-lint vet go-generate
$(GOLANGCI_LINT) run --verbose --max-same-issues 0 --sort-results -D wrapcheck -D exhaustivestruct -D errorlint -D goerr113 -D gomnd -D nestif -D funlen -D gosec
clean:
- rm -rf $(BIN)
.PHONY: generate
generate: go-generate
.PHONY: go-dependencies-test
go-dependencies-test: fmt
go mod tidy
$(MAKE) diff
.PHONY: generated-diff-test
generated-diff-test: fmt generate
$(MAKE) diff
.PHONY: diff
diff:
git status
git diff --diff-filter=d --exit-code HEAD