diff --git a/Makefile b/Makefile index d96c461..9e531b9 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ DOCS_ASSET=src/docs/bindata.go SOURCE=$(wildcard cmd/paste/*.go) $(filter-out src/routes/bindata.go, $(wildcard src/routes/*.go)) BINARY=paste +VERSION:=$(shell debian/inc_version.sh -p $(shell git describe --tags `git rev-list --tags --max-count=1`)) +DATE:=$(shell date -u +%FT%TZ) + define DUMMY_BINDATA package docs import "net/http" @@ -27,8 +30,9 @@ run: $(BINARY) ./$(BINARY) -vv serve $(BINARY): $(SOURCE) $(ROUTE_ASSET) $(DOCS_ASSET) - go build "sour.is/x/paste/cmd/paste" - + go build \ + -ldflags "-X main.AppVersion=$(VERSION) -X main.AppBuild=$(DATE)" \ + "sour.is/x/paste/cmd/paste" clean-ui: rm -rf $(ROUTE_ASSET) $(DOCS_ASSET) diff --git a/debian/Makefile b/debian/Makefile index 618e522..9ffe8b6 100644 --- a/debian/Makefile +++ b/debian/Makefile @@ -1,42 +1,40 @@ NAME=sour.is-paste -VERSION:=$(shell cat VERSION) -RELEASE:=$(shell cat RELEASE) +VERSION:=$(shell ./inc_version.sh -p $(shell git describe --tags `git rev-list --tags --max-count=1`)|cut -b2-) +DATE:=$(shell date -u +%FT%TZ) REPO_HOST="xuu@kapha" ANSIBLE_HOST="kapha" REPO_PATH="/opt/web/pub/sour.is/debian/" -all: release build copy +all: build copy tag clean: rm -r BUILD/* -release: - @echo "release version $(RELEASE)" - @echo `expr $(RELEASE) + 1` > RELEASE - git commit -am "release version $(VERSION)-$(RELEASE)" - git tag -a -m "release version $(VERSION)-$(RELEASE)" "v$(VERSION)-$(RELEASE)" +tag: + git commit -am "release version $(VERSION)" + git tag -a -m "release version $(VERSION)" "v$(VERSION)" git push --tags build: - export BUILD="BUILD/$(NAME)_$(VERSION)-$(RELEASE)"; \ + export BUILD="BUILD/$(NAME)_$(VERSION)"; \ rm -rf ./$${BUILD}; \ cp -r ROOT "$${BUILD}"; \ - sed -i'.tmp' "s_Version:.*_Version: $(VERSION)-$(RELEASE)_" "$${BUILD}/DEBIAN/control" + sed -i'.tmp' "s_Version:.*_Version: $(VERSION)_" "$${BUILD}/DEBIAN/control" export DATE=`date -u +%FT%TZ`; \ - export BUILD="BUILD/$(NAME)_$(VERSION)-$(RELEASE)"; \ + export BUILD="BUILD/$(NAME)_$(VERSION)"; \ env GOOS=linux GOARCH=amd64 go build -v -o $${BUILD}/opt/sour.is/bin/paste \ - -ldflags "-X main.AppVersion=$(VERSION)-$(RELEASE) -X main.AppBuild=$${DATE}"\ + -ldflags "-X main.AppVersion=$(VERSION) -X main.AppBuild=$(DATE)"\ sour.is/x/paste/cmd/paste; \ dpkg -b $${BUILD}; copy: - export BUILD="BUILD/$(NAME)_$(VERSION)-$(RELEASE)"; \ + export BUILD="BUILD/$(NAME)_$(VERSION)"; \ scp "$${BUILD}.deb" $(REPO_HOST):$(REPO_PATH); \ - ssh $(REPO_HOST) -- $(REPO_PATH)scan.sh "$(REPO_PATH)$(NAME)_$(VERSION)-$(RELEASE).deb"; + ssh $(REPO_HOST) -- $(REPO_PATH)scan.sh "$(REPO_PATH)$(NAME)_$(VERSION).deb"; deploy: ansible $(ANSIBLE_HOST) -u xuu -b -m apt -a "name=sour.is-paste update_cache=yes state=latest" -.PHONY: clean release build copy # deploy +.PHONY: clean tag build copy deploy diff --git a/debian/RELEASE b/debian/RELEASE deleted file mode 100644 index d6b2404..0000000 --- a/debian/RELEASE +++ /dev/null @@ -1 +0,0 @@ -19 diff --git a/debian/inc_version.sh b/debian/inc_version.sh new file mode 100755 index 0000000..dfd0097 --- /dev/null +++ b/debian/inc_version.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Increment a version string using Semantic Versioning (SemVer) terminology. + +# Parse command line options. + +while getopts ":Mmp" Option +do + case $Option in + M ) major=true;; + m ) minor=true;; + p ) patch=true;; + esac +done + +shift $(($OPTIND - 1)) + +version=$1 + +# Build array from version string. + +a=( ${version//./ } ) + +# If version string is missing or has the wrong number of members, show usage message. + +if [ ${#a[@]} -ne 3 ] +then + >&2 echo "usage: $(basename $0) [-Mmp] major.minor.patch" + exit 1 +fi + +# Increment version numbers as requested. + +if [ ! -z $major ] +then + ((a[0]++)) + a[1]=0 + a[2]=0 +fi + +if [ ! -z $minor ] +then + ((a[1]++)) + a[2]=0 +fi + +if [ ! -z $patch ] +then + ((a[2]++)) +fi + +echo "${a[0]}.${a[1]}.${a[2]}" \ No newline at end of file