about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDave Collins <davec@conformal.com>2011-10-03 19:02:53 -0500
committerDave Collins <davec@conformal.com>2011-10-03 22:29:29 -0500
commit68a74b3ee0454313bcc5193135e6190023389664 (patch)
tree1ddd05ac379757ede723d57de73b8c8cc93a4339
parent1f146bc014ebd09e3c8c6a49c3970dca02b39e03 (diff)
downloadxombrero-68a74b3ee0454313bcc5193135e6190023389664.tar.gz
Add full versioning support with automatic release
-rw-r--r--Makefile9
-rwxr-xr-xbuildver.sh4
-rwxr-xr-x[-rw-r--r--]release.sh136
-rw-r--r--version.h32
-rwxr-xr-xversion.sh20
-rw-r--r--xxxterm.c16
6 files changed, 201 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 290f5f2..c284092 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,11 @@ GTK_CFLAGS!= pkg-config --cflags $(LIBS)
 GTK_LDFLAGS!= pkg-config --libs $(LIBS)
 CFLAGS+= $(GTK_CFLAGS) -Wall -pthread
 LDFLAGS+= $(GTK_LDFLAGS) -pthread
+BUILDVERSION != sh "${.CUDIR}/buildver.sh"
+.if !${BUILDVERSION} == ""
+CPPFLAGS+= -DXXXTERM_BUILDSTR=\"$(BUILDVERSION)\"
+.endif
+
 
 MANDIR= ${PREFIX}/man/man
 
@@ -38,7 +43,5 @@ beforeinstall:
 
 ${PROG} ${OBJS} beforedepend: ${.CURDIR}/javascript.h
 
-release: xxxterm xxxterm.cat1
-	@sh ${.CURDIR}/release.sh ${.CURDIR}
-
 .include <bsd.prog.mk>
+
diff --git a/buildver.sh b/buildver.sh
new file mode 100755
index 0000000..be2517b
--- /dev/null
+++ b/buildver.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+if [ -d .git ]; then
+	git describe --tags | tr -d '\n'
+fi
diff --git a/release.sh b/release.sh
index 171035b..d089e11 100644..100755
--- a/release.sh
+++ b/release.sh
@@ -1,13 +1,129 @@
 #!/bin/sh
 #
