Skip to content

Commit

Permalink
Use new go jsonnet formatter (#2258)
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun authored Mar 13, 2020
1 parent 8a67462 commit c0418a2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ MISSPELL ?= $(GOBIN)/misspell-$(MISSPELL_VERSION)
GOJSONTOYAML_VERSION ?= e8bd32d46b3d764bef60f12b3bada1c132c4be55
GOJSONTOYAML ?= $(GOBIN)/gojsontoyaml-$(GOJSONTOYAML_VERSION)
# v0.14.0
JSONNET_VERSION ?= fbde25be2182caa4345b03f1532450911ac7d1f3
JSONNET_VERSION ?= 724650d358b67909a7bea00ea443e23afc3d2a17
JSONNET ?= $(GOBIN)/jsonnet-$(JSONNET_VERSION)
JSONNETFMT ?= $(GOBIN)/jsonnetfmt-$(JSONNET_VERSION)
JSONNET_BUNDLER_VERSION ?= efe0c9e864431e93d5c3376bd5931d0fb9b2a296
JSONNET_BUNDLER ?= $(GOBIN)/jb-$(JSONNET_BUNDLER_VERSION)
# Prometheus v2.14.0
Expand Down Expand Up @@ -371,19 +372,17 @@ jsonnet-vendor: $(JSONNET_BUNDLER) $(MIXIN_ROOT)/jsonnetfile.json $(MIXIN_ROOT)/
rm -rf ${JSONNET_VENDOR_DIR}
cd ${MIXIN_ROOT} && $(JSONNET_BUNDLER) install

JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s
JSONNETFMT_CMD := $(JSONNETFMT) -n 2 --max-blank-lines 2 --string-style s --comment-style s

.PHONY: jsonnet-format
jsonnet-format:
@which jsonnetfmt 2>&1 >/dev/null || ( \
echo "Cannot find jsonnetfmt command, please install from https://github.com/google/jsonnet/releases.\nIf your C++ does not support GLIBCXX_3.4.20, please use xxx-in-container target like jsonnet-format-in-container." \
&& exit 1)
jsonnet-format: $(JSONNETFMT)
find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
xargs -n 1 -- $(JSONNET_FMT) -i
xargs -n 1 -- $(JSONNETFMT_CMD) -i

.PHONY: jsonnet-format-in-container
jsonnet-format-in-container:
$(JSONNET_CONTAINER_CMD) make $(MFLAGS) jsonnet-format
$(JSONNET_CONTAINER_CMD) find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
xargs -n 1 -- jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s -i

.PHONY: example-rules-lint
example-rules-lint: $(PROMTOOL) examples/alerts/alerts.yaml examples/alerts/rules.yaml
Expand Down Expand Up @@ -447,6 +446,9 @@ $(PROTOC):
$(JSONNET):
$(call fetch_go_bin_version,github.com/google/go-jsonnet/cmd/jsonnet,$(JSONNET_VERSION))

$(JSONNETFMT):
$(call fetch_go_bin_version,github.com/google/go-jsonnet/cmd/jsonnetfmt,$(JSONNET_VERSION))

$(GOJSONTOYAML):
$(call fetch_go_bin_version,github.com/brancz/gojsontoyaml,$(GOJSONTOYAML_VERSION))

Expand Down

0 comments on commit c0418a2

Please sign in to comment.