-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
154 lines (112 loc) · 5.28 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
export CGO_ENABLED=0
export GO111MODULE=on
LDFLAGS := -w -s
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_SHA = $(shell git rev-parse --short HEAD)
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
GOTESTSUM = $(shell which gotestsum || echo "~/go/bin/gotestsum")
ifdef VERSION
BINARY_VERSION = $(VERSION)
endif
BINARY_VERSION ?= ${GIT_TAG}
# Only set Version if building a tag or VERSION is set
ifneq ($(BINARY_VERSION),)
LDFLAGS += -X github.com/kosli-dev/cli/internal/version.version=${BINARY_VERSION}
endif
VERSION_METADATA = unreleased
# Clear the "unreleased" string in BuildMetadata
ifneq ($(GIT_TAG),)
VERSION_METADATA =
endif
LDFLAGS += -X github.com/kosli-dev/cli/internal/version.metadata=${VERSION_METADATA}
LDFLAGS += -X github.com/kosli-dev/cli/internal/version.gitCommit=${GIT_COMMIT}
LDFLAGS += -X github.com/kosli-dev/cli/internal/version.gitTreeState=${GIT_DIRTY}
LDFLAGS += -extldflags "-static"
ldflags:
@echo $(LDFLAGS)
fmt: ## Reformat package sources
@go fmt ./...
lint:
@docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --timeout=5m -v ./...
vet: fmt
@go vet ./...
deps: ## Install depdendencies. Runs `go get` internally.
@GOFLAGS="" go mod download
@GOFLAGS="" go mod tidy
build: deps vet ## Build the binary
@go build -o kosli -ldflags '$(LDFLAGS)' ./cmd/kosli/
check_dirty:
@git diff-index --quiet HEAD -- || echo "Cannot test release with dirty git repo"
@git diff-index --quiet HEAD --
add_test_tag:
@git tag -d v0.0.99 2> /dev/null || true
@git tag v0.0.99
build_release: check_dirty add_test_tag
rm -rf dist/
goreleaser release --skip-publish --debug
@git tag -d v0.0.99 2> /dev/null || true
ensure_network:
docker network inspect cli_net > /dev/null || docker network create --driver bridge cli_net
ensure_gotestsum:
@go install gotest.tools/gotestsum@latest
test_setup: ensure_gotestsum
./bin/reset-or-start-server.sh
test_setup_restart_server: ensure_gotestsum
./bin/reset-or-start-server.sh force
test_integration: deps vet ensure_network test_setup ## Run tests except the too slow ones
@[ -e ~/.kosli.yml ] && mv ~/.kosli.yml ~/.kosli-renamed.yml || true
@export KOSLI_TESTS=true && $(GOTESTSUM) -- --short -p=8 -coverprofile=cover.out ./...
@go tool cover -func=cover.out | grep total:
@go tool cover -html=cover.out
@[ -e ~/.kosli-renamed.yml ] && mv ~/.kosli-renamed.yml ~/.kosli.yml || true
test_integration_full: deps vet ensure_network test_setup ## Run all tests
@[ -e ~/.kosli.yml ] && mv ~/.kosli.yml ~/.kosli-renamed.yml || true
@export KOSLI_TESTS=true && $(GOTESTSUM) --junitfile junit.xml -- -p=8 -coverprofile=cover.out ./...
@go tool cover -func=cover.out
@[ -e ~/.kosli-renamed.yml ] && mv ~/.kosli-renamed.yml ~/.kosli.yml || true
test_integration_restart_server: test_setup_restart_server
@[ -e ~/.kosli.yml ] && mv ~/.kosli.yml ~/.kosli-renamed.yml || true
@export KOSLI_TESTS=true && $(GOTESTSUM) -- --short -p=8 -coverprofile=cover.out ./...
@go tool cover -html=cover.out
@[ -e ~/.kosli-renamed.yml ] && mv ~/.kosli-renamed.yml ~/.kosli.yml || true
test_integration_single: test_setup
@export KOSLI_TESTS=true && $(GOTESTSUM) -- -p=1 ./... -run "${TARGET}"
test_docs: deps vet ensure_network test_setup
./bin/test_docs_cmds.sh docs.kosli.com/content/use_cases/simulating_a_devops_system/_index.md
docker:
@docker build -t kosli-cli .
cli-docs: build
@rm -f docs.kosli.com/content/client_reference/kosli*
@export DOCS=true && ./kosli docs --dir docs.kosli.com/content/client_reference
legacy-ref-docs:
@./hack/generate-old-versions-docs.sh "v2.*"
licenses:
@rm -rf licenses || true
@go install github.com/google/go-licenses@latest
@go-licenses save ./... --save_path="licenses/" || true
$(eval DATA := $(shell go-licenses csv ./...))
@echo $(DATA) | tr " " "\n" > licenses/licenses.csv
upgrade-deps:
@go get -u ./...
generate-json-metadata:
echo '{"currentversion": "vlocal"}' > docs.kosli.com/assets/metadata.json
hugo: cli-docs helm-docs generate-json-metadata
cd docs.kosli.com && hugo server --minify --buildDrafts --port=1515
hugo-local: cli-docs generate-json-metadata
cd docs.kosli.com && hugo server --minify --buildDrafts --port=1515
helm-lint:
@cd charts/k8s-reporter && helm lint .
helm-docs: helm-lint
@cd charts/k8s-reporter && docker run --rm --volume "$(PWD):/helm-docs" jnorwood/helm-docs:latest --template-files README.md.gotmpl,_templates.gotmpl --output-file README.md
@cd charts/k8s-reporter && docker run --rm --volume "$(PWD):/helm-docs" jnorwood/helm-docs:latest --template-files README.md.gotmpl,_templates.gotmpl --output-file ../../docs.kosli.com/content/helm/_index.md
release:
@git remote update
@git status -uno | grep --silent "Your branch is up to date" || (echo "ERROR: your branch is NOT up to date with remote" && return 1)
git tag -a $(tag) -m"$(tag)"
git push origin $(tag)
# check-links:
# @docker run -v ${PWD}:/tmp:ro --rm -i --entrypoint '' ghcr.io/tcort/markdown-link-check:stable /bin/sh -c 'find /tmp/docs.kosli.com/content -name \*.md -print0 | xargs -0 -n1 markdown-link-check -q -c /tmp/link-checker-config.json'
check-links:
@cd docs.kosli.com && hugo --minify
@docker run -v ${PWD}:/test --rm wjdp/htmltest -c .htmltest.yml -l 1