Advertisement
helgatheviki

Bash Script for deploying git to WordPress SVN

Apr 4th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.96 KB | None | 0 0
  1. #! /bin/bash
  2. # A modification of Dean Clatworthy's deploy script as found here: https://github.com/deanc/wordpress-plugin-git-svn
  3. # The difference is that this script lives in the plugin's git repo & doesn't require an existing SVN repo.
  4. # source: https://gist.github.com/3767319
  5.  
  6. # main config
  7. PLUGINSLUG="nav-menu-roles"
  8. CURRENTDIR=`pwd`
  9. MAINFILE="$PLUGINSLUG.php" # this should be the name of your main php file in the wordpress plugin
  10.  
  11. # git config
  12. GITPATH="$CURRENTDIR/" # this file should be in the base of your git repository
  13.  
  14. # svn config
  15. SVNPATH="C:/Users/helga/wamp/www/localhost/tmp/$PLUGINSLUG" # path to a temp SVN repo. No trailing slash required and don't add trunk.
  16. SVNURL="http://plugins.svn.wordpress.org/$PLUGINSLUG/" # Remote SVN repo on wordpress.org, with no trailing slash
  17. SVNUSER="helgatheviking" # your svn username
  18.  
  19.  
  20. # Let's begin...
  21. echo ".........................................."
  22. echo
  23. echo "Preparing to deploy wordpress plugin"
  24. echo
  25. echo ".........................................."
  26. echo
  27.  
  28. # Check version in readme.txt is the same as plugin file
  29. NEWVERSION1=`grep "^Stable tag" $GITPATH/readme.txt | awk -F' ' '{print $3}'`
  30. echo "readme version: $NEWVERSION1"
  31. NEWVERSION2=`grep "^Version" $GITPATH/$MAINFILE | awk -F' ' '{print $2}'`
  32. echo "$MAINFILE version: $NEWVERSION2"
  33.  
  34. if [ "$NEWVERSION1" != "$NEWVERSION2" ]; then echo "Versions don't match. Exiting...."; exit 1; fi
  35.  
  36. echo "Versions match in readme.txt and PHP file. Let's proceed..."
  37.  
  38. cd $GITPATH
  39. echo -e "Enter a commit message for this new version: \c"
  40. read COMMITMSG
  41. git commit -am "$COMMITMSG"
  42.  
  43. echo "Tagging new version in git"
  44. git tag -a "$NEWVERSION1" -m "Tagging version $NEWVERSION1"
  45.  
  46. echo "Pushing latest commit to origin, with tags"
  47. git push origin master
  48. git push origin master --tags
  49.  
  50. echo
  51. echo "Creating local copy of SVN repo ..."
  52. svn co $SVNURL $SVNPATH
  53.  
  54. echo "Exporting the HEAD of master from git to the trunk of SVN"
  55. git checkout-index -a -f --prefix=$SVNPATH/trunk/
  56.  
  57. echo "Ignoring github specific & deployment script"
  58. svn propset svn:ignore "deploy.sh
  59. README.md
  60. .git
  61. .gitignore" "$SVNPATH/trunk/"
  62.  
  63. echo "Moving assets-wp-repo"
  64. mkdir $SVNPATH/assets/
  65. mv $SVNPATH/trunk/assets-wp-repo/* $SVNPATH/assets/
  66. svn add $SVNPATH/assets/
  67. svn delete $SVNPATH/trunk/assets-wp-repo
  68.  
  69. echo "Changing directory to SVN"
  70. cd $SVNPATH/trunk/
  71. # Add all new files that are not set to be ignored
  72. svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add
  73. echo "committing to trunk"
  74. svn commit --username=$SVNUSER -m "$COMMITMSG"
  75.  
  76. echo "Updating WP plugin repo assets & committing"
  77. cd $SVNPATH/assets/
  78. svn commit --username=$SVNUSER -m "Updating wp-repo-assets"
  79.  
  80. echo "Creating new SVN tag & committing it"
  81. cd $SVNPATH
  82. svn copy trunk/ tags/$NEWVERSION1/
  83. cd $SVNPATH/tags/$NEWVERSION1
  84. svn commit --username=$SVNUSER -m "Tagging version $NEWVERSION1"
  85.  
  86. echo "Removing temporary directory $SVNPATH"
  87. rm -fr $SVNPATH/
  88.  
  89. echo "*** FIN ***"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement