Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Last active August 29, 2015 14:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidWells/1388002253e4c95e0037 to your computer and use it in GitHub Desktop.
Save DavidWells/1388002253e4c95e0037 to your computer and use it in GitHub Desktop.
Deploying WordPress Plugin to Github and then to WordPress.org SVN
#! /bin/bash
# A modification of Dean Clatworthy's deploy script as found here: https://github.com/deanc/wordpress-plugin-git-svn
# The difference is that this script lives in the plugin's git repo & doesn't require an existing SVN repo.
# Instructions
#
# Important!!!!!
# Replace YOUR-WORDPRESS-PLUGIN-SLUG-HERE, YOUR-WORDPRESS-MAIN-PLUGIN-FILE-HERE, YOUR_WORDPRESS_USERNAME_HERE with yours
# End Important!!!!!
#
# Then follow these steps:
#
# 1. Add this file to your root folder of your WordPress Plugin
# 2. Update 'NEWVERSIONNUM' with correct version number on line 19. Example: NEWVERSIONNUM=1.0.2
# 3. then run below command in terminal (with no # in front of it)
# ./deploy.sh
# 4. (if you know have github ssh keys setup) Enter github username and password twice and magic happens
NEWVERSIONNUM=1.0.1
# main config
PLUGINSLUG="YOUR-WORDPRESS-PLUGIN-SLUG-HERE"
CURRENTDIR=`pwd`
MAINFILE="YOUR-WORDPRESS-MAIN-PLUGIN-FILE-HERE.php" # this should be the name of your main php file in the wordpress plugin
# git config
GITPATH="$CURRENTDIR/" # this file should be in the base of your git repository
# svn config
SVNPATH="/tmp/$PLUGINSLUG" # path to a temp SVN repo. No trailing slash required and don't add trunk.
SVNURL="http://plugins.svn.wordpress.org/YOUR-WORDPRESS-PLUGIN-SLUG-HERE/" # Remote SVN repo on wordpress.org, with no trailing slash
SVNUSER="YOUR_WORDPRESS_USERNAME_HERE" # your svn username
# Let's begin...
echo ".........................................."
echo
echo "Preparing to deploy your WordPress plugin"
echo
echo ".........................................."
echo
# Check version in readme.txt is the same as plugin file after translating both to unix line breaks to work around grep's failure to identify mac line breaks
echo "New version: $NEWVERSIONNUM"
CURRENTVERSIONNUM=`grep "^Version:" $GITPATH/$MAINFILE | awk -F' ' '{print $NF}'`
echo "$MAINFILE version: $CURRENTVERSIONNUM"
if [ "$CURRENTVERSIONNUM" != "$CURRENTVERSIONNUM" ]; then echo "Version in readme.txt & $MAINFILE don't match. Exiting...."; exit 1; fi
echo "Versions match in readme.txt and $MAINFILE. Let's proceed..."
if git show-ref --tags --quiet --verify -- "refs/tags/$NEWVERSIONNUM"
then
echo "Version $NEWVERSIONNUM already exists as git tag. Exiting....";
exit 1;
else
echo "Git version does not exist. Let's proceed..."
fi
cd $GITPATH
echo -e "Enter a commit message for this new version: \c"
read COMMITMSG
git commit -am "$COMMITMSG"
echo "Tagging new version in git"
git tag -a "$NEWVERSIONNUM" -m "Tagging version $NEWVERSIONNUM"
echo "Pushing latest commit to origin, with tags"
git push origin master
git push origin master --tags
echo
echo "Creating local copy of SVN repo ..."
svn co $SVNURL $SVNPATH
echo "Exporting the HEAD of master from git to the trunk of SVN"
git checkout-index -a -f --prefix=$SVNPATH/trunk/
echo "Ignoring github specific files and deployment script"
svn propset svn:ignore "deploy.sh
README.md
.git
.gitignore" "$SVNPATH/trunk/"
echo "Changing directory to SVN and committing to trunk"
cd $SVNPATH/trunk/
# Add all new files that are not set to be ignored
svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add
svn commit --username=$SVNUSER -m "$COMMITMSG"
echo "Creating new SVN tag & committing it"
cd $SVNPATH
svn copy trunk/ tags/$NEWVERSIONNUM/
cd $SVNPATH/tags/$NEWVERSIONNUM
svn commit --username=$SVNUSER -m "Tagging version $NEWVERSIONNUM"
echo "Removing temporary directory $SVNPATH"
rm -fr $SVNPATH/
echo "*** FINISHED YOUR PLUGIN IS DEPLOYED! ***"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment