-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gradle-remote to execute gradle builds on a build server
- Loading branch information
Wolf Montwe
committed
Jan 21, 2025
1 parent
5175031
commit b0b8246
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
# This script serves as a drop-in replacement for running Gradle tasks locally. | ||
# It automates the process of building a Gradle project on a remote server by synchronizing local files, | ||
# executing specified Gradle tasks remotely, and copying all build outputs back to your local machine. | ||
|
||
# Disclaimer | ||
echo "Please note that this script is quite basic and not recommended for use with public build servers." | ||
echo "Since rsync transfers all files from the developer's machine, including potentially sensitive information" | ||
echo "like secrets or configuration files, it should be used with care." | ||
|
||
if ! [ -f build.gradle.kts ]; then | ||
echo "No build.gradle.kts found" | ||
exit 1 | ||
fi | ||
|
||
remote=$GRADLE_REMOTE_SSH | ||
if [ -z "$remote" ]; then | ||
echo "\$GRADLE_REMOTE_SSH is not set, please set it to a valid SSH login on your build server" | ||
exit 1 | ||
fi | ||
|
||
remote_dir=$GRADLE_REMOTE_DIR | ||
if [ -z "$remote_dir" ]; then | ||
echo "\$GRADLE_REMOTE_DIR is not set, please set it to the directory where the project should be copied on the remote server" | ||
exit 1 | ||
fi | ||
|
||
remote_project_dir="$remote_dir/$(basename "$(dirname "$PWD")")_$(basename "$PWD")" | ||
|
||
set -e | ||
|
||
# Define rsync exclusions | ||
exclusions=( | ||
--exclude .git/ | ||
--exclude .github/ | ||
--exclude .gradle/ | ||
--exclude .idea/ | ||
--exclude .kotlin/ | ||
--exclude .signing/ | ||
--exclude metadata | ||
--exclude build/ | ||
) | ||
|
||
# Define rsync inclusions | ||
inclusions=( | ||
--include .gradle/gradle.properties | ||
) | ||
|
||
# Copy the project to the remote server, excluding specified paths but including gradle properties | ||
rsync -irc "${exclusions[@]}" "${inclusions[@]}" --delete . "$remote:$remote_project_dir" | ||
|
||
# Run the gradle command on the remote | ||
ssh -t "$remote" "cd $remote_project_dir && ./gradlew $*" | ||
|
||
# Copy the build directory back | ||
rsync --delete -ircuq "$remote:$remote_project_dir/build" . | (grep -v '/$' || true) |