Last active
February 3, 2016 09:47
-
-
Save lesterchan/4f2bf09d5d1b4e734f81 to your computer and use it in GitHub Desktop.
WordPress Plugin Deploy From GitHub to SVN
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
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified from https://gist.github.com/scribu/1125050