2017-05-18 02:10:45 +00:00
SOURCE ?= file go-bindata github aws-s3 google-cloud-storage
2017-05-18 02:16:08 +00:00
DATABASE ?= postgres mysql redshift
2017-02-23 18:36:33 +00:00
VERSION ?= $( shell git describe --tags 2>/dev/null | cut -c 2-)
2017-02-09 00:17:04 +00:00
TEST_FLAGS ?=
2017-02-09 03:34:53 +00:00
REPO_OWNER ?= $( shell cd .. && basename " $$ (pwd) " )
2017-02-09 00:17:04 +00:00
2017-02-08 06:01:29 +00:00
build-cli : clean
-mkdir ./cli/build
2017-02-09 00:17:04 +00:00
cd ./cli && GOOS = linux GOARCH = amd64 go build -a -o build/migrate.linux-amd64 -ldflags= '-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' .
cd ./cli && GOOS = darwin GOARCH = amd64 go build -a -o build/migrate.darwin-amd64 -ldflags= '-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' .
cd ./cli && GOOS = windows GOARCH = amd64 go build -a -o build/migrate.windows-amd64.exe -ldflags= '-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' .
2017-02-08 06:01:29 +00:00
cd ./cli/build && find . -name 'migrate*' | xargs -I{ } tar czf { } .tar.gz { }
cd ./cli/build && shasum -a 256 * > sha256sum.txt
cat ./cli/build/sha256sum.txt
2015-10-15 16:49:43 +00:00
2017-02-09 00:17:04 +00:00
2015-10-15 16:49:43 +00:00
clean :
2017-02-08 06:01:29 +00:00
-rm -r ./cli/build
2017-02-09 00:17:04 +00:00
2017-02-08 06:01:29 +00:00
test-short :
make test-with-flags --ignore-errors TEST_FLAGS = '-short'
2017-02-09 00:17:04 +00:00
2017-02-08 06:01:29 +00:00
test :
2017-02-09 00:17:04 +00:00
@-rm -r .coverage
@mkdir .coverage
2017-02-15 07:12:16 +00:00
make test-with-flags TEST_FLAGS = '-v -race -covermode atomic -coverprofile .coverage/_$$(RAND).txt -bench=. -benchmem'
2017-02-09 00:17:04 +00:00
@echo 'mode: atomic' > .coverage/combined.txt
@cat .coverage/*.txt | grep -v 'mode: atomic' >> .coverage/combined.txt
2017-02-08 06:01:29 +00:00
2015-10-15 16:49:43 +00:00
2017-02-08 06:01:29 +00:00
test-with-flags :
@echo SOURCE: $( SOURCE)
@echo DATABASE: $( DATABASE)
2016-10-23 21:56:37 +00:00
2017-02-08 06:01:29 +00:00
@go test $( TEST_FLAGS) .
@go test $( TEST_FLAGS) ./cli/...
2017-02-09 00:17:04 +00:00
@go test $( TEST_FLAGS) ./testing/...
2016-10-23 21:56:37 +00:00
2017-02-09 00:17:04 +00:00
@echo -n '$(SOURCE)' | tr -s ' ' '\n' | xargs -I{ } go test $( TEST_FLAGS) ./source/{ }
2017-02-09 03:34:53 +00:00
@go test $( TEST_FLAGS) ./source/testing/...
@go test $( TEST_FLAGS) ./source/stub/...
2015-10-15 16:49:43 +00:00
2017-02-09 00:17:04 +00:00
@echo -n '$(DATABASE)' | tr -s ' ' '\n' | xargs -I{ } go test $( TEST_FLAGS) ./database/{ }
2017-02-09 03:34:53 +00:00
@go test $( TEST_FLAGS) ./database/testing/...
@go test $( TEST_FLAGS) ./database/stub/...
2017-02-09 00:17:04 +00:00
2017-02-12 03:15:54 +00:00
kill-orphaned-docker-containers :
docker rm -f $( shell docker ps -aq --filter label = migrate_test)
2017-02-09 00:17:04 +00:00
html-coverage :
go tool cover -html= .coverage/combined.txt
2015-10-15 16:49:43 +00:00
2017-02-08 09:49:57 +00:00
deps :
-go get -v -u ./...
-go test -v -i ./...
2017-05-18 02:21:48 +00:00
# TODO: why is this not being fetched with the command above?
2017-05-18 02:26:24 +00:00
-go get github.com/fsouza/fake-gcs-server/fakestorage
2017-05-18 02:21:48 +00:00
2017-02-08 09:49:57 +00:00
2017-02-09 03:34:53 +00:00
list-external-deps :
$( call external_deps,'.' )
$( call external_deps,'./cli/...' )
$( call external_deps,'./testing/...' )
$( foreach v, $( SOURCE) , $( call external_deps,'./source/$(v)/...' ) )
$( call external_deps,'./source/testing/...' )
$( call external_deps,'./source/stub/...' )
$( foreach v, $( DATABASE) , $( call external_deps,'./database/$(v)/...' ) )
$( call external_deps,'./database/testing/...' )
$( call external_deps,'./database/stub/...' )
2017-02-09 02:01:01 +00:00
restore-import-paths :
2017-02-09 03:34:53 +00:00
find . -name '*.go' -type f -execdir sed -i '' s%\" github.com/$( REPO_OWNER) /migrate%\" github.com/mattes/migrate%g '{}' \;
2017-02-09 02:01:01 +00:00
rewrite-import-paths :
2017-02-09 03:34:53 +00:00
find . -name '*.go' -type f -execdir sed -i '' s%\" github.com/mattes/migrate%\" github.com/$( REPO_OWNER) /migrate%g '{}' \;
2017-02-09 19:59:49 +00:00
# example: fswatch -0 --exclude .godoc.pid --event Updated . | xargs -0 -n1 -I{} make docs
docs :
-make kill-docs
nohup godoc -play -http= 127.0.0.1:6064 </dev/null >/dev/null 2>& 1 & echo $$ ! > .godoc.pid
cat .godoc.pid
kill-docs :
@cat .godoc.pid
kill -9 $$ ( cat .godoc.pid)
rm .godoc.pid
open-docs :
open http://localhost:6064/pkg/github.com/$( REPO_OWNER) /migrate
# example: make release V=0.0.0
2017-02-09 03:54:50 +00:00
release :
git tag v$( V)
@read -p "Press enter to confirm and push to origin ..." && git push origin v$( V)
2017-02-09 03:34:53 +00:00
d e f i n e e x t e r n a l _ d e p s
2017-02-11 19:13:27 +00:00
@echo '-- $(1)' ; go list -f '{{join .Deps "\n"}}' $( 1) | grep -v github.com/$( REPO_OWNER) /migrate | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'
2017-02-09 03:34:53 +00:00
e n d e f
2017-02-09 02:01:01 +00:00
.PHONY : build -cli clean test -short test test -with -flags deps html -coverage \
2017-02-09 20:03:03 +00:00
restore-import-paths rewrite-import-paths list-external-deps release \
2017-02-12 03:15:54 +00:00
docs kill-docs open-docs kill-orphaned-docker-containers
2017-02-09 02:01:01 +00:00
2017-02-09 00:17:04 +00:00
SHELL = /bin/bash
RAND = $( shell echo $$ RANDOM)
2015-10-15 16:49:43 +00:00