At work, we've been moving all of our development processes to git. As part of that, I've encouraged that alphas, betas, and releases be tagged in git -- it's important to know which versions are in use where. Additionally, my director wanted archives (zips/tars) of each of these versions to make it easier to install the releases, particularly for the members of our department who are not git-friendly. I realized that with git hooks and our use of gitolite, we could produce automated archives when tags with the words alpha/beta/release are pushed to the gitolite server. The script below is placed in the $GL_PACKAGE_HOOKS/common directory. It uses the name of the repository to decide if it should be archived (matches $ALLOW_ARCHIVE) and where the archive should be put (within $ARCHIVE_DIR).
#!/bin/bash # post-receive gitolite hook to produce archives # Debug mode DEBUG=1 # Where to put archives ARCHIVE_DIR=/srv/archives/ # When to allow archiving (regex) ALLOW_ARCHIVE="^(drupal|moodle)" #### NO CONFIG BELOW #### # Check if this repo can be archived if [[ ! "$GL_REPO" =~ $ALLOW_ARCHIVE ]] ; then [[ $DEBUG ]] && echo "Archiving for this repository is disabled." exit 0 fi # Get repo name ARCHIVE_DIR="${ARCHIVE_DIR}/${GL_REPO}" while read rev1 rev2 ref ; do if [[ ! "$ref" =~ ^refs/tags ]] ; then [[ $DEBUG ]] && echo "Not a tag reference..." continue fi # Get tag name tag=${ref##*/} # Check if tag contains alpha, beta, or release: if [[ ! $tag =~ (alpha|beta|release) ]] ; then [[ $DEBUG ]] && echo "Not alpha/beta/release" continue fi # Ensure directory exists mkdir -p ${ARCHIVE_DIR} # Repo base name REPO_BASE=${GL_REPO##*/} # Make archive [[ $DEBUG ]] && echo git archive --format=zip --prefix=${REPO_BASE}/ -o "${ARCHIVE_DIR}/$tag.zip" $ref git archive --format=zip --prefix=${REPO_BASE}/ -o "${ARCHIVE_DIR}/$tag.zip" $ref done