-# $xxxterm$
-# XXX This sucks, I know.  send me diffs to make it better
-#
+# Prepares a release:
+#   - Bumps version according to specified level (major, minor, or patch)
+#   - Updates all necessary headers new version
+#   - Commits the changes
+#   - Tags the release
+#   - Pushes changes to origin repository
+#   - Creates a release tarball
+
+PROJECT=xxxterm
+PROJECT_UC=$(echo $PROJECT | tr '[:lower:]' '[:upper:]')
+SCRIPT=$(basename $0)
+HEADER=version.h
+
+# verify params
+if [ $# -lt 1 ]; then
+	echo "usage: $SCRIPT {major | minor | patch}"
+	exit 1
+fi
+
+report_err()
+{
+	echo "$SCRIPT: error: $1" 1>&2
+	exit 1
+}
+
+
+CUR_DIR=$(pwd)
+cd "$(dirname $0)"
+
+# verify header exists
+if [ ! -f "$HEADER" ]; then
+	report_err "$HEADER does not exist"
+fi
+
+# verify valid release type
+RTYPE="$1"
+if [ "$RTYPE" != "major" -a "$RYPTE" != "minor" -a "$RTYPE" != "patch" ]; then
+	report_err "release type must be major, minor, or patch"
+fi
+
+# verify git is available
+if ! type git >/dev/null 2>&1; then
+	report_err "unable to find 'git' in the system path"
+fi
+
+# verify the git repository is on the master branch
+BRANCH=$(git branch | grep '\*' | cut -c3-)
+if [ "$BRANCH" != "master" ]; then
+	report_err "git repository must be on the master branch"
+fi
+
+# verify there are no uncommitted modifications prior to release modifications
+NUM_MODIFIED=$(git diff 2>/dev/null | wc -l | sed 's/^[ \t]*//')
+NUM_STAGED=$(git diff --cached 2>/dev/null | wc -l | sed 's/^[ \t]*//')
+if [ "$NUM_MODIFIED" != "0" -o "$NUM_STAGED" != "0" ]; then
+#	report_err "the working directory contains uncommitted modifications"
+	echo
+fi
+
+# get version
+PAT_PREFIX="(^#define[[:space:]]+${PROJECT_UC}"
+PAT_SUFFIX='[[:space:]]+)[0-9]+$'
+MAJOR=$(egrep "${PAT_PREFIX}_MAJOR${PAT_SUFFIX}" $HEADER | awk '{print $3}')
+MINOR=$(egrep "${PAT_PREFIX}_MINOR${PAT_SUFFIX}" $HEADER | awk '{print $3}')
+PATCH=$(egrep "${PAT_PREFIX}_PATCH${PAT_SUFFIX}" $HEADER | awk '{print $3}')
+if [ -z "$MAJOR" -o -z "$MINOR" -o -z "$PATCH" ]; then
+	report_err "unable to get version from $HEADER"
+fi
+
+# bump version according to level
+if [ "$RTYPE" = "major" ]; then
+	MAJOR=$(expr $MAJOR + 1)
+	MINOR=0
+	PATCH=0
+elif [ "$RTYPE" = "minor" ]; then
+	MINOR=$(expr $MINOR + 1)
+	PATCH=0
+elif [ "$RTYPE" = "patch" ]; then
+	PATCH=$(expr $PATCH + 1)
+fi
+PROJ_VER="$MAJOR.$MINOR.$PATCH"
+
+# update header with new version
+sed -E "
+    s/${PAT_PREFIX}_MAJOR${PAT_SUFFIX}/\1${MAJOR}/;
+    s/${PAT_PREFIX}_MINOR${PAT_SUFFIX}/\1${MINOR}/;
+    s/${PAT_PREFIX}_PATCH${PAT_SUFFIX}/\1${PATCH}/;
+" <"$HEADER" >"${HEADER}.tmp"
+
+# apply changes
+mv "${HEADER}.tmp" "$HEADER"
+
+# commit and tag
+TAG="${PROJECT_UC}_${MAJOR}_${MINOR}_${PATCH}"
+git commit -am "Prepare for release ${PROJ_VER}." ||
+    report_err "unable to commit changes"
+git tag -a "$TAG" -m "Release ${PROJ_VER}" || report_err "unable to create tag"
+
+# create temp working space and copy repo over
+TD=$(mktemp -d /tmp/release.XXXXXXXXXX)
+if [ ! -d "$TD" ]; then
+	report_err "unable to create temp directory"
+fi
+RELEASE_DIR="$PROJECT-$PROJ_VER"
+RELEASE_TAR="$PROJECT-$PROJ_VER.tar.gz"
+git clone . "$TD/$RELEASE_DIR" ||
+    report_err "unable to copy to $TD/$RELEASE_DIR"
+
+# cleanup repository files
+cd "$TD"
+if [ -d "$RELEASE_DIR" -a -d "$RELEASE_DIR/.git" ]; then
+        rm -rf "$RELEASE_DIR/.git"
+fi
+if [ -d "$RELEASE_DIR" -a -f "$RELEASE_DIR/.gitignore" ]; then
+        rm -f "$RELEASE_DIR/.gitignore"
+fi
+
+# make snap
+tar -zcf "$RELEASE_TAR" "$RELEASE_DIR" ||
+    report_err "unable to create $RELEASE_TAR"
+
 
-td=`mktemp -d /tmp/release.XXXXXXXXXX`
-cd $td
-cvs -d $(cat $1/CVS/Root) -Q export -D tomorrow xxxterm || exit 1
-REL=$(awk '/ .xxxterm: xxxterm.c,v/{print $4;}' xxxterm/xxxterm.c)
-mv xxxterm xxxterm-$REL
-tar zcf xxxterm-$REL.tgz xxxterm-$REL
-echo $td/xxxterm-$REL.tgz
+echo "Release tarball:"
+echo "  $TD/$RELEASE_TAR"
+echo ""
+echo "If everything is accurate, use the following command to push the changes:"
+echo "  git push --tags origin master"
diff --git a/version.h b/version.h
new file mode 100644
index 0000000..7053e5a
--- /dev/null
+++ b/version.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2011 Conformal Systems LLC <info@conformal.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+#ifndef XXXTERM_VERSION_H
+#define XXXTERM_VERSION_H
+
+#define XXXTERM_STR(x)		#x
+#define XXXTERM_STRINGIZE(x)	XXXTERM_STR(x)
+
+#define XXXTERM_MAJOR		0
+#define XXXTERM_MINOR		5
+#define XXXTERM_PATCH		0
+#define XXXTERM_VERSION		XXXTERM_STRINGIZE(XXXTERM_MAJOR) "." \
+				XXXTERM_STRINGIZE(XXXTERM_MINOR) "." \
+				XXXTERM_STRINGIZE(XXXTERM_PATCH)
+
+#endif /* XXXTERM_VERSION_H */
+
diff --git a/version.sh b/version.sh
new file mode 100755
index 0000000..2440cda
--- /dev/null
+++ b/version.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+#
+# Get version from header.
+#
+HEADER=version.h
+SCRIPT=version.sh
+if [ ! -f "$HEADER" ]; then
+	echo "$SCRIPT: error: $HEADER does not exist" 1>&2
+	exit 1
+fi
+PAT_PREFIX='^#define[[:space:]]+XXXTERM_'
+PAT_SUFFIX='[[:space:]]+[0-9]+$'
+MAJOR=$(egrep "${PAT_PREFIX}MAJOR${PAT_SUFFIX}" $HEADER | awk '{print $3}')
+MINOR=$(egrep "${PAT_PREFIX}MINOR${PAT_SUFFIX}" $HEADER | awk '{print $3}')
+PATCH=$(egrep "${PAT_PREFIX}PATCH${PAT_SUFFIX}" $HEADER | awk '{print $3}')
+if [ -z "$MAJOR" -o -z "$MINOR" -o -z "$PATCH" ]; then
+	echo "$SCRIPT: error: unable to get version from $HEADER" 1>&2
+	exit 1
+fi
+echo $MAJOR.$MINOR.$PATCH | tr -d '\n'
diff --git a/xxxterm.c b/xxxterm.c
index 68e22c1..473aa3d 100644
--- a/xxxterm.c
+++ b/xxxterm.c
@@ -75,6 +75,7 @@
 #include <JavaScriptCore/JavaScript.h>
 #include <gnutls/x509.h>
 
+#include "version.h"
 #include "javascript.h"
 /*
 
@@ -103,7 +104,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */
 
-static char		*version = "$xxxterm$";
+static char		*version = XXXTERM_VERSION;
 
 /* hooked functions */
 void		(*_soup_cookie_jar_add_cookie)(SoupCookieJar *, SoupCookie *);
@@ -3058,7 +3059,11 @@ about(struct tab *t, struct karg *args)
 	if (t == NULL)
 		show_oops(NULL, "about invalid parameters");
 
-	body = g_strdup_printf("<b>Version: %s</b><p>"
+	body = g_strdup_printf("<b>Version: %s</b>"
+#ifdef XXXTERM_BUILDSTR
+	    "<br><b>Build: %s</b>"
+#endif
+	    "<p>"
 	    "Authors:"
 	    "<ul>"
 	    "<li>Marco Peereboom &lt;marco@peereboom.us&gt;</li>"
@@ -3068,8 +3073,13 @@ about(struct tab *t, struct karg *args)
 	    "<li>Raphael Graf &lt;r@undefined.ch&gt; </li>"
 	    "</ul>"
 	    "Copyrights and licenses can be found on the XXXTerm "
-	    "<a href=\"http://opensource.conformal.com/wiki/XXXTerm\">website</a>",
+	    "<a href=\"http://opensource.conformal.com/wiki/XXXTerm\">website</a>"
+	    "</p>",
+#ifdef XXXTERM_BUILDSTR
+	    version, XXXTERM_BUILDSTR
+#else
 	    version
+#endif
 	    );
 
 	page = get_html_page("About", body, "", 0);