github.com/scaleway/scaleway-cli@v1.11.1/Makefile (about) 1 # Go parameters 2 GOENV ?= GO15VENDOREXPERIMENT=1 3 GO ?= $(GOENV) go 4 GODEP ?= $(GOENV) godep 5 GOBUILD ?= $(GO) build 6 GOCLEAN ?= $(GO) clean 7 GOINSTALL ?= $(GO) install 8 GOTEST ?= $(GO) test $(GOTESTFLAGS) 9 GOFMT ?= gofmt -w -s 10 GODIR ?= github.com/scaleway/scaleway-cli 11 GOCOVER ?= $(GOTEST) -covermode=count -v 12 FPM_VERSION ?= $(shell ./dist/scw-Darwin-i386 --version | sed 's/.*v\([0-9.]*\),.*/\1/g') 13 FPM_DOCKER ?= \ 14 -it --rm \ 15 -v $(PWD)/dist:/output \ 16 -w /output \ 17 tenzer/fpm fpm 18 FPM_ARGS ?= \ 19 -C /input/ \ 20 -s dir \ 21 --name=scw \ 22 --no-depends \ 23 --version=$(FPM_VERSION) \ 24 --license=mit \ 25 -m "Scaleway <opensource@scaleway.com>" 26 27 28 NAME = scw 29 30 SOURCES := $(shell find ./pkg ./cmd -type f -name "*.go" | grep -v "_test.go$$") 31 COMMANDS := $(shell go list ./... | grep -v /vendor/ | grep /cmd/) 32 PACKAGES := $(shell go list ./... | grep -v /vendor/ | grep -v /cmd/) 33 REL_COMMANDS := $(subst $(GODIR),.,$(COMMANDS)) 34 REL_PACKAGES := $(subst $(GODIR),.,$(PACKAGES)) 35 VERSION = $(shell cat .goxc.json | grep "PackageVersion" | egrep -o "([0-9]{1,}\.)+[0-9]{1,}") 36 REV = $(shell git rev-parse --short HEAD || echo "nogit") 37 TAG = $(shell git describe --tags --always || echo $(VERSION) || echo "nogit") 38 LDFLAGS = "-X `go list ./pkg/scwversion`.GITCOMMIT=$(REV) -s" 39 BUILDER = scaleway-cli-builder 40 41 # Check go version 42 GOVERSIONMAJOR = $(shell go version | grep -o '[1-9].[0-9]' | cut -d '.' -f1) 43 GOVERSIONMINOR = $(shell go version | grep -o '[1-9].[0-9]' | cut -d '.' -f2) 44 VERSION_GE_1_5 = $(shell [ $(GOVERSIONMAJOR) -gt 1 -o $(GOVERSIONMINOR) -ge 5 ] && echo true) 45 ifneq ($(VERSION_GE_1_5),true) 46 $(error Bad go version, please install a version greater than or equal to 1.5) 47 endif 48 49 BUILD_LIST = $(foreach int, $(COMMANDS), $(int)_build) 50 CLEAN_LIST = $(foreach int, $(COMMANDS) $(PACKAGES), $(int)_clean) 51 INSTALL_LIST = $(foreach int, $(COMMANDS), $(int)_install) 52 TEST_LIST = $(foreach int, $(COMMANDS) $(PACKAGES), $(int)_test) 53 FMT_LIST = $(foreach int, $(COMMANDS) $(PACKAGES), $(int)_fmt) 54 COVERPROFILE_LIST = $(foreach int, $(subst $(GODIR),./,$(PACKAGES)), $(int)/profile.out) 55 56 57 .PHONY: $(CLEAN_LIST) $(TEST_LIST) $(FMT_LIST) $(INSTALL_LIST) $(BUILD_LIST) $(IREF_LIST) 58 59 60 all: build 61 build: $(BUILD_LIST) 62 clean: $(CLEAN_LIST) 63 install: $(INSTALL_LIST) 64 test: $(TEST_LIST) 65 fmt: $(FMT_LIST) 66 67 68 .git: 69 touch $@ 70 71 72 $(BUILD_LIST): %_build: %_fmt 73 @go tool vet --all=true $(SOURCES) 74 $(GOBUILD) -ldflags $(LDFLAGS) -o $(NAME) $(subst $(GODIR),.,$*) 75 $(CLEAN_LIST): %_clean: 76 $(GOCLEAN) $(subst $(GODIR),./,$*) 77 $(INSTALL_LIST): %_install: 78 $(GOINSTALL) $(subst $(GODIR),./,$*) 79 $(TEST_LIST): %_test: 80 $(GOTEST) -ldflags $(LDFLAGS) -v $(subst $(GODIR),.,$*) 81 $(FMT_LIST): %_fmt: 82 @$(GOFMT) $(SOURCES) 83 84 85 86 release-docker: 87 docker push scaleway/cli 88 89 90 goxc: 91 rm -rf dist/$(shell cat .goxc.json| jq -r .PackageVersion) 92 rm -f dist/latest 93 mkdir -p dist/$(shell cat .goxc.json| jq -r .PackageVersion) 94 ln -s -f $(shell cat .goxc.json| jq -r .PackageVersion) dist/latest 95 96 $(GOENV) goxc -build-ldflags $(LDFLAGS) 97 98 -mv dist/latest/darwin_386/scw dist/latest/scw-Darwin-i386 99 -mv dist/latest/darwin_amd64/scw dist/latest/scw-Darwin-amd64 100 -mv dist/latest/freebsd_386/scw dist/latest/scw-Freebsd-i386 101 -mv dist/latest/freebsd_amd64/scw dist/latest/scw-Freebsd-x86_64 102 -mv dist/latest/freebsd_arm/scw dist/latest/scw-Freebsd-arm 103 -mv dist/latest/linux_386/scw dist/latest/scw-Linux-i386 104 -mv dist/latest/linux_amd64/scw dist/latest/scw-Linux-x86_64 105 -mv dist/latest/linux_arm/scw dist/latest/scw-Linux-arm 106 -mv dist/latest/netbsd_386/scw dist/latest/scw-Netbsd-i386 107 -mv dist/latest/netbsd_amd64/scw dist/latest/scw-Netbsd-x86_64 108 -mv dist/latest/netbsd_arm/scw dist/latest/scw-Netbsd-arm 109 -mv dist/latest/windows_386/scw.exe dist/latest/scw-Windows-i386.exe 110 -mv dist/latest/windows_amd64/scw.exe dist/latest/scw-Windows-x86_64.exe 111 112 -cp dist/latest/scw-Linux-arm dist/latest/scw-Linux-armv7l 113 114 @rmdir dist/latest/* || true 115 116 docker run --rm golang tar -cf - /etc/ssl > dist/latest/ssl.tar 117 docker build -t scaleway/cli dist 118 docker run scaleway/cli version 119 docker tag -f scaleway/cli:latest scaleway/cli:$(TAG) 120 121 @echo "Now you can run 'goxc publish-github', 'goxc bintray' and 'make release-docker'" 122 123 124 packages: 125 rm -f dist/*.deb 126 docker run -v $(PWD)/dist/scw-Linux-x86_64:/input/scw $(FPM_DOCKER) $(FPM_ARGS) -t deb -a x86_64 ./ 127 docker run -v $(PWD)/dist/scw-Linux-i386:/input/scw $(FPM_DOCKER) $(FPM_ARGS) -t deb -a i386 ./ 128 docker run -v $(PWD)/dist/scw-Linux-arm:/input/scw $(FPM_DOCKER) $(FPM_ARGS) -t deb -a arm ./ 129 130 131 #publish_packages: 132 # docker run -v $(PWD)/dist moul/dput ppa:moul/scw dist/scw_$(FPM_VERSION)_arm.changes 133 134 135 .PHONY: golint 136 golint: 137 @$(GO) get github.com/golang/lint/golint 138 @for dir in $(shell $(GO) list ./... | grep -v /vendor/); do golint $$dir; done 139 140 141 .PHONY: gocyclo 142 gocyclo: 143 go get github.com/fzipp/gocyclo 144 gocyclo -over 15 $(shell find . -name "*.go" -not -name "*test.go" | grep -v /vendor/) 145 146 147 .PHONY: godep-save 148 godep-save: 149 go get github.com/tools/godep 150 $(GODEP) save $(PACKAGES) $(COMMANDS) 151 152 153 .PHONY: convey 154 convey: 155 go get github.com/smartystreets/goconvey 156 $(GOENV) goconvey -cover -port=9042 -workDir="$(realpath .)/pkg" -depth=-1 157 158 159 .PHONY: travis_login 160 travis_login: 161 @if [ "$(TRAVIS_SCALEWAY_TOKEN)" -a "$(TRAVIS_SCALEWAY_ORGANIZATION)" ]; then \ 162 echo '{"organization":"$(TRAVIS_SCALEWAY_ORGANIZATION)","token":"$(TRAVIS_SCALEWAY_TOKEN)"}' > ~/.scwrc && \ 163 chmod 600 ~/.scwrc; \ 164 else \ 165 echo "Cannot login, credentials are missing"; \ 166 fi 167 168 169 .PHONY: cover 170 cover: profile.out 171 172 $(COVERPROFILE_LIST):: $(SOURCES) 173 rm -f $@ 174 $(GOCOVER) -ldflags $(LDFLAGS) -coverpkg=./pkg/... -coverprofile=$@ ./$(dir $@) 175 176 profile.out:: $(COVERPROFILE_LIST) 177 rm -f $@ 178 echo "mode: set" > $@ 179 cat ./pkg/*/profile.out | grep -v mode: | sort -r | awk '{if($$1 != last) {print $$0;last=$$1}}' >> $@ 180 181 182 .PHONY: travis_coveralls 183 travis_coveralls: 184 if [ -f ~/.scwrc ]; then goveralls -covermode=count -service=travis-ci -v -coverprofile=profile.out; fi 185 186 187 .PHONY: travis_cleanup 188 travis_cleanup: 189 # FIXME: delete only resources created for this project 190 @if [ "$(TRAVIS_SCALEWAY_TOKEN)" -a "$(TRAVIS_SCALEWAY_ORGANIZATION)" ]; then \ 191 ./scw stop -t $(shell ./scw ps -q) || true; \ 192 ./scw rm $(shell ./scw ps -aq) || true; \ 193 ./scw rmi $(shell ./scw images -a -f organization=me -q) || true; \ 194 fi 195 196 197 .PHONY: show_version 198 show_version: 199 ./scw version