Last active
October 28, 2016 12:32
-
-
Save mthadley/0a13cd1c2ac6d61a64297613dc484d58 to your computer and use it in GitHub Desktop.
Update Script, USE AT YOUR OWN PERIL
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
#!/usr/bin/env sh | |
# | |
# Pulls down changes in each Repo | |
# | |
read -r -d '' USAGE << 'END_USAGE' | |
usage: ./update-cloud.sh [-uh] [-g "gradle tasks"] | |
u : pull down master changes in each module | |
g : run gradle task in each folder | |
./update-cloud.sh -g "clean deploy" | |
h : print help | |
END_USAGE | |
set -e | |
set -o pipefail | |
# | |
# If you only have a single remote, just comment out | |
# ORIGIN_REMOTE and ORIGIN_BRANCH. If this is true, you | |
# probably also want to change UPSTREAM_REMOTE to "origin" | |
# as wel. | |
# | |
UPSTREAM_REMOTE="upstream" | |
UPSTREAM_BRANCH="master" | |
ORIGIN_REMOTE="origin" | |
ORIGIN_BRANCH="master" | |
REPOS=( | |
"com-liferay-dxp-cloud-site" | |
"com-liferay-dxp-cloud-site-assets" | |
"com-liferay-dxp-cloud-site-campaigns" | |
"com-liferay-dxp-cloud-site-contacts" | |
"com-liferay-dxp-cloud-site-touchpoints" | |
) | |
ORIG_PWD="$PWD" | |
UPDATE=false | |
GRADLE=false | |
GRADLE_PARAMS="" | |
while getopts "ug:h" OPT; do | |
case $OPT in | |
u) | |
UPDATE=true | |
;; | |
g) | |
GRADLE=true | |
GRADLE_PARAMS="$OPTARG" | |
;; | |
h) | |
echo "$USAGE" | |
exit 0 | |
;; | |
\?) | |
echo "$USAGE" | |
exit 1 | |
esac | |
done | |
if ! $UPDATE && ! $DEPLOY; then | |
echo "Nothing to do..." | |
echo "$USAGE" | |
exit 0 | |
fi | |
if $UPDATE; then | |
# Check if any are Dirty... | |
for REPO in "${REPOS[@]}"; do | |
cd "$REPO" | |
if [[ -n $(git diff --diff-filter=x --name-only) ]]; then | |
echo "Repo: $REPO is dirty, aborting..." | |
exit 1 | |
fi | |
cd "$ORIG_PWD" | |
done | |
# Update each Repo... | |
for REPO in "${REPOS[@]}"; do | |
echo "Updating $REPO" | |
cd "$REPO" | |
if [[ -z $(git remote | grep "$UPSTREAM_REMOTE") ]]; then | |
echo "Upstream remote \"$UPSTREAM_REMOTE\" not found, aborting..." | |
cd "$ORIG_PWD" | |
exit 1 | |
fi | |
git checkout "$UPSTREAM_BRANCH" | |
git pull "$UPSTREAM_REMOTE" "$UPSTREAM_BRANCH" | |
if [[ | |
-n "$ORIGIN_REMOTE" && | |
-n "$ORIGIN_BRANCH" && | |
-n $(git remote | grep "$ORIGIN_REMOTE") | |
]]; then | |
git push "$ORIGIN_REMOTE" "$ORIGIN_BRANCH" | |
fi | |
cd "$ORIG_PWD" | |
done | |
fi | |
if $GRADLE; then | |
for REPO in "${REPOS[@]}"; do | |
cd "$REPO" | |
GRADLE_EXEC=$(git rev-parse --show-toplevel 2>/dev/null) | |
if [[ -n "$GRADLE_EXEC" && -f "$GRADLE_EXEC/gradlew" ]]; then | |
GRADLE_EXEC="$GRADLE_EXEC/gradlew" | |
else | |
GRADLE_EXEC=$(which gradle) | |
fi | |
"$GRADLE_EXEC" "$GRADLE_PARAMS" | |
cd "$ORIG_PWD" | |
done | |
fi | |
echo "Done." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment