Created
October 9, 2017 12:11
-
-
Save shamim2883/ee383fe84eaece238e2e4c144bfce00e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# A modification of https://gist.github.com/kloon/6487562 | |
# The difference is that | |
# 1. Some error fix | |
# 2. Push only one tag | |
# 3. Does not download full repo from svn, download only trunk. | |
# main config | |
PLUGINSLUG="plugin-slug" # this should be the slug of your main wordpress plugin (folder name) | |
MAINFILE="plugin-main-file.php" # this should be the name of your main php file in the wordpress plugin | |
SVNUSER="user" # your svn username | |
CURRENTDIR=`pwd` | |
# 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="https://plugins.svn.wordpress.org/$PLUGINSLUG" # Remote SVN repo on wordpress.org, with no trailing slash | |
# Let's begin... | |
echo ".........................................." | |
echo | |
echo "Preparing to deploy 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 | |
NEWVERSION1=`grep "^Stable tag:" $GITPATH/readme.txt | awk -F' ' '{print $NF}'` | |
echo "readme.txt version: $NEWVERSION1" | |
NEWVERSION2=`grep "Version:" $GITPATH/$MAINFILE | awk -F' ' '{print $NF}'` | |
echo "$MAINFILE version: $NEWVERSION2" | |
NEWVERSION1="$(echo -e "${NEWVERSION1}" | tr -d '[:space:]')" | |
NEWVERSION2="$(echo -e "${NEWVERSION2}" | tr -d '[:space:]')" | |
if [ "$NEWVERSION1" != "$NEWVERSION2" ]; then echo "Version in readme.txt & $MAINFILE don't match. Exiting...."; exit 1; fi | |
echo "New Version $NEWVERSION1" | |
echo "Versions match in readme.txt and $MAINFILE. Let's proceed..." | |
if git show-ref --tags --quiet --verify -- "refs/tags/$NEWVERSION1" | |
then | |
echo "Version $NEWVERSION1 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 $NEWVERSION1 -m "Tagging version $NEWVERSION1" | |
echo "Pushing latest commit to origin, with tags" | |
git push origin master | |
git push origin $NEWVERSION1 | |
echo | |
echo "Creating local copy of SVN repo ..." | |
svn co $SVNURL/trunk $SVNPATH/trunk | |
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 | |
.gitattributes" "$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 '^?' | sed -e 's/^? *//' | xargs --no-run-if-empty -d '\n' svn add | |
svn commit --username=$SVNUSER -m "$COMMITMSG" | |
echo "Creating new SVN tag" | |
svn copy $SVNURL/trunk $SVNURL/tags/$NEWVERSION1 -m "Tagging version $NEWVERSION1" | |
echo "Removing temporary directory $SVNPATH" | |
rm -fr $SVNPATH | |
echo "*** FIN ***" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment