-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathMakefile
144 lines (121 loc) · 4.47 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
# Copyright 2025 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include Makefile.tools
VERSION := 0.16.3
SHORT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
GO_VERSION := $(shell go version | awk '{ print $$3}' | sed 's/^go//')
FMT_OPTIONS := -x '**/testdata' -x site/themes -x '.vscode/*' -x dist -x 'internal/*' -x '.github/*' -t jsonnet -t json -t yaml
LEARN_THEME_TAG := 2.2.0
# When modifying this, also modify the corresponding ldflags in .goreleaser.yaml
LD_FLAGS_PKG ?= github.com/splunk/qbec/internal/commands
LD_FLAGS :=
LD_FLAGS += -X "$(LD_FLAGS_PKG).version=$(VERSION)"
LD_FLAGS += -X "$(LD_FLAGS_PKG).commit=$(SHORT_COMMIT)"
LD_FLAGS += -X "$(LD_FLAGS_PKG).goVersion=$(GO_VERSION)"
LINT_FLAGS ?=
TEST_FLAGS ?=
export GO111MODULE=on
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
.DEFAULT_GOAL := all
.PHONY: all
all: build lint test
.PHONY: get
get:
go get ./...
.PHONY: build
build:
go install -ldflags '$(LD_FLAGS)' ./...
.PHONY: test
test:
go test $(TEST_FLAGS) -coverprofile=coverage.txt -covermode=atomic -race ./...
.PHONY: generate
generate:
go run ./cmd/gen-qbec-swagger internal/model/swagger.yaml internal/model/swagger-schema.go
.PHONY: lint
lint: check-format
go vet ./...
golint ./...
golangci-lint run $(LINT_FLAGS) .
./licenselint.sh
.PHONY: fmt-license
fmt-license:
addlicense -c "Splunk Inc." -l apache $$(find . -type f ! -path "*testdata*" -print0 | xargs -0)
.PHONY: check-license
check-license:
addlicense -c "Splunk Inc." -l apache -check $$(find . -type f ! -path "*testdata*" ! -path "*examples*.yaml" -print0 | xargs -0)
.PHONY: check-format
check-format: build
@echo "Running qbec fmt -e ..."
qbec fmt -e $(FMT_OPTIONS)
@echo "Running gofmt..."
$(eval unformatted=$(shell find . -name '*.go' | grep -v ./.git | grep -v vendor | xargs gofmt -s -l))
$(if $(strip $(unformatted)),\
$(error $(\n) Some files are ill formatted! Run: \
$(foreach file,$(unformatted),$(\n) gofmt -s -w $(file))$(\n)),\
@echo All files are well formatted.\
)
.PHONY: fmt
fmt: build
@echo "Running qbec fmt -w ..."
qbec fmt -w $(FMT_OPTIONS)
.PHONY: install-ci
install-ci: HELM_VERSION := 3.3.1
install-ci: HELM_PLATFORM := $(shell uname| tr '[:upper:]' '[:lower:]')
install-ci:
# Refactor helm install into a separate step
# curl -sSL -o helm.tar.gz https://get.helm.sh/helm-v${HELM_VERSION}-${HELM_PLATFORM}-amd64.tar.gz
# tar -xvzf helm.tar.gz
# mv ${HELM_PLATFORM}-amd64/helm $(GOPATH)/bin/
go install github.com/golangci/golangci-lint/cmd/[email protected]
.PHONY: create-cluster
create-cluster: .tools/kind
.tools/kind create cluster
.PHONY: install
install:
go install golang.org/x/lint/[email protected]
go install github.com/google/[email protected]
@echo for building docs, manually install hugo for your OS from: https://github.com/gohugoio/hugo/releases
.PHONY: site
site:
cd site && rm -rf themes/
mkdir -p site/themes
git clone https://github.com/matcornic/hugo-theme-learn site/themes/learn
(cd site/themes/learn && git checkout -q $(LEARN_THEME_TAG) && rm -rf exampleSite && rm -f images/* && rm -f CHANGELOG.md netlify.toml wercker.yaml .grenrc.yml)
cd site && hugo
.PHONY: clean
clean:
rm -rf vendor/
rm -rf site/themes
rm -rf site/public
.PHONY: os_archive
os_archive:
@echo build O/S archive for: $(GOOS)-$(GOARCH)
rm -rf dist/tmp
mkdir -p dist/tmp
mkdir -p dist/assets
ifeq ($(GOOS), windows)
go build -ldflags '$(LD_FLAGS)' -o dist/tmp/qbec.exe .
go build -ldflags '$(LD_FLAGS)' -o dist/tmp/jsonnet-qbec.exe ./cmd/jsonnet-qbec
(cd dist/tmp && zip ../assets/qbec-$(GOOS)-$(GOARCH).zip *)
else
go build -ldflags '$(LD_FLAGS)' -o dist/tmp/qbec .
go build -ldflags '$(LD_FLAGS)' -o dist/tmp/jsonnet-qbec ./cmd/jsonnet-qbec
(cd dist/tmp && tar -czf ../assets/qbec-$(GOOS)-$(GOARCH).tar.gz *)
endif
rm -rf dist/tmp
.PHONY: release-notes
release-notes:
go test cmd/changelog-extractor/*.go
go run cmd/changelog-extractor/main.go CHANGELOG.md > .release-notes.md