Skip to content

Instantly share code, notes, and snippets.

@lesterchan
Last active February 3, 2016 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lesterchan/4f2bf09d5d1b4e734f81 to your computer and use it in GitHub Desktop.
Save lesterchan/4f2bf09d5d1b4e734f81 to your computer and use it in GitHub Desktop.
WordPress Plugin Deploy From GitHub to SVN
#!/bin/bash
# paths
SRC_DIR=$(git rev-parse --show-toplevel)
DIR_NAME=$(basename $SRC_DIR)
#MSG=${1-'Deploying $DIR_NAME from GitHub'}
#BRANCH=${2-'trunk'}
MSG="Deploying $DIR_NAME from GitHub"
BRANCH="trunk"
DEST_DIR=~/svn/wordpress_plugins/$DIR_NAME/$BRANCH
# build first
if [ -f "$SRC_DIR/bin/build" ]; then
$SRC_DIR/bin/build
fi
# make sure we're deploying from the right dir
if [ ! -d "$SRC_DIR/.git" ]; then
echo "$SRC_DIR doesn't seem to be a git repository"
exit
fi
# make sure the destination dir exists
svn mkdir $DEST_DIR 2> /dev/null
svn add $DEST_DIR 2> /dev/null
# delete everything except .svn dirs
for file in $(find $DEST_DIR/* -not -path "*.svn*")
do
rm -rf $file 2>/dev/null
done
# copy everything over from git
rsync --recursive --exclude='*.git*' --exclude='.idea' --exclude='.travis.yml' $SRC_DIR/* $DEST_DIR
cd $DEST_DIR
# check .svnignore
for file in $(cat "$SRC_DIR/.svnignore" 2> /dev/null)
do
rm -rf $DEST_DIR/$file
done
# Transform the readme
if [ -f README.md ]; then
mv README.md readme.txt
sed -i '' -e 's/^# \(.*\)$/=== \1 ===/' -e 's/ #* ===$/ ===/' -e 's/^## \(.*\)$/== \1 ==/' -e 's/ #* ==$/ ==/' -e 's/^### \(.*\)$/= \1 =/' -e 's/ #* =$/ =/' -e 's/```php/`/' -e 's/```/`/' readme.txt
#sed -i '' -e 's///g' readme.txt
fi
# svn addremove
svn stat | awk '/^\?/ {print $2}' | xargs svn add > /dev/null 2>&1
svn stat | awk '/^\!/ {print $2}' | xargs svn rm --force
svn stat
svn ci -m "$MSG"
@lesterchan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment