Skip to content

Commit 310d274

Browse files
committed
feat: allow Makefile to install swagger if missing
1 parent df2023f commit 310d274

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

Makefile

+36-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ build:
88

99
clean-generate: remove-generated generate
1010

11-
generate: specs/swagger-stripped-oauth.json
12-
swagger generate client --skip-validation -f $^ -t falcon
11+
generate: swagger-cli specs/swagger-stripped-oauth.json
12+
$(SWAGGER) generate client --skip-validation -f $^ -t falcon
1313

1414
.PHONY: build generate remove-generated
1515

@@ -27,3 +27,37 @@ specs/swagger-patched.json: specs/swagger.json ./specs/transformation.jq
2727
specs/swagger.json:
2828
@echo "Sorry swagger.json needs to be obtained manually at this moment"
2929
@exit 1
30+
31+
##@ Dependencies
32+
33+
## Location to install dependencies to
34+
LOCALBIN ?= $(shell pwd)/bin
35+
$(LOCALBIN):
36+
mkdir -p $(LOCALBIN)
37+
38+
## Tool Binaries
39+
SWAGGER = $(LOCALBIN)/swagger
40+
41+
## Tool Versions
42+
SWAGGER_VERSION ?= v0.31.0
43+
44+
.PHONY: swagger-cli
45+
swagger-cli: $(SWAGGER) ## Download swagger locally if necessary.
46+
$(SWAGGER): $(LOCALBIN)
47+
$(call go-install-tool,$(SWAGGER),github.com/go-swagger/go-swagger/cmd/swagger,$(SWAGGER_VERSION))
48+
49+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
50+
# $1 - target path with name of binary
51+
# $2 - package url which can be installed
52+
# $3 - specific version of package
53+
define go-install-tool
54+
@[ -f "$(1)-$(3)" ] || { \
55+
set -e; \
56+
package=$(2)@$(3) ;\
57+
echo "Downloading $${package}" ;\
58+
rm -f $(1) || true ;\
59+
GOBIN=$(LOCALBIN) go install $${package} ;\
60+
mv $(1) $(1)-$(3) ;\
61+
} ;\
62+
ln -sf $(1)-$(3) $(1)
63+
endef

0 commit comments

Comments
 (0)