forked from ceph/ceph-ansible
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
106 lines (92 loc) · 3.05 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Makefile for constructing RPMs.
# Try "make" (for SRPMS) or "make rpm"
NAME = ceph-ansible
# Set the RPM package NVR from "git describe".
# Examples:
#
# A "git describe" value of "v2.2.0beta1" would create an NVR
# "ceph-ansible-2.2.0-0.beta1.1.el8"
#
# A "git describe" value of "v2.2.0rc1" would create an NVR
# "ceph-ansible-2.2.0-0.rc1.1.el8"
#
# A "git describe" value of "v2.2.0rc1-1-gc465f85" would create an NVR
# "ceph-ansible-2.2.0-0.rc1.1.gc465f85.el8"
#
# A "git describe" value of "v2.2.0" creates an NVR
# "ceph-ansible-2.2.0-1.el8"
TAG := $(shell git describe --tags --abbrev=0 --match 'v*')
VERSION := $(shell echo $(TAG) | sed 's/^v//')
COMMIT := $(shell git rev-parse HEAD)
SHORTCOMMIT := $(shell echo $(COMMIT) | cut -c1-7)
RELEASE := $(shell git describe --tags --match 'v*' \
| sed 's/^v//' \
| sed 's/^[^-]*-//' \
| sed 's/-/./')
ifeq ($(VERSION),$(RELEASE))
RELEASE = 1
endif
ifneq (,$(findstring beta,$(VERSION)))
BETA := $(shell echo $(VERSION) | sed 's/.*beta/beta/')
RELEASE := 0.$(BETA).$(RELEASE)
VERSION := $(subst $(BETA),,$(VERSION))
endif
ifneq (,$(findstring rc,$(VERSION)))
RC := $(shell echo $(VERSION) | sed 's/.*rc/rc/')
RELEASE := 0.$(RC).$(RELEASE)
VERSION := $(subst $(RC),,$(VERSION))
endif
ifneq (,$(shell echo $(VERSION) | grep [a-zA-Z]))
# If we still have alpha characters in our Git tag string, we don't know
# how to translate that into a sane RPM version/release. Bail out.
$(error cannot translate Git tag version $(VERSION) to an RPM NVR)
endif
NVR := $(NAME)-$(VERSION)-$(RELEASE).el8
all: srpm
# Testing only
echo:
echo COMMIT $(COMMIT)
echo VERSION $(VERSION)
echo RELEASE $(RELEASE)
echo NVR $(NVR)
clean:
rm -rf dist/
rm -rf ceph-ansible-$(VERSION)-$(SHORTCOMMIT).tar.gz
rm -rf $(NVR).src.rpm
dist:
git archive --format=tar.gz --prefix=ceph-ansible-$(VERSION)/ HEAD > ceph-ansible-$(VERSION)-$(SHORTCOMMIT).tar.gz
spec:
sed ceph-ansible.spec.in \
-e 's/@COMMIT@/$(COMMIT)/' \
-e 's/@VERSION@/$(VERSION)/' \
-e 's/@RELEASE@/$(RELEASE)/' \
> ceph-ansible.spec
srpm: dist spec
rpmbuild -bs ceph-ansible.spec \
--define "_topdir ." \
--define "_sourcedir ." \
--define "_srcrpmdir ." \
--define "dist .el8"
rpm: dist srpm
mock -r epel-7-x86_64 rebuild $(NVR).src.rpm \
--resultdir=. \
--define "dist .el8"
tag:
$(eval BRANCH := $(shell git rev-parse --abbrev-ref HEAD))
$(eval LASTNUM := $(shell echo $(TAG) \
| sed -E "s/.*[^0-9]([0-9]+)$$/\1/"))
$(eval NEXTNUM=$(shell echo $$(($(LASTNUM)+1))))
$(eval NEXTTAG=$(shell echo $(TAG) | sed "s/$(LASTNUM)$$/$(NEXTNUM)/"))
if [[ "$(TAG)" == "$(git describe --tags --match 'v*')" ]]; then \
echo "$(SHORTCOMMIT) on $(BRANCH) is already tagged as $(TAG)"; \
exit 1; \
fi
if [[ "$(BRANCH)" != "master" ]] && \
! [[ "$(BRANCH)" =~ ^stable- ]]; then \
echo Cannot tag $(BRANCH); \
exit 1; \
fi
@echo Tagging Git branch $(BRANCH)
git tag $(NEXTTAG)
@echo run \'git push origin $(NEXTTAG)\' to push to GitHub.
.PHONY: dist rpm srpm tag