Skip to content

Commit 684606d

Browse files
committed
Add Makefile
This makefile is ported over from directxman12/k8s-prometheus-adapter, and adds make targets to populate vendor, build the sample adapter, run tests, and run/verify gofmt.
1 parent 42c5886 commit 684606d

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*.swp
22
*~
3-
sample-main
43
vendor
4+
_output

Makefile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARCH?=amd64
2+
OUT_DIR?=./_output
3+
4+
.PHONY: all test verify-gofmt gofmt verify
5+
6+
all: build
7+
build: vendor
8+
CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -tags netgo -o $(OUT_DIR)/$(ARCH)/sample-adapter github.com/directxman12/custom-metrics-boilerplate
9+
10+
vendor: glide.lock
11+
glide install -v
12+
13+
test: vendor
14+
CGO_ENABLED=0 go test ./pkg/...
15+
16+
verify-gofmt:
17+
./hack/gofmt-all.sh -v
18+
19+
gofmt:
20+
./hack/gofmt-all.sh
21+
22+
verify: verify-gofmt test

hack/gofmt-all.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
verify=0
22+
if [[ ${1:-} = "--verify" || ${1:-} = "-v" ]]; then
23+
verify=1
24+
fi
25+
26+
find_files() {
27+
find . -not \( \( \
28+
-wholename './_output' \
29+
-o -wholename './vendor' \
30+
\) -prune \) -name '*.go'
31+
}
32+
33+
if [[ $verify -eq 1 ]]; then
34+
diff=$(find_files | xargs gofmt -s -d 2>&1)
35+
if [[ -n "${diff}" ]]; then
36+
echo "gofmt -s -w $(echo "${diff}" | awk '/^diff / { print $2 }' | tr '\n' ' ')"
37+
exit 1
38+
fi
39+
else
40+
find_files | xargs gofmt -s -w
41+
fi

0 commit comments

Comments
 (0)