2017-06-25 21:45:22 +00:00
|
|
|
SHELL := /bin/bash
|
|
|
|
|
|
|
|
PREFIX=qingstor-sdk-go
|
|
|
|
VERSION=$(shell cat version.go | grep "Version\ =" | sed -e s/^.*\ //g | sed -e s/\"//g)
|
|
|
|
DIRS_TO_CHECK=$(shell ls -d */ | grep -vE "vendor|test")
|
|
|
|
PKGS_TO_CHECK=$(shell go list ./... | grep -v "/vendor/")
|
|
|
|
PKGS_TO_RELEASE=$(shell go list ./... | grep -vE "/vendor/|/test")
|
|
|
|
FILES_TO_RELEASE=$(shell find . -name "*.go" | grep -vE "/vendor/|/test|.*_test.go")
|
|
|
|
FILES_TO_RELEASE_WITH_VENDOR=$(shell find . -name "*.go" | grep -vE "/test|.*_test.go")
|
|
|
|
|
|
|
|
.PHONY: help
|
|
|
|
help:
|
|
|
|
@echo "Please use \`make <target>\` where <target> is one of"
|
|
|
|
@echo " all to check, build, test and release this SDK"
|
|
|
|
@echo " check to vet and lint the SDK"
|
|
|
|
@echo " update to update git submodules"
|
|
|
|
@echo " generate to generate service code"
|
|
|
|
@echo " build to build the SDK"
|
|
|
|
@echo " test to run test"
|
|
|
|
@echo " test-coverage to run test with coverage"
|
|
|
|
@echo " test-race to run test with race"
|
|
|
|
@echo " integration-test to run integration test"
|
|
|
|
@echo " release to build and release current version"
|
|
|
|
@echo " release-source to pack the source code"
|
|
|
|
@echo " clean to clean the coverage files"
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: check build unit release
|
|
|
|
|
|
|
|
.PHONY: check
|
|
|
|
check: vet lint
|
|
|
|
|
|
|
|
.PHONY: vet
|
|
|
|
vet:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Go tool vet, skipping vendor packages"
|
2017-06-25 21:45:22 +00:00
|
|
|
@go tool vet -all ${DIRS_TO_CHECK}
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: lint
|
|
|
|
lint:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Golint, skipping vendor packages"
|
2017-06-25 21:45:22 +00:00
|
|
|
@lint=$$(for pkg in ${PKGS_TO_CHECK}; do golint $${pkg}; done); \
|
|
|
|
lint=$$(echo "$${lint}"); \
|
|
|
|
if [[ -n $${lint} ]]; then echo "$${lint}"; exit 1; fi
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: update
|
|
|
|
update:
|
|
|
|
git submodule update --remote
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: generate
|
|
|
|
generate:
|
|
|
|
@if [[ ! -f "$$(which snips)" ]]; then \
|
|
|
|
echo "ERROR: Command \"snips\" not found."; \
|
|
|
|
fi
|
2017-09-30 14:27:27 +00:00
|
|
|
snips -f="./specs/qingstor/2016-01-06/swagger/api_v2.0.json" -t="./template" -o="./service"
|
2017-06-25 21:45:22 +00:00
|
|
|
gofmt -w .
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: build
|
|
|
|
build:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Build the SDK"
|
2017-09-30 14:27:27 +00:00
|
|
|
go build ${PKGS_TO_RELEASE}
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
test:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Run test"
|
2017-06-25 21:45:22 +00:00
|
|
|
go test -v ${PKGS_TO_RELEASE}
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: test-coverage
|
|
|
|
test-coverage:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Run test with coverage"
|
2017-06-25 21:45:22 +00:00
|
|
|
for pkg in ${PKGS_TO_RELEASE}; do \
|
|
|
|
output="coverage$${pkg#github.com/yunify/qingstor-sdk-go}"; \
|
|
|
|
mkdir -p $${output}; \
|
|
|
|
go test -v -cover -coverprofile="$${output}/profile.out" $${pkg}; \
|
|
|
|
if [[ -e "$${output}/profile.out" ]]; then \
|
|
|
|
go tool cover -html="$${output}/profile.out" -o "$${output}/profile.html"; \
|
|
|
|
fi; \
|
|
|
|
done
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: test-race
|
|
|
|
test-race:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Run test with race"
|
2017-06-25 21:45:22 +00:00
|
|
|
go test -v -race -cpu=1,2,4 ${PKGS_TO_RELEASE}
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: integration-test
|
|
|
|
integration-test:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Run integration test"
|
2017-06-25 21:45:22 +00:00
|
|
|
pushd "./test"; go run *.go; popd
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: release
|
|
|
|
release: release-source release-source-with-vendor
|
|
|
|
|
|
|
|
.PHONY: release-source
|
|
|
|
release-source:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Pack the source code"
|
2017-06-25 21:45:22 +00:00
|
|
|
mkdir -p "release"
|
|
|
|
zip -FS "release/${PREFIX}-source-v${VERSION}.zip" ${FILES_TO_RELEASE}
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: release-source-with-vendor
|
|
|
|
release-source-with-vendor:
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Pack the source code with vendor"
|
2017-06-25 21:45:22 +00:00
|
|
|
mkdir -p "release"
|
|
|
|
zip -FS "release/${PREFIX}-source-with-vendor-v${VERSION}.zip" ${FILES_TO_RELEASE_WITH_VENDOR}
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|
2017-06-25 21:45:22 +00:00
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm -rf $${PWD}/coverage
|
2018-01-16 13:20:59 +00:00
|
|
|
@echo "Done"
|