Last active
August 9, 2018 20:14
-
-
Save kasparsd/c040cf3865863cb99b3d25b47ff0b42a to your computer and use it in GitHub Desktop.
Deploy script for WordPress VIP
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 bash | |
# Set this to -ex for verbose output. | |
set -e | |
# Set the working directory to the repository root. | |
cd "$(dirname "$0")/.." | |
DEPLOY_BRANCH="$2" | |
SVN_REPO="$1" | |
REPO_SLUG=$(basename $SVN_REPO) | |
DIST_SVN="$PWD/deploy/svn/$REPO_SLUG" | |
DIST_GIT="$PWD/deploy/git" | |
# Ensure we don't corrupt the local development repository. | |
echo "Copying the Git repository to $DIST_GIT" | |
rm -rf "$DIST_GIT" | |
mkdir -p "$DIST_GIT" | |
cp -r "$PWD/.git" "$DIST_GIT/" | |
export GIT_DIR="$DIST_GIT/.git" | |
export GIT_WORK_TREE="$DIST_GIT" | |
# Checkout the deploy branch | |
echo "Checking out Git branch $DEPLOY_BRANCH" | |
git checkout -f "$DEPLOY_BRANCH" | |
git clean -d --force | |
git reset --hard | |
git pull | |
# Clone the SVN upstream. | |
echo "Fetching the latest changes from the SVN repository:" | |
mkdir -p "$DIST_SVN" | |
svn checkout $SVN_REPO "$DIST_SVN" | |
svn revert --recursive "$DIST_SVN" | |
svn update --force "$DIST_SVN" | |
echo "Please review the latest commits on SVN:" | |
svn log --limit 5 "$DIST_SVN" | |
read -r -p "Are there any commits that need to be merged in before deploying your changes? Enter 'no' if nothing need to be merged: " CONFIRM_SVN_UPSTREAM_CHANGES | |
if [ "no" != "$CONFIRM_SVN_UPSTREAM_CHANGES" ]; then | |
echo "Aborting to merge in upstream changes manually." | |
exit 1 | |
fi | |
# Use .distignore to exclude files from the build. | |
if [ -f "$DIST_GIT/.distignore" ]; then | |
DIST_IGNORE="$DIST_GIT/.distignore" | |
fi | |
echo "Copying over updates from Git to SVN:" | |
rsync -a --delete ${DIST_IGNORE:+ --exclude-from "$DIST_IGNORE"} "$DIST_GIT/" "$DIST_SVN" | |
# Move into SVN directory because we can't pass it to svn add/rm through xargs | |
cd "$DIST_SVN" | |
# SVN add and remove. | |
svn stat | awk '/^\?/ {print $2}' | xargs svn add > /dev/null 2>&1 | |
svn stat | awk '/^\!/ {print $2}' | xargs svn delete --force | |
SVN_DIFF=$(svn status -q "$DIST_SVN") | |
if [ -z "$SVN_DIFF" ]; then | |
echo "Nothing to deploy, aborting!" | |
exit 1 | |
fi | |
echo "Deploy to: $(svn info --show-item repos-root-url)" | |
echo "Current SVN diff summary:" | |
svn diff --summarize "$DIST_SVN" | |
# Ask for deploy message | |
read -r -p "Please enter the commit message: " COMMIT_MSG | |
# Ask for username to confirm the deploy. | |
read -r -p "Please enter '$USER' to confirm the deploy: " COMMIT_CONFIRM | |
if [ "$COMMIT_CONFIRM" == "$USER" ]; then | |
echo "Deploying!" | |
svn commit -m "$COMMIT_MSG" | |
else | |
echo "Deploy aborted!" | |
fi |
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 bash | |
# Set this to -ex for verbose output. | |
set -e | |
# Set the working directory to the repository root. | |
cd "$(dirname "$0")/.." | |
SVN_REPO="$1" | |
SVN_REVISION_TO="$2" | |
if [ -z "$SVN_REVISION_TO" ]; then | |
echo "Please specify the revision to revert to." | |
exit 1 | |
fi | |
REPO_SLUG=$(basename $SVN_REPO) | |
DIST_SVN="$PWD/deploy/svn/$REPO_SLUG" | |
# Clone the SVN upstream. | |
echo "Fetching the latest changes from the SVN repository:" | |
mkdir -p "$DIST_SVN" | |
svn checkout $SVN_REPO "$DIST_SVN" | |
svn revert --recursive "$DIST_SVN" | |
svn update --force "$DIST_SVN" | |
# Get the latest revision that has been deployed. | |
SVN_REVISION_NOW=$(svn info --show-item revision "$DIST_SVN" | tr -d [:space:]) | |
# Revert locally. | |
echo "Reverting to $SVN_REVISION_TO on $SVN_REPO" | |
svn merge --revision "$SVN_REVISION_NOW:$SVN_REVISION_TO" "$DIST_SVN" "$DIST_SVN" | |
# Ask for username to confirm the deploy. | |
read -r -p "Please enter '$USER' to confirm the revert: " COMMIT_CONFIRM | |
if [ "$COMMIT_CONFIRM" == "$USER" ]; then | |
echo "Reverting to $SVN_REVISION_TO" | |
svn commit -m "Reverting to $SVN_REVISION_TO" "$DIST_SVN" | |
else | |
echo "Revert aborted!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment