Created
April 7, 2015 10:59
-
-
Save ideag/534e71882a470fcc6128 to your computer and use it in GitHub Desktop.
Publishes from git repository to wordpress.org plugin directory via svn. It expects the git repo to sit in /git subfolder.
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 | |
# args | |
VERSION=${1} | |
MSG=${2-'Deploy from git'} | |
COMMIT=${3-true} | |
UPDATE_ALL=${4-true} | |
if [ ! ${VERSION} ]; then | |
echo 'Error: no version given' | |
exit | |
fi | |
BASEDIR=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd) | |
SLUG=$(basename $BASEDIR) | |
SRC_DIR=${BASEDIR}/git | |
DEST_DIR=${BASEDIR}/svn | |
cd $SRC_DIR | |
if [ ! $(git tag --list $VERSION) ]; then | |
echo 'Error: wrong version' | |
git add * | |
git commit -a -m "version ${VERSION}: ${MSG}" | |
git tag ${VERSION} | |
git push origin master --tags | |
fi | |
echo 'Building SVN from GIT' | |
# 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 SVN repo exists | |
if [ ! -d "${BASEDIR}/svn" ]; then | |
echo "Coudn't find the SVN repo at ${BASEDIR}/svn. Trying to create one..." | |
svn co http://plugins.svn.wordpress.org/$SLUG/ ${BASEDIR}/svn | |
exit | |
fi | |
if [ ${UPDATE_ALL} ]; then | |
TAGS=$(git tag) | |
for TAG in ${TAGS[@]} | |
do | |
echo ${TAG##v} | |
TAG_DIR=${DEST_DIR}/tags/${TAG##v} | |
if [ ! -d "${TAG_DIR}" ]; then | |
mkdir ${TAG_DIR} | |
fi | |
rm -rf ${TAG_DIR}/* | |
git archive --format=tar ${TAG} | tar -C ${TAG_DIR} -xf - | |
# check .svnignore | |
for file in $(cat "$TAG_DIR/.svnignore" 2> /dev/null) | |
do | |
rm -rf $TAG_DIR/$file | |
done | |
done | |
else | |
echo ${VERSION##v} | |
TAG_DIR=${DEST_DIR}/tags/${VERSION##v} | |
if [ ! -d "${TAG_DIR}" ]; then | |
mkdir ${TAG_DIR} | |
fi | |
rm -rf ${TAG_DIR}/* | |
git archive --format=tar ${VERSION} | tar -C ${TAG_DIR} -xf - | |
# check .svnignore | |
for file in $(cat "$TAG_DIR/.svnignore" 2> /dev/null) | |
do | |
rm -rf $TAG_DIR/$file | |
done | |
fi | |
SVN_TRUNK=${DEST_DIR}/trunk | |
rm -rf ${SVN_TRUNK}/* | |
git archive --format=tar ${VERSION} ./readme.txt | tar -C ${SVN_TRUNK} -xf - | |
rm -rf ${DEST_DIR}/assets/* | |
git archive --format=tar assets | tar -C ${DEST_DIR}/assets -xf - | |
cd $DEST_DIR | |
# 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/ #* =$/ =/' 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 | |
if [ ${COMMIT} ]; then | |
svn ci -m "$VERSION: $MSG" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment