This repository has been archived by the owner on Jul 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
203 lines (177 loc) · 7.18 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#
# paws -- provision automated windows and services
# Copyright (C) 2016 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
default: help
############################################
# GLOBAL VARIABLES
############################################
# set version into paws/version.txt before to run any build
# release is managed by separated variable due build diff between spec and pip
VERSION=0.6.0
RELEASE=0
NAME=paws
MANPAGE=../paws-doc/man/paws.1
PWD=$(shell bash -c "pwd -P")
RPMDIST=$(shell rpm --eval '%dist')
RPMTOP=$(PWD)/rpmbuild
SPEC=$(NAME).spec
TARBALL=$(NAME)-$(VERSION)-$(RELEASE).tar.gz
SRPM=$(NAME)-$(VERSION)-$(RELEASE).src.rpm
RPM=$(NAME)-$(VERSION)-$(RELEASE).noarch.rpm
# for dev phony
DIST=$(shell bash -c "uname -r")
BRANCH=$(shell git symbolic-ref --short HEAD)
# Unit tests
TEST_SOURCE=tests
TEST_OUTPUT=$(RPMTOP)/TESTS
TEST_UNIT_FILE=unit-tests.xml
############################################
# Color definition
############################################
NO_COLOR = \x1b[0m
OK_COLOR = \x1b[32;01m
WARN_COLOR = \x1b[50;01m
ERROR_COLOR = \x1b[31;01m
help:
@echo
@echo -e "Usage: $(WARN_COLOR) make target$(NO_COLOR) where $(WARN_COLOR)target$(NO_COLOR) is one of following:"
@echo
@echo -e "\t$(OK_COLOR)--- code ---$(NO_COLOR)"
@echo -e "\t$(WARN_COLOR)clean$(NO_COLOR) clean temp files from local workspace"
@echo -e "\t$(WARN_COLOR)codecheck$(NO_COLOR) run code checkers pep8 and pylint"
@echo -e "\t$(WARN_COLOR)test$(NO_COLOR) run unit tests locally"
@echo -e "\t$(OK_COLOR)--- doc ---$(NO_COLOR)"
@echo -e "\t$(WARN_COLOR)doc$(NO_COLOR) generate sphinx doc html and man pages"
@echo -e "\t$(OK_COLOR)--- pip ---$(NO_COLOR)"
@echo -e "\t$(WARN_COLOR)pip$(NO_COLOR) build source codes and generate tar.gz file"
@echo -e "\t$(WARN_COLOR)pypi-test$(NO_COLOR) upload tar.gz to pypi-test"
@echo -e "\t$(WARN_COLOR)pypi$(NO_COLOR) upload tar.gz to pypi"
@echo -e "\t$(OK_COLOR)--- rpm ---$(NO_COLOR)"
@echo -e "\t$(WARN_COLOR)rpm$(NO_COLOR) build source codes and generate rpm file"
@echo -e "\t$(WARN_COLOR)tarball$(NO_COLOR) generate tarball of project"
@echo -e "\t$(WARN_COLOR)srpm$(NO_COLOR) generate srpm of project"
@echo -e "\t$(WARN_COLOR)copr-upstream$(NO_COLOR) generate srpm and send to build in upstream copr-fedora (prod)"
@echo -e "\t$(WARN_COLOR)copr-upstream-devel$(NO_COLOR) generate srpm and send to build in upstream copr-fedora (devel)"
@echo -e "\t$(WARN_COLOR)all$(NO_COLOR) clean test doc rpm"
@echo -e "\t$(WARN_COLOR)dev$(NO_COLOR) clean, rpm and install PAWS locally"
@echo -e "$(NO_COLOR)"
all: clean test rpm
prep:
@mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SRPMS,TESTS}
@echo -e "$(OK_COLOR)rpmbuild workdir created$(NO_COLOR)"
@echo
set-version:
@cp paws/version.txt $(RPMTOP)/BUILD/version.txt
@echo -e "$(OK_COLOR)set version $(VERSION) to $(RPMTOP)/SOURCES/version.txt$(NO_COLOR)"
@echo
clean:
$(RM) -r dist build paws_cli.egg-info
$(RM) $(NAME)*.tar.gz
$(RM) -r rpmbuild build doc/build
$(RM) -r .tox .pytest_cache
@find -name '*.py[co]' -delete
@echo -e "$(OK_COLOR)deleted rpmbuild, dist and build$(NO_COLOR)"
make clean -C doc/
@echo
tarball: doc
git ls-files | tar --transform='s|^|$(NAME)/|' \
--files-from /proc/self/fd/0 \
-czf $(RPMTOP)/SOURCES/$(TARBALL) $(SPEC)
cd $(RPMTOP)/SOURCES/ && tar -xf $(TARBALL)
cd $(RPMTOP)/SOURCES/ && cp paws.1 paws/paws.1
cd $(RPMTOP)/SOURCES/ && tar -czf $(TARBALL) $(NAME)
@echo -e "$(OK_COLOR)tarball created at $(RPMTOP)/SOURCES/$(TARBALL)$(NO_COLOR)"
@echo
srpm: tarball
rpmbuild --define="_topdir $(RPMTOP)" -ts $(RPMTOP)/SOURCES/$(TARBALL)
@echo -e "$(OK_COLOR)srpm created at $(RPMTOP)/SRPMS/$(SRPM)$(NO_COLOR)"
@echo
rpm: srpm
rpmbuild --define="_topdir $(RPMTOP)" --rebuild $(RPMTOP)/SRPMS/$(SRPM)
@echo -e "$(OK_COLOR)rpm created at $(RPMTOP)/RPMS/noarch/$(RPM)$(NO_COLOR)"
@echo
test: prep
nosetests --verbosity=3 -x --with-xunit \
--xunit-file=$(TEST_OUTPUT)/$(TEST_UNIT_FILE)
@echo
doc: prep set-version
make -C doc/ doc
make -C doc/ man
cp $(MANPAGE) $(RPMTOP)/SOURCES/
cp $(MANPAGE) $(RPMTOP)/BUILD/paws.1
@echo -e "$(OK_COLOR)html doc saved at: ../paws-doc/html/index.html$(NO_COLOR)"
@echo -e "$(OK_COLOR)man page saved at: ../paws-doc/man/paws.1$(NO_COLOR)"
@echo
copr-upstream: srpm
# build in fedora copr
# you need to have a valid ~/.config/copr file to use copr-cli
@echo "building source-code from branch $(BRANCH)"
ifeq ("$(BRANCH)","master")
@echo -e "$(OK_COLOR)running build in https://copr.fedorainfracloud.org/coprs/eduardocerqueira/paws/$(NO_COLOR)"
@copr-cli --config /home/$(USER)/.config/copr build eduardocerqueira/paws $(RPMTOP)/SRPMS/$(SRPM)
else
@echo -e "$(ERROR_COLOR)can't run build for branch != master to upstream$(NO_COLOR)"
endif
copr-upstream-devel: srpm
# build in fedora copr
# you need to have a valid ~/.config/copr file to use copr-cli
@echo "building source-code from branch $(BRANCH)"
ifeq ("$(BRANCH)","devel")
@echo -e "$(OK_COLOR)running build in https://copr.fedorainfracloud.org/coprs/rywillia/paws-devel/$(NO_COLOR)"
@copr-cli --config /home/$(USER)/.config/copr build rywillia/paws-devel $(RPMTOP)/SRPMS/$(SRPM)
else
@echo -e "$(ERROR_COLOR)can't run build for branch != devel to upstream$(NO_COLOR)"
endif
codecheck:
tox -e pep8
# get distro and set package manager DNF or YUM depending of distro
distro:
@echo "your system is running $(DIST)"
ifneq ($(findstring el,$(DIST)),)
PKGMNGR := yum
endif
ifneq ($(findstring fc,$(DIST)),)
PKGMNGR := dnf
endif
# build local rpm, remove previous, install new and print paws version
dev: clean distro rpm
ifneq ("$(wildcard /usr/bin/paws)","")
sudo $(PKGMNGR) remove paws -y > /dev/null
endif
sudo $(PKGMNGR) install $(shell bash -c "find $(RPMTOP)/RPMS/ \
-name '$(NAME)-$(VERSION)*'") -y > /dev/null
# install pip modules
sudo pip install -r rpm-post-packages.txt > /dev/null
sudo chown -R $(LOGNAME):$(LOGNAME) /usr/share/paws
@echo
paws --version
@echo
# pip tasks
pip: clean
@python setup.py sdist
@echo -e "$(OK_COLOR)pip tar.gz created at dist/$(NO_COLOR)"
@echo
# requires credential in ~/.pypirc
pypi-test: pip
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
@echo -e "$(OK_COLOR)check https://test.pypi.org/project/paws/#files$(NO_COLOR)"
@echo
# requires credential in ~/.pypirc
pypi: pip
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
@echo -e "$(OK_COLOR)check https://pypi.org/project/paws/#files$(NO_COLOR)"
@echo