Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract exclude rules to separate files, abstract away from Gradle. #51

Merged
merged 3 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions mainframer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ function property {
grep "^${1}=" $PROJECT_DIR/local.properties | cut -d'=' -f2
}

function readExcludesFile {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s wrong with rsync --exclude-from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing, will try

if [ -f "$1" ]; then
EXCLUDES=""

# Second part is a fallback in case if last line does not contain newline character.
while read -r line || [[ -n "$line" ]]
do
# Do not process empty lines.
if [ ! -z "$line" ]; then
EXCLUDES+="--exclude=\"$line\" "
fi
done < "$1"

echo "$EXCLUDES"
else
echo ""
fi
}

pushd "$PROJECT_DIR"

# Read config variables from local.properties.
REMOTE_BUILD_MACHINE=$(property 'remote_build.machine')
LOCAL_COMPRESS_LEVEL=$(property 'remote_build.local_gzip_level')
Expand All @@ -40,32 +61,21 @@ if [ -z "$BUILD_COMMAND" ]; then
exit 1
fi

pushd "$PROJECT_DIR"
# Read exclude rules.
LOCAL_EXCLUDE="$(readExcludesFile .mainframerignorelocal)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that. What about .mainframerlocalignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #54. I'd vote for current names at the moment and then if we decide to move configs into a separate folder -> rename this files, names are not the point of this PR.

REMOTE_EXCLUDE="$(readExcludesFile .mainframerignoreremote)"

# Sync project to remote machine.
rsync --archive --delete --compress-level=$LOCAL_COMPRESS_LEVEL \
--exclude='.gradle' \
--exclude='.idea' \
--exclude='**/.git/' \
--exclude='artifacts' \
--exclude='captures' \
--exclude='**/build' \
--exclude='**/local.properties' \
--rsh "ssh" ./ "$REMOTE_BUILD_MACHINE:~/$PROJECT_DIR_NAME"
eval "rsync --archive --delete --compress-level=$LOCAL_COMPRESS_LEVEL $LOCAL_EXCLUDE --rsh ssh ./ $REMOTE_BUILD_MACHINE:~/$PROJECT_DIR_NAME"
Copy link
Contributor

@arturdryomov arturdryomov Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we can make this a function with four arguments. Not sure if it’s worth it though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for now


# Build project on a remote machine.
ssh $REMOTE_BUILD_MACHINE "echo 'set -xe && cd ~/$PROJECT_DIR_NAME/ && $BUILD_COMMAND' | bash"

# Sync project back to local machine.
rsync --archive --delete --compress-level=$REMOTE_COMPRESS_LEVEL \
--exclude='.gradle' \
--exclude='.idea' \
--exclude='**/.git/' \
--exclude='artifacts' \
--exclude='captures' \
--exclude='**/local.properties' \
--rsh "ssh" "$REMOTE_BUILD_MACHINE:~/$PROJECT_DIR_NAME/" ./
popd
eval "rsync --archive --delete --compress-level=$REMOTE_COMPRESS_LEVEL $REMOTE_EXCLUDE --rsh ssh $REMOTE_BUILD_MACHINE:~/$PROJECT_DIR_NAME/ ./"

BUILD_END_TIME=`date +%s`
echo "End time: $( date )"
echo "Whole process took `expr $BUILD_END_TIME - $BUILD_START_TIME` seconds."

popd
5 changes: 5 additions & 0 deletions samples/gradle/.mainframerignorelocal
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gradle
.idea
**/.git/
**/local.properties
**/build
5 changes: 5 additions & 0 deletions samples/gradle/.mainframerignoreremote
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gradle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Samples don’t entirely repeat what we have at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it's basic gradle sample, not gradle-android

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradle-android will make more sense since our userbase mostly consists of Android developers (for now).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in a separate pr.

.idea
**/.git/
**/local.properties
**/src/
1 change: 1 addition & 0 deletions samples/gradle/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
remote_build.machine=sample-remote-build-machine.com