morganestes
9/20/2013 - 2:29 PM

plugin-deploy.sh

#!/bin/bash

# args
MSG=${1-'deploy from git'}
BRANCH=${2-'trunk'}

# paths
SRC_DIR=$(git rev-parse --show-toplevel)
DIR_NAME=$(basename $SRC_DIR)
DEST_DIR=~/Sites/wp-plugins/$DIR_NAME/$BRANCH
ASSETS_DIR=~/Sites/wp-plugins/$DIR_NAME/assets

# 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 $file 2>/dev/null
done

# copy everything over from git
rsync -r --exclude='*.git*' $SRC_DIR/* $DEST_DIR

cd $DEST_DIR

# check .svnignore
for file in $(cat "$SRC_DIR/.svnignore" 2>/dev/null)
do
	rm $file -rf
done

# Transform the readme - assumes in root with .md extension
README=$DEST_DIR/README.md
sed -i '' -e 's/^# \(.*\)$/=== \1 ===/' -e 's/ #* ===$/ ===/' -e 's/^## \(.*\)$/== \1 ==/' -e 's/ #* ==$/ ==/' -e 's/^### \(.*\)$/= \1 =/' -e 's/ #* =$/ =/' $README

mv $README $DEST_DIR/readme.txt

# Copy assets over to the top-level assets directory and delete the extra directory
rsync -r --exclude='*.git*' $SRC_DIR/assets/* $ASSETS_DIR
rm -rf $DEST_DIR/assets

# svn addremove
svn stat | grep '^\?' | awk '{print $2}' | xargs svn add > /dev/null 2>&1
svn stat | grep '^\!' | awk '{print $2}' | xargs svn rm  > /dev/null 2>&1

svn stat

svn ci -m "$MSG"
#!/bin/bash

if [ $# -lt 1 ]; then
	echo 'usage: plugin-tag 1.2.3'
	exit
fi

TAG_NAME=$1

git tag $TAG_NAME
git push
git push --tags

plugin-deploy "tagging version $TAG_NAME" tags/$TAG_NAME