1- JSONNET_FMT := jsonnetfmt -n 2 --max-blank-lines 2 --string-style s --comment-style s
1+ SHELL =/usr/bin/env bash -o pipefail
2+ BIN_DIR ?= $(shell pwd) /tmp/bin
3+
4+ EMBEDMD ?= $(BIN_DIR ) /embedmd
5+ GOJSONTOYAML ?= $(BIN_DIR ) /gojsontoyaml
6+ JSONNET ?= $(BIN_DIR ) /jsonnet
7+ JSONNET_BUNDLER ?= $(BIN_DIR ) /jb
8+ JSONNET_FMT ?= $(BIN_DIR ) /jsonnetfmt
9+ JSONNET_SRC = $(shell find . -name 'vendor' -prune -o -name 'jsonnet/vendor' -prune -o -name 'tmp' -prune -o -name '* .libsonnet' -print -o -name '* .jsonnet' -print)
10+ JSONNET_FMT_CMD := $(JSONNET_FMT ) -n 2 --max-blank-lines 2 --string-style s --comment-style s
211
312CONTAINER_CMD: =docker run --rm \
413 -u="$(shell id -u) :$(shell id -g) " \
@@ -9,6 +18,9 @@ CONTAINER_CMD:=docker run --rm \
918 -e GO111MODULE=on \
1019 quay.io/coreos/jsonnet-ci
1120
21+ EXAMPLES := examples
22+ MANIFESTS := manifests
23+
1224all : generate fmt
1325
1426.PHONY : generate-in-docker
@@ -17,28 +29,48 @@ generate-in-docker:
1729 $(CONTAINER_CMD ) make $(MFLAGS ) generate
1830
1931.PHONY : generate
20- generate : manifests ** .md
21-
22- **.md : $(shell find examples) build.sh example.jsonnet
23- embedmd -w ` find . -name " *.md" | grep -v vendor`
32+ generate : vendor ${MANIFESTS} ** .md
2433
25- manifests : vendor example.jsonnet build.sh
26- rm -rf manifests
27- ./build.sh
34+ **.md : $(EMBEDMD ) $(shell find ${EXAMPLES}) build.sh example.jsonnet
35+ $(EMBEDMD ) -w ` find . -name " *.md" | grep -v vendor`
2836
29- jb :
30- curl -L -o jb " https://github.com/jsonnet-bundler/jsonnet-bundler/releases/download/v0.2.0/jb-$( shell go env GOOS) -$( shell go env GOARCH) "
31- chmod +x jb
32-
33- vendor : jb jsonnetfile.json jsonnetfile.lock.json
34- rm -rf vendor
35- ./jb install
37+ .PHONY : ${MANIFESTS}
38+ ${MANIFESTS} : $(JSONNET ) $(GOJSONTOYAML ) vendor example.jsonnet build.sh
39+ @rm -rf ${MANIFESTS}
40+ @mkdir -p ${MANIFESTS}
41+ PATH=$$ PATH:$$(pwd ) /$(BIN_DIR ) ./build.sh
3642
3743.PHONY : fmt
38- fmt :
39- find . -name ' vendor' -prune -o -name ' *.libsonnet' -print -o -name ' *.jsonnet' -print | \
40- xargs -n 1 -- $(JSONNET_FMT ) -i
44+ fmt : $(JSONNET_FMT )
45+ PATH=$$ PATH:$$(pwd ) /$(BIN_DIR ) echo ${JSONNET_SRC} | xargs -n 1 -- $(JSONNET_FMT_CMD ) -i
46+
47+ vendor : | $(JSONNET_BUNDLER ) jsonnetfile.json jsonnetfile.lock.json
48+ $(JSONNET_BUNDLER ) install
4149
4250.PHONY : clean
4351clean :
52+ -rm -rf tmp/bin
4453 rm -rf manifests/
54+
55+ $(BIN_DIR ) :
56+ mkdir -p $(BIN_DIR )
57+
58+ $(EMBEDMD ) : $(BIN_DIR )
59+ go get -d github.com/campoy/embedmd
60+ go build -o $@ github.com/campoy/embedmd
61+
62+ $(GOJSONTOYAML ) : $(BIN_DIR )
63+ go get -d github.com/brancz/gojsontoyaml
64+ go build -o $@ github.com/brancz/gojsontoyaml
65+
66+ $(JSONNET ) : $(BIN_DIR )
67+ go get -d github.com/google/go-jsonnet/cmd/jsonnet
68+ go build -o $@ github.com/google/go-jsonnet/cmd/jsonnet
69+
70+ $(JSONNET_FMT ) : $(BIN_DIR )
71+ go get -d github.com/google/go-jsonnet/cmd/jsonnetfmt
72+ go build -o $@ github.com/google/go-jsonnet/cmd/jsonnetfmt
73+
74+ $(JSONNET_BUNDLER ) : $(BIN_DIR )
75+ curl -L -o $(JSONNET_BUNDLER ) " https://github.com/jsonnet-bundler/jsonnet-bundler/releases/download/v0.2.0/jb-$( shell go env GOOS) -$( shell go env GOARCH) "
76+ chmod +x $(JSONNET_BUNDLER )
0 commit comments