forked from mittwald/goharbor-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
89 lines (65 loc) · 2.7 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
.PHONY: generate swagger-generate swagger-cleanup mock-generate mock-cleanup setup-harbor-v1 setup-harbor-v2 \
harbor-teardown test integration-test-v1-ci integration-test-v2-ci integration-test-v1 integration-test-v2 \
fmt gofmt gofumpt goimports lint uninstall-harbor-v2 uninstall-harbor-v1
V1_VERSION = v1.10.18
V2_VERSION = v2.9.1
MOCKERY_VERSION = v2.14.0
GOSWAGGER_VERSION = v0.25.0
GOLANGCI_LINT_VERSION = v1.50.1
# Run all code generation targets
generate: swagger-generate mock-generate
# Run go-swagger code generation
swagger-generate: swagger-cleanup
scripts/swagger-gen.sh $(V1_VERSION) $(GOSWAGGER_VERSION)
scripts/swagger-gen.sh $(V2_VERSION) $(GOSWAGGER_VERSION)
# Delete all auto-generated API files
swagger-cleanup:
rm -rf ./apiv*/internal ./apiv*/model/
# Run mockery
mock-generate: mock-cleanup
scripts/gen-mock.sh v1 $(MOCKERY_VERSION)
scripts/gen-mock.sh v2 $(MOCKERY_VERSION)
# Delete all auto-generated mock files
mock-cleanup:
rm -rf ./apiv*/mocks/*
# Create a Harbor instance as a docker container via Kind.
# Delete cluster via scripts/teardown-harbor.sh
setup-harbor-v1:
scripts/setup-harbor.sh $(V1_VERSION)
setup-harbor-v2:
scripts/setup-harbor.sh $(V2_VERSION)
uninstall-harbor-v2:
kind delete clusters "goharbor-client-integration-tests-$(V2_VERSION)"
uninstall-harbor-v1:
kind delete clusters "goharbor-client-integration-tests-$(V1_VERSION)"
test:
go test -v ./... -tags !integration
INTEGRATION_V1 = CGO_ENABLED=0 go test -p 1 -count 1 -v github.com/mittwald/goharbor-client/v5/apiv1/... -tags integration
INTEGRATION_V2 = CGO_ENABLED=0 go test -p 1 -count 1 -v github.com/mittwald/goharbor-client/v5/apiv2/... -tags integration
# Integration testing (CI Jobs)
integration-test-v1-ci: setup-harbor-v1 integration-test-v1
integration-test-v2-ci: setup-harbor-v2 integration-test-v2
# Integration testing (local execution)
integration-test-v1:
$(INTEGRATION_V1)
integration-test-v2: upload-test-image
$(INTEGRATION_V2)
upload-test-image:
@echo Building and uploading test image
docker login -u admin -p Harbor12345 core.harbor.domain
docker build -t core.harbor.domain/library/image:test ./testdata
docker push core.harbor.domain/library/image:test
# Exclude auto-generated code to be formatted by gofmt, gofumpt & goimports.
FIND=find . \( -path "./apiv*/internal" -o -path "./apiv*/mocks" -o -path "./apiv*/model" \) -prune -false -o -name '*.go'
fmt: gofmt gofumpt goimports tidy
tidy:
go mod tidy
gofmt:
$(FIND) -exec gofmt -l -w {} \;
gofumpt:
$(FIND) -exec gofumpt -w {} \;
goimports:
$(FIND) -exec goimports -w {} \;
lint:
docker run --rm -v $(shell pwd):/goharbor-client -w /goharbor-client/. \
golangci/golangci-lint:${GOLANGCI_LINT_VERSION} golangci-lint run --sort-results