Skip to content

Commit

Permalink
add features to sync swagger doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun committed Nov 20, 2019
1 parent 64cf204 commit 18d8b0b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
BINDIR ?= $(GOPATH)/bin
CORE_PACK := $(shell go list -m github.com/terra-project/core | sed 's/ /\@/g')

export GO111MODULE = on
Expand Down Expand Up @@ -93,6 +94,15 @@ install: go.sum
install-debug: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/terradebug

update-swagger-docs: statik
$(BINDIR)/statik -src=client/lcd/swagger-ui -dest=client/lcd -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
exit 1;\
else \
echo "\033[92mSwagger docs are in sync\033[0m";\
fi
.PHONY: update-swagger-docs


########################################
Expand Down
38 changes: 22 additions & 16 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
###
ifeq ($(OS),Windows_NT)
GO := $(shell where go.exe 2> NUL)
FS := \\
FS := "\\"
else
GO := $(shell command -v go 2> /dev/null)
FS := /
FS := "/"
endif

ifeq ($(GO),)
Expand All @@ -17,8 +17,7 @@ endif

GOPATH ?= $(shell $(GO) env GOPATH)
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com
GOLANGCI_LINT_VERSION := v1.17.1
GOLANGCI_LINT_HASHSUM := f5fa647a12f658924d9f7d6b9628d505ab118e8e049e43272de6526053ebe08d
GOLANGCI_LINT_HASHSUM := 8d21cc95da8d3daf8321ac40091456fc26123c964d7c2281d339d431f2f4c840

###
# Functions
Expand All @@ -33,8 +32,6 @@ mkdir -p $(GITHUBDIR)$(FS)$(1) &&\
)\
cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && git fetch origin && git checkout -q $(3)

go_install = $(call go_get,$(1),$(2),$(3)) && cd $(GITHUBDIR)$(FS)$(1)$(FS)$(2) && $(GO) install

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)

Expand All @@ -43,33 +40,42 @@ mkfile_dir := $(shell cd $(shell dirname $(mkfile_path)); pwd)
###

TOOLS_DESTDIR ?= $(GOPATH)/bin
GOLANGCI_LINT = $(TOOLS_DESTDIR)/golangci-lint
RUNSIM = $(TOOLS_DESTDIR)/runsim

GOLANGCI_LINT = $(TOOLS_DESTDIR)/golangci-lint
STATIK = $(TOOLS_DESTDIR)/statik
RUNSIM = $(TOOLS_DESTDIR)/runsim

all: tools

tools: tools-stamp
tools-stamp: $(GOIMPORTS) $(RUNSIM)
touch $@
tools: statik runsim golangci-lint

golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(mkfile_dir)/install-golangci-lint.sh
@echo "Installing golangci-lint..."
@bash $(mkfile_dir)/install-golangci-lint.sh $(TOOLS_DESTDIR) $(GOLANGCI_LINT_VERSION) $(GOLANGCI_LINT_HASHSUM)
@bash $(mkfile_dir)/install-golangci-lint.sh $(TOOLS_DESTDIR) $(GOLANGCI_LINT_HASHSUM)

# Install the runsim binary with a temporary workaround of entering an outside
# directory as the "go get" command ignores the -mod option and will polute the
# go.{mod, sum} files.
#
# ref: https://github.com/golang/go/issues/30515
statik: $(STATIK)
$(STATIK):
@echo "Installing statik..."
@(cd /tmp && go get github.com/rakyll/[email protected])

# Install the runsim binary with a temporary workaround of entering an outside
# directory as the "go get" command ignores the -mod option and will polute the
# go.{mod, sum} files.
#
# ref: https://github.com/golang/go/issues/30515
runsim: $(RUNSIM)
$(RUNSIM):
@echo "Installing runsim..."
@(cd /tmp && go get github.com/cosmos/tools/cmd/[email protected])

golangci-lint: $(GOLANGCI_LINT)

tools-clean:
rm -f $(GOLANGCI_LINT)
rm -f $(RUNSIM)
rm -f $(STATIK) $(GOLANGCI_LINT) $(RUNSIM)
rm -f tools-stamp

.PHONY: all tools tools-clean
20 changes: 13 additions & 7 deletions contrib/devtools/install-golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

set -euo pipefail

installer="$(mktemp)"
trap "rm -f ${installer}" EXIT

GOBIN="${1}"
CURL="$(which curl)"
HASHSUM="${2}"

f_sha256() {
local l_file
l_file=$1
python -sBc "import hashlib;print(hashlib.sha256(open('$l_file','rb').read()).hexdigest())"
}

installer="$(mktemp)"
trap "rm -f ${installer}" EXIT
get_latest_release() {
"${CURL}" --silent "https://api.github.com/repos/$1/releases/latest" | \
grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}

GOBIN="${1}"
VERSION="${2}"
HASHSUM="${3}"
CURL="$(which curl)"
VERSION="$(get_latest_release golangci/golangci-lint)"

echo "Downloading golangci-lint ${VERSION} installer ..." >&2
"${CURL}" -sfL "https://raw.githubusercontent.com/golangci/golangci-lint/${VERSION}/install.sh" > "${installer}"
Expand All @@ -24,4 +30,4 @@ echo "Checking hashsum ..." >&2
chmod +x "${installer}"

echo "Launching installer ..." >&2
exec "${installer}" -d -b "${GOBIN}" "${VERSION}"
exec "${installer}" -d -b "${GOBIN}" "${VERSION}"

0 comments on commit 18d8b0b

Please sign in to comment.