forked from SonarSource/sonar-developer-toolset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspush
executable file
·78 lines (65 loc) · 1.91 KB
/
spush
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
#!/bin/bash
# Unbreakable build
REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
REPO_NAME=${REPO_DIR##*/}
BUILD_DIR=$(mktemp -d -t ${REPO_NAME}.XXXXXXXX 2>/dev/null)
LOCATION=$(pwd)
REMOTE='origin'
REMOTE_URL=$(LC_ALL=en_US git remote show -n ${REMOTE} | awk '/Fetch/ {print $3}')
BRANCH=$(git symbolic-ref -q HEAD)
BRANCH=${BRANCH##refs/heads/}
function alert_user {
echo "${1}"
command -v notify-send >/dev/null 2>&1 && notify-send -t 3000 "${REPO_NAME}" "${1}"
command -v osascript >/dev/null 2>&1 && osascript -e "display notification \"${1}\" with title \"${REPO_NAME}\""
command -v growlnotify >/dev/null 2>&1 && growlnotify "${REPO_NAME}" -m "${1}"
command -v terminal-notifier >/dev/null 2>&1 && terminal-notifier -title "${REPO_NAME}" -message "${1}"
}
function exit_ko {
alert_user "${1}"; clean_build_dir; exit 1
}
function exit_ok {
alert_user "${1}"; exit 0
}
rollback_wip() {
git log -1 | grep -q -c "wip" && git reset HEAD~1
}
clean_build_dir() {
rm -rf ${BUILD_DIR}
}
# Git black magic to pull rebase even with uncommited work in progress
git fetch ${REMOTE}
git add -A; git ls-files --deleted -z | xargs -0 -I {} git rm {}; git commit -m "wip"
if ! git rebase ${REMOTE}/${BRANCH}; then
git rebase --abort
rollback_wip
exit_ko "Unable to rebase. please pull or rebase and fix conflicts manually."
fi
rollback_wip
# Private build
git clone --single-branch -slb "${BRANCH}" . ${BUILD_DIR}
cd ${BUILD_DIR}
# Build
if [ -f 'build.sh' ]
then
sh ./build.sh ${1}
elif [ -f 'build.gradle' ]
then
./gradlew build ${1}
elif [ -f 'pom.xml' ]
then
mvn clean install ${1}
else
exit_ko "Don't know how to build. No pom.xml nor build.sh."
fi
if [ $? -ne 0 ]; then
exit_ko "Unable to build"
fi
# Push
if ! git push ${REMOTE_URL} ${BRANCH}; then
exit_ko "Unable to push"
fi
# Update working directory
cd ${LOCATION} && git fetch ${REMOTE}
clean_build_dir
exit_ok "Yet another successful build!"