Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Zip Up a Release From a hg Repository

DZone's Guide to

How to Zip Up a Release From a hg Repository

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

Did you know hg archive command can quickly zip up your project by given a revision or release name? This is very handy to package up a distribution and share with other who is refusing to use the same client.

I wrote a simple bash script to do this with couple extras. It will create a zip file with a nice basename so it’s easy for unzipping. It also auto generate and append the given revision or tag name into the RELEASE.txt file, so you know what’s been released.

Just add the following file into any root of your hg based project’s bin directory and it’s ready to use.

NOTE
This script will not tag your repository. It assumed you already have tagged. It simply will package up a release into a nice little zip file.
bin/zip-release.sh
#!/usr/bin/env bash
#
# Package a release or snapshot from Hg repository for distribution.
# :Author: Zemian Deng
# :Date: 2013/02/01
#
# Usage example:
#   # release a specific tag
#   cd /path/to/project
#   bin/zip-release.sh 1.0.1
#
#   # release a snapshot
#   bin/zip-release.sh
#

# Command line arguments and options
# Assume this script is in bin, which one directory up.
APP_HOME=`cd $(dirname $0)/.. && pwd`
if [[ `command -v realpath` != "" ]]; then
	# resolve symbolic link if possible.
    APP_HOME=`realpath $APP_HOME`
fi
HG_REVISION=`hg id -i`
REL_VERSION=$1
if [[ "$REL_VERSION" == "" ]]; then
    REL_VERSION=$HG_REVISION
fi
REL_NAME="`basename $APP_HOME`-$REL_VERSION"
REL_DIR=$APP_HOME/target/$REL_NAME
REL_ZIPFILE=$REL_DIR/../$REL_NAME.zip

# Generate the zip package
printf "Generating $REL_NAME in directory=`pwd`\n"
mkdir -p $REL_DIR
hg archive -r $REL_VERSION $REL_ZIPFILE

# Auto append revision id to release file.
if [[ -e $APP_HOME/RELEASE.txt ]]; then
	cp $APP_HOME/RELEASE.txt $REL_DIR/RELEASE.txt
fi
printf "$REL_NAME revsion=$HG_REVISION date=`date`\n" >> $REL_DIR/RELEASE.txt
zip -u $REL_ZIPFILE $REL_DIR/RELEASE.txt

# Clean up the tmp rel dir.
rm -r $REL_DIR

printf "$REL_ZIPFILE created.\n"

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Published at DZone with permission of Zemian Deng, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}