Skip to content

Commit

Permalink
Add release and publish scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Apr 24, 2013
1 parent 2f0b8b8 commit a1b8712
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 0 deletions.
169 changes: 169 additions & 0 deletions publish.sh
@@ -0,0 +1,169 @@
#!/usr/bin/env bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

# Define
SANDBOX_URL=".rhcloud.com"
SANDBOX_SSH_USERNAME=""
SANDBOX_REPO="ssh://${SANDBOX_SSH_USERNAME}@${SANDBOX_URL}/~/git/site.git/"
SANDBOX_CHECKOUT_DIR=$DIR/_tmp/sandbox

# team email subject
EMAIL_SUBJECT="cdi-spec.org site released at \${PRODUCTION_URL}"
# email To ?
EMAIL_TO=""
EMAIL_FROM="\"cdi-spec.org Site Publish Script\" <benevides@redhat.com>"

JBORG_DIR="cdispec"
JBORG_REPO="filemgmt.jboss.org:www_htdocs"

STAGING_URL="cdi-spec.org/staging"
STAGING_DIR="${JBORG_DIR}/staging"

PRODUCTION_DIR="${JBORG_DIR}"
PRODUCTION_URL="www.cdi-spec.org"


notify_email()
{
echo "***** Performing cdi-spec.org site release notifications"
echo "*** Notifying cdi-dev list"
subject=`eval echo $EMAIL_SUBJECT`
echo "Email from: " $EMAIL_FROM
echo "Email to: " $EMAIL_TO
echo "Subject: " $subject
# send email using sendmail
printf "Subject: $subject\nSee \$subject :)\n" | /usr/bin/env sendmail -f "$EMAIL_FROM" "$EMAIL_TO"
}


shallow_clean() {
echo "**** Cleaning site ****"
rm -rf $DIR/_site
echo "**** Cleaning asciidoc cache ****"
rm -rf $DIR/_tmp/asciidoc
}

deep_clean() {
echo "**** Cleaning site ****"
rm -rf $DIR/_site
echo "**** Cleaning caches ****"
rm -rf $DIR/_tmp/lanyrd
rm -rf $DIR/_tmp/remote_partial
rm -rf $DIR/_tmp/datacache
rm -rf $DIR/_tmp/restcache
rm -rf $DIR/_tmp/asciidoc
}

