-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild-git.sh
More file actions
48 lines (42 loc) · 879 Bytes
/
build-git.sh
File metadata and controls
48 lines (42 loc) · 879 Bytes
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
#!/bin/sh
BUILDDIR=lib
die() {
echo "!!! $* !!!" >&2
exit 1
}
if ! git diff --quiet; then
die Repo is not clean
fi
CURRENT=$(git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/^\* //')
ORIGIN=$(git config branch."$CURRENT".remote)
if [ -z "$ORIGIN" ]; then
die "Cannot determine origin, are you on a branch?"
fi
if [ -n "$1" ]; then
CURRENT=$1
fi
B=${CURRENT}-build
echo "=== Building and pushing to $ORIGIN/$B ==="
if ! nps test; then
die Tests failed
fi
if ! nps build; then
die Could not build
fi
if ! git add -f $BUILDDIR; then
die Could not add to commit
fi
if ! git commit -m build; then
die Could not commit
fi
clean() {
# This undoes the last commit but leaves the build in place
git reset HEAD^
}
if ! git push -f "$ORIGIN" "HEAD:$B"; then
clean
die Could not push to "$ORIGIN/$B"
fi
if ! clean; then
die Could not clean temporary commit
fi