Use Makefile instead of bash scripts

This commit is contained in:
Jannis Mattheis 2018-02-24 10:55:00 +01:00 committed by Jannis Mattheis
parent 66a7c3ee47
commit 61c4954b88
7 changed files with 95 additions and 91 deletions

3
.gitignore vendored
View File

@ -2,3 +2,6 @@ vendor/
.idea/
build/
certs/
build/
licenses/
coverage.txt

View File

@ -15,37 +15,21 @@ env:
before_install:
- curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o $GOPATH/bin/dep
- chmod +x $GOPATH/bin/dep
- chmod +x ./all-test-with-coverage.sh
- chmod +x ./swagger-validate.sh
- chmod +x ./build.sh
- chmod +x ./docker-build.sh
- chmod +x ./docker-push.sh
- mkdir build
- make download-tools
install:
- dep ensure
- go get github.com/golang/lint/golint
- go get honnef.co/go/tools/cmd/megacheck
- go get github.com/fzipp/gocyclo
- go get -u github.com/gobuffalo/packr/...
- go get -u github.com/go-swagger/go-swagger/cmd/swagger
- dep ensure -v
script:
- ./swagger-validate.sh
- ./all-test-with-coverage.sh
- go vet ./...
- megacheck ./...
- gocyclo -over 10 $(find . -iname '*.go' -type f | grep -v /vendor/)
- golint -set_exit_status $(go list ./... | grep -v mock)
- make test
- make check
after_success:
- bash <(curl -s https://codecov.io/bash)
before_deploy:
- docker pull karalabe/xgo-latest
- go get github.com/karalabe/xgo
- ./build.sh ${TRAVIS_TAG#v}
- ./docker-build.sh ${TRAVIS_TAG#v}
- if [[ $TRAVIS_TAG != "v"* ]]; then exit 1; fi
- VERSION=$(echo $TRAVIS_TAG | cut -c 2-) make build-all
deploy:
- provider: releases

85
Makefile Normal file
View File

@ -0,0 +1,85 @@
LICENSE_DIR=./licenses/
BUILD_DIR=./build/
DOCKER_DIR=./docker/
SHELL := /bin/bash
test: test-coverage test-race
check: additional-checks check-swagger
build-all: build-zip build-docker
require-version:
if [ -n ${VERSION} ] && [[ $$VERSION == "v"* ]]; then echo "The version may not start with v" && exit 1; fi
if [ -z ${VERSION} ]; then echo "Need to set VERSION" && exit 1; fi;
test-race:
go test -v -race ./...
test-coverage:
echo "" > coverage.txt
for d in $(shell go list ./... | grep -v vendor); do \
go test -v -coverprofile=profile.out -covermode=atomic $$d ; \
if [ -f profile.out ]; then \
cat profile.out >> coverage.txt ; \
rm profile.out ; \
fi \
done
additional-checks:
go vet ./...
megacheck ./...
gocyclo -over 10 $(shell find . -iname '*.go' -type f | grep -v /vendor/)
golint -set_exit_status $(shell go list ./... | grep -v mock)
download-tools:
go get github.com/golang/lint/golint
go get honnef.co/go/tools/cmd/megacheck
go get github.com/fzipp/gocyclo
go get -u github.com/gobuffalo/packr/...
go get -u github.com/go-swagger/go-swagger/cmd/swagger
go get github.com/karalabe/xgo
update-swagger:
swagger generate spec --scan-models -o docs/spec.json
check-swagger: update-swagger
## add the docs to git, this changes line endings in git, otherwise this does not work on windows
git add docs
if [ -n "$(shell git status --porcelain | grep docs)" ]; then \
git status --porcelain | grep docs; \
echo Swagger or the Packr file is not up-to-date; \
exit 1; \
fi
extract-licenses:
mkdir ${LICENSE_DIR} || true
for LICENSE in $(shell find vendor/* -name LICENSE | grep -v monkey); do \
DIR=`echo $$LICENSE | tr "/" _ | sed -e 's/vendor_//; s/_LICENSE//'` ; \
cp $$LICENSE ${LICENSE_DIR}$$DIR ; \
done
build-binary: require-version
mkdir build || true
docker pull karalabe/xgo-latest;
xgo -ldflags "-X main.Version=${VERSION} \
-X main.BuildDate=$(shell date "+%F-%T") \
-X main.Commit=$(shell git rev-parse --verify HEAD)" \
-targets linux/arm64,linux/amd64,linux/arm-7,windows-10/amd64 \
-dest ${BUILD_DIR} \
-out gotify \
github.com/gotify/server
build-zip: build-binary extract-licenses
for BUILD in $(shell find ${BUILD_DIR}*); do \
zip -j $$BUILD.zip $$BUILD ./LICENSE; \
zip -ur $$BUILD.zip ${LICENSE_DIR}; \
done
build-docker: require-version build-binary
cp ${BUILD_DIR}gotify-linux-amd64 ./docker/gotify-app
(cd ${DOCKER_DIR} && docker build -t gotify/server:latest -t gotify/server:${VERSION} .)
rm ${DOCKER_DIR}gotify-app
cp ${BUILD_DIR}gotify-linux-arm-7 ./docker/gotify-app
(cd ${DOCKER_DIR} && docker build -f Dockerfile.arm7 -t gotify/server-arm7:latest -t gotify/server-arm7:${VERSION} .)
rm ${DOCKER_DIR}gotify-app
.PHONY: test-race test-coverage test additional-checks verify-swagger check download-tools update-swagger build-binary build-zip build-docker build-all

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
set -e
echo "" > coverage.txt
for d in $(go list ./... | grep -v vendor); do
go test -v -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done
go test -v -race ./...

View File

@ -1,32 +0,0 @@
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo You need to pass the version as first parameter.
exit 1
fi
VERSION=$1
DATE=`date "+%F-%T"`
COMMIT=`git rev-parse --verify HEAD`
BRANCH=`git rev-parse --abbrev-ref HEAD`
URL=github.com/gotify/server
PREFIX=gotify
DEST=./build
TARGETS=linux/arm64,linux/amd64,linux/arm-7,windows-10/amd64
LICENSES=./licenses/
xgo -ldflags "-X main.Version=$VERSION -X main.BuildDate=$DATE -X main.Commit=$COMMIT -X main.Branch=$BRANCH" -targets $TARGETS -dest $DEST -out $PREFIX $URL
mkdir $LICENSES
for LICENSE in $(find vendor/ -name LICENSE | grep -v monkey); do
DIR=$(echo $LICENSE | tr "/" _ | sed -e 's/vendor_//; s/_LICENSE//')
mkdir $LICENSES$DIR
cp $LICENSE $LICENSES$DIR
done
for BUILD in $(find build/*); do
zip -j $BUILD.zip $BUILD ./LICENSE
zip -ur $BUILD.zip $LICENSES
done
rm -rf $LICENSES

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo You need to pass the version as first parameter.
exit 1
fi
cp ./build/gotify-linux-amd64 ./docker/gotify-app
(cd docker && docker build -t gotify/server:latest -t gotify/server:$1 .)
rm ./docker/gotify-app
cp ./build/gotify-linux-arm-7 ./docker/gotify-app
(cd docker && docker build -f Dockerfile.arm7 -t gotify/server-arm7:latest -t gotify/server-arm7:$1 .)
rm ./docker/gotify-app

View File

@ -1,10 +0,0 @@
#!/usr/bin/env bash
swagger generate spec --scan-models -o docs/spec.json
(cd docs && packr && git add .)
if [[ `git diff docs` ]]; then
git status --porcelain | grep docs
git diff docs
echo Swagger or the Packr file is not up-to-date
exit 1
fi