-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·68 lines (60 loc) · 2.37 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
PACKAGE=github.com/davfive/gitspaces/v2
GOFLAGS=-ldflags=-X=${PACKAGE}/cmd.Version=${VERSION}
VERSION:=$(shell git describe --long --tags --dirty)
VERSION_SHORT:=$(shell git describe --tags --abbrev=0)
BRANCH:=$(shell git branch --show-current)
MAJVER:=$(shell echo ${VERSION} | cut -d. -f1)
#=-----------------------------------------------------------
.PHONY: checkbranch checkdirty checkpending checkversion
.PHONY: checkbuild checkinstall checkpublish
.PHONY: build install newtag publish
#=-----------------------------------------------------------
build: checkbuild
@echo "[$@] Building ${VERSION} version"
go build ${GOFLAGS} -o build/gitspaces
install: checkinstall build
@echo "[$@] Installing ${VERSION} version"
go install ${GOFLAGS}
newtag:
@echo "[$@] Creating new tag for ${VERSION_SHORT} version"
echo "$(tag)" | grep -qE "v2\.\d+\.\d+" # check tag format
echo "{ \"version\": \"$(tag)\" }" > manifest.json
git commit -am "Release $(tag)"
git push
git tag -a $(tag) -m "Release $(tag)"
git push origin $(tag)
publish: checkpublish
@echo "[$@] Publishing ${VERSION_SHORT} version"
GOPROXY=proxy.golang.org go list -m ${GOFLAGS} ${PACKAGE}@${VERSION_SHORT}
#=-----------------------------------------------------------
checkbuild: checkversion
checkinstall: checkversion
checkpublish: checkversion checkbranch checkdirty checkpending
#=-----------------------------------------------------------
checkbranch:
@echo "[$@] Checking ${VERSION} version publish branch is ${MAJVER}"
@if [ "${BRANCH}" != "${MAJVER}" ]; then \
echo "Cannot publish ${VERSION} from branch ${BRANCH}"; \
echo "Please check ${VERSION} version release branch: ${MAJVER}"; \
exit 1; \
fi
checkdirty:
@echo "[$@] Checking working directory state"
@if [[ "${VERSION}" = *-dirty ]]; then \
echo "Cannot publish with modified (dirty) working directory: ${VERSION}"; \
echo "Please commit or stash your changes"; \
exit 1; \
fi
checkpending:
@echo "[$@] Checking that the tag is on the latest commit"
@if ! [[ "${VERSION}" = *-0-* ]]; then \
echo "Cannot publish tag with later commits: ${VERSION}"; \
echo "Please create/push a new tag"; \
exit 1; \
fi
checkversion:
@echo "[$@] Checking current git version: ${VERSION_SHORT} (${VERSION})"
@if [ -z "${VERSION}" -o -z "${VERSION_SHORT}" ]; then \
echo "Failed to get version from 'git describe --long --tags --dirty'"; \
exit 1; \
fi