-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradle-remote
executable file
·34 lines (28 loc) · 1.11 KB
/
gradle-remote
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
#!/bin/bash
# we need bash, not just posix shell for some types of expansions
# search upwards in file hierarchy for build.gradle
while [ "$PWD" != / ] && [ ! -f build.gradle ]; do
cd "$(dirname "$PWD")"
done
if ! [ -f build.gradle ]; then
printf '%s\n' 'No build.gradle file found'
exit 1
fi
remote="$GRADLE_REMOTE_SSH"
if [ -z "$remote" ]; then
printf '%s\n' 'Set GRADLE_REMOTE_SSH to a valid ssh login on your build server'
exit 1
fi
remotehome="$GRADLE_REMOTE_DIR"
if [ -z "$remotehome" ]; then
printf '%s\n' 'Set GRADLE_REMOTE_DIR to the place where projects will be stored on the server'
exit 1
fi
remotedir="$remotehome/${PWD////_}"
set -e
rsync -ircu --exclude build --exclude .gradle --exclude '**.swp' --delete . "$remote:$remotedir"
# https://stackoverflow.com/questions/6592376/prevent-ssh-from-breaking-up-shell-script-parameters
# ssh argument expansion is pure unfiltered cancer
# TODO - pass the command through stdin instead
ssh -t "$remote" "source .profile; " gradle -p "$remotedir" "${@@Q}" " && mkdir -p $remotedir/build"
rsync --delete -ircuq "$remote:$remotedir/build" . | (grep -v '/$' || true)