sandbox() {
shallow_clean
echo "**** Generating site ****"
awestruct -Psandbox

if [ ! -d "$SANDBOX_CHECKOUT_DIR/.git" ]; then
echo "**** Cloning OpenShift repo ****"
mkdir -p $SANDBOX_CHECKOUT_DIR
git clone $SANDBOX_REPO $SANDBOX_CHECKOUT_DIR
fi

cp -rf $DIR/_site/* $SANDBOX_CHECKOUT_DIR/php


echo "**** Publishing site to http://${SANDBOX_URL} ****"
cd $SANDBOX_CHECKOUT_DIR
git add *
git commit -a -m"deploy"
git push -f
shallow_clean
}

production() {
deep_clean
echo "**** Generating site ****"
awestruct -Pproduction

echo "\n**** Publishing site to http://${PRODUCTION_URL} ****"
rsync -Pqr --protocol=28 --delete-after --exclude=presentations $DIR/_site/* ${JBORG_DIR}@${JBORG_REPO}/${PRODUCTION_DIR}

shallow_clean

read -p "Do you want to send release notifcations to $EMAIL_TO[y/N]? " yn
case $yn in
[Yy]* ) notify_email;;
* ) exit;
esac
}

staging() {
deep_clean
echo "**** Generating site ****"
awestruct -Pstaging

echo "**** Publishing site to http://${STAGING_URL} ****"
rsync -Pqr --protocol=28 --delete-after --exclude=presentations $DIR/_site/* ${JBORG_DIR}@${JBORG_REPO}/${STAGING_DIR}

shallow_clean
}

clear_staging() {
echo "**** Removing staging site from http://${STAGING_URL}"
rm -rf _site
mkdir _site
rsync -Pqr --protocol=28 --delete $DIR/_site/ ${JBORG_DIR}@${JBORG_REPO}/${STAGING_DIR}
}


usage() {
cat << EOF
usage: $0 options
This script publishes the cdi-spec.org site, either to sandbox, staging or to production
OPTIONS:
-d Publish *sandbox* version of the site to http://${SANDBOX_URL}
-s Publish staging version of the site to http://${STAGING_URL}
-p Publish production version of the site to http://${PRODUCTION_URL}
-c Clear out all caches
-r Remove the staging version of the site from http://${STAGING_URL} - please do this after using staging
EOF
}

while getopts "spdchr" OPTION

do
case $OPTION in
s)
staging
exit
;;
r)
clear_staging
exit
;;

d)
sandbox
exit
;;
p)
production
exit
;;
c)
deep_clean
exit
;;
h)
usage
exit
;;
[?])
usage
exit
;;
esac
done

usage
75 changes: 75 additions & 0 deletions release-utils.sh
@@ -0,0 +1,75 @@
#!/bin/bash

REQUIRED_BASH_VERSION=3.0.0

if [[ $BASH_VERSION < $REQUIRED_BASH_VERSION ]]; then
echo "You must use Bash version 3 or newer to run this script"
exit
fi

DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)


# DEFINE

VERSION_REGEX='([0-9]*)\.([0-9]*)([a-zA-Z0-9\.]*)'

# SCRIPT

usage()
{
cat << EOF
usage: $0 options
This script aids in releasing the cdi-spec.org site
OPTIONS:
-u Updates version numbers in all POMs, used with -o and -n
-o Old version number to update from
-n New version number to update to
-h Shows this message
EOF
}

parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}

update()
{
cd $DIR/
echo "Updating versions from $OLDVERSION TO $NEWVERSION for all Java and XML files under $PWD"
perl -pi -e "s/version: ${OLDVERSION}/version: ${NEWVERSION}/g" _config/site.yml
}

OLDVERSION="1.0.0-SNAPSHOT"
NEWVERSION="1.0.0-SNAPSHOT"
VERSION="1.0.0-SNAPSHOT"
CMD="usage"

while getopts “uo:n:” OPTION

do
case $OPTION in
u)
CMD="update"
;;
h)
usage
exit
;;
o)
OLDVERSION=$OPTARG
;;
n)
NEWVERSION=$OPTARG
;;
[?])
usage
exit
;;
esac
done

$CMD

87 changes: 87 additions & 0 deletions release.sh
@@ -0,0 +1,87 @@
#!/bin/bash

REQUIRED_BASH_VERSION=3.0.0

if [[ $BASH_VERSION < $REQUIRED_BASH_VERSION ]]; then
echo "You must use Bash version 3 or newer to run this script"
exit
fi

DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)

# DEFINE

VERSION_REGEX='([0-9]*)\.([0-9]*)([a-zA-Z0-9\.]*)'


# SCRIPT

usage()
{
cat << EOF
usage: $0 options
This script performs a release the cdi-spec.org site
OPTIONS:
-s Snapshot version number to update from
-n New snapshot version number to update to, if undefined, defaults to the version number updated from
-r Release version number
EOF
}

release()
{
echo "Releasing cdi-spec.org site version $RELEASEVERSION"
$DIR/release-utils.sh -u -o $SNAPSHOTVERSION -n $RELEASEVERSION
git commit -a -m "Prepare for $RELEASEVERSION release"
git tag -a $RELEASEVERSION -m "Tag $RELEASEVERSION"
$DIR/publish.sh -p
$DIR/release-utils.sh -u -o $RELEASEVERSION -n $NEWSNAPSHOTVERSION
git commit -a -m "Prepare for development of $NEWSNAPSHOTVERSION"
}

SNAPSHOTVERSION="UNDEFINED"
RELEASEVERSION="UNDEFINED"
NEWSNAPSHOTVERSION="UNDEFINED"
MAJOR_VERSION="UNDEFINED"
MINOR_VERSION="UNDEFINED"

while getopts “hn:r:s:” OPTION

do
case $OPTION in
h)
usage
exit
;;
s)
SNAPSHOTVERSION=$OPTARG
;;
r)
RELEASEVERSION=$OPTARG
;;
n)
NEWSNAPSHOTVERSION=$OPTARG
;;
[?])
usage
exit
;;
esac
done

if [ "$NEWSNAPSHOTVERSION" == "UNDEFINED" ]
then
NEWSNAPSHOTVERSION=$SNAPSHOTVERSION
fi

if [ "$SNAPSHOTVERSION" == "UNDEFINED" -o "$RELEASEVERSION" == "UNDEFINED" ]
then
echo "\nMust specify -r and -s\n"
usage
exit
fi

release

0 comments on commit a1b8712

Please sign in to comment.