-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.sla
225 lines (192 loc) · 6.45 KB
/
build.sla
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#
# This is a script containing functions that are used as build rules. You can
# use the Simple Little Automator (https://github.com/fboender/sla.git) to run
# these rules, or you can run them directly in your shell:
#
# $ bash -c ". build.sla && test"
#
PROG="scriptform"
test () {
# Run tests
# Runs unit, integration, linting and code quality tests.
ROOTDIR="$(pwd)"
# Unit / integration tests
cd test && /usr/bin/env python3 ./test.py
# Code quality linting (flake8)
cd $ROOTDIR
# E402 == module level import not at top of file
cd src && flake8 --extend-ignore=E402 *.py || true
# Code quality linting (pylint)
cd $ROOTDIR
cd src && pylint --reports=n -dR -d subprocess-popen-preexec-fn -d invalid-name -d star-args -d no-member *.py || true
cd $ROOTDIR
}
clean () {
# Clean the repo of artifacts
rm -rf $PROG.spec
rm -rf *.tar.gz
rm -rf *.zip
rm -rf *.deb
rm -rf rel_deb
rm -rf rel_bin
rm -rf scriptform-*
rm -rf doc/manual.html
rm -rf doc/MANUAL.html
rm -rf examples/megacorp_acc/megacorp.db
rm -rf examples/megacorp_acc/.coverage
rm -rf examples/megacorp_acc/htmlcov
find ./ -name "*.log" -delete
find ./ -name "*.pyc" -delete
rm -f test/data.csv
rm -f test/data.raw
rm -f test/.coverage
rm -rf test/htmlcov
rm -rf dist/
rm -rf build
}
doc () {
# Generate documentation
cat doc/header.html > doc/MANUAL.html
markdown_py doc/MANUAL.md >> doc/MANUAL.html
cat doc/footer.html >> doc/MANUAL.html
cat doc/header.html > README.html
markdown_py README.md >> README.html
cat doc/footer.html >> README.html
T_DOC_BUILT=1
}
_release_check() {
# Verify and prepare for release
# Only run this rule once
if [ -z "$RELEASE_CHECK_DONE" ]; then
RELEASE_CHECK_DONE=1
# Prepare project for release
clean
doc
# Check that REL_VERSION is set
if [ ! -z "$1" ]; then
REL_VERSION="$1"
shift
else
echo "REL_VERSION not set. Aborting" >&2
exit 1
fi
fi
}
release_src () {
# Build source (tar.gz) release
# Usage: sla release_src <version>
#
# Example:
# sla release_src 9.99
_release_check "$*"
# Prepare source
rm -rf "$PROG-$REL_VERSION"
mkdir "$PROG-$REL_VERSION"
cp src/*.py "$PROG-$REL_VERSION/"
mv "$PROG-$REL_VERSION/scriptform.py" "$PROG-$REL_VERSION/$PROG"
cp LICENSE "$PROG-$REL_VERSION/"
cp README.md "$PROG-$REL_VERSION/"
cp contrib/release_Makefile "$PROG-$REL_VERSION/Makefile"
cp doc/MANUAL.html "$PROG-$REL_VERSION/MANUAL.html"
# Bump version numbers
find "$PROG-$REL_VERSION/" -type f -print0 | xargs -0 sed -i "s/%%VERSION%%/$REL_VERSION/g"
# Create archives
zip -q -r "$PROG-$REL_VERSION.zip" "$PROG-$REL_VERSION"
tar -czf "$PROG-$REL_VERSION.tar.gz" "$PROG-$REL_VERSION"
}
release_deb () {
# Build deb release
# Usage: sla release_deb <version>
#
# Example:
# sla release_deb 9.99
_release_check "$*"
if [ -z "$RELEASE_DEB_DONE" ]; then
mkdir -p "rel_deb/usr/bin"
mkdir -p "rel_deb/usr/lib/$PROG"
mkdir -p "rel_deb/usr/share/doc/$PROG"
mkdir -p "rel_deb/usr/share/man/man1"
# Copy the source to the release directory structure.
cp LICENSE "rel_deb/usr/share/doc/$PROG"
cp README.md "rel_deb/usr/share/doc/$PROG"
cp doc/MANUAL.md "rel_deb/usr/share/doc/$PROG"
cp README.html "rel_deb/usr/share/doc/$PROG"
cp doc/MANUAL.html "rel_deb/usr/share/doc/$PROG"
cp -ar examples "rel_deb/usr/share/doc/$PROG"
cp src/*.py "rel_deb/usr/lib/$PROG/"
ln -s "/usr/lib/$PROG/scriptform.py" "rel_deb/usr/bin/$PROG"
cp contrib/scriptform.init.d_debian "rel_deb/usr/share/doc/$PROG"
cp contrib/scriptform.init.d_redhat "rel_deb/usr/share/doc/$PROG"
cp contrib/scriptform.service "rel_deb/usr/share/doc/$PROG"
cp -ar contrib/debian/DEBIAN "rel_deb/"
# Bump version numbers
find rel_deb/ -type f -print0 | xargs -0 sed -i "s/%%VERSION%%/$REL_VERSION/g"
# Create debian pacakge
fakeroot dpkg-deb --build rel_deb > /dev/null
mv rel_deb.deb "$PROG-$REL_VERSION.deb"
# Cleanup
rm -rf rel_deb
rm -rf "$PROG-$REL_VERSION"
RELEASE_DEB_DONE=1
fi
}
release_rpm () {
# Build rpm release
# Usage: sla release_rpm <version>
#
# Example:
# sla release_rpm 9.99
_release_check "$*"
release_deb
alien -r -g -v scriptform-$REL_VERSION.deb
sed -i 's#%dir "/"##' scriptform-$REL_VERSION/scriptform-$REL_VERSION-2.spec
sed -i 's#%dir "/usr/"##' scriptform-$REL_VERSION/scriptform-$REL_VERSION-2.spec
sed -i 's#%dir "/usr/bin/"##' scriptform-$REL_VERSION/scriptform-$REL_VERSION-2.spec
sed -i 's#%dir "/usr/lib/"##' scriptform-$REL_VERSION/scriptform-$REL_VERSION-2.spec
sed -i 's#%dir "/usr/share/"##' scriptform-$REL_VERSION/scriptform-$REL_VERSION-2.spec
sed -i 's#%dir "/usr/share/doc/"##' scriptform-$REL_VERSION/scriptform-$REL_VERSION-2.spec
sed -i 's#%dir "/usr/share/man/"##' scriptform-$REL_VERSION/scriptform-$REL_VERSION-2.spec
sed -i 's#%dir "/usr/share/man/man1/"##' scriptform-$REL_VERSION/scriptform-$REL_VERSION-2.spec
pushd .
cd scriptform-$REL_VERSION/
FULLPATH="$(pwd)"
rpmbuild --quiet --target=noarch --buildroot "$FULLPATH" -bb scriptform-$REL_VERSION-2.spec
popd
}
release_bin () {
# Build standalone binary release
# Usage: sla release_bin <version>
#
# Example:
# sla release_bin 9.99
_release_check "$*"
rm -rf dist/scriptform/
# Create copy and bump version numbers
cp -ar src/ rel_bin/
find rel_bin/ -type f -print0 | xargs -0 sed -i "s/%%VERSION%%/$REL_VERSION/g"
# Generate binary
pyinstaller --strip --onefile rel_bin/scriptform.py
# Generate tarball
mv dist $PROG-$REL_VERSION-bin64
cp contrib/scriptform.service $PROG-$REL_VERSION-bin64
tar -czf $PROG-$REL_VERSION-bin64.tar.gz $PROG-$REL_VERSION-bin64
# Cleanup
rm -rf $PROG-$REL_VERSION-bin64
rm -rf $PROG.spec
rm -rf build
rm -rf rel_bin
}
release () {
# Build all releases
# Usage: sla release <version>
#
# Builds the debian, rpm packages, source release and standalone binary.
#
# Example:
# sla release 9.99
_release_check "$*"
release_src
release_deb
release_rpm
release_bin
}