Skip to content

Instantly share code, notes, and snippets.

@josteinaj
Created January 26, 2015 16:29
Show Gist options
  • Save josteinaj/f991af1fdf2dae22cd45 to your computer and use it in GitHub Desktop.
Save josteinaj/f991af1fdf2dae22cd45 to your computer and use it in GitHub Desktop.
A bash script I use to checkout a specific version of the Pipeline 2 modules (master, v1.8, v1.9); makes it easy to switch between them during development.
#!/bin/bash
# WARNING: this will git pull all projects, which may overwrite any unstaged file changes! I've added "git add -A" to the script to avoid this, but try commiting any changes before running this script just to be safe.
# Convenience script that checks out Pipeline 2 module projects for a given minor version (or master)
#
# To checkout:
# ./pipeline-build.sh tag
#
TAG="$1"
if [ "`echo "$TAG" | grep -i master | wc -l`" = 1 ]; then
TAG="master"
else
if [ "`echo "$TAG" | grep "[^0-9]*[0-9]*\.[0-9]*[^0-9]*" | wc -l`" -eq 1 ]; then
TAG="`echo "$TAG" | sed 's/[^0-9]*\([0-9]*\.[0-9]*\)[^0-9]*/\1/'`"
else
echo "Invalid tag: '$1'"
exit
fi
fi
echo "checking out $TAG..."
function assertSuccess(){
if [ $? -ne 0 ]; then echo "failed to checkout $TAG" && exit 1; fi
}
function checkout(){
echo "cd $1"
cd "$1"; assertSuccess
echo "git add -A"
git add -A; assertSuccess
if [ `git status | grep detached | wc -l` -eq 0 ]; then
echo "git pull"
git pull #; assertSuccess
else
echo "working in detached state; won't pull"
fi
MATCHING_TAG=""
if [ "$2" = "master" ]; then
MATCHING_TAG="master"
else
for tag in $(git tag | sort | tac) ; do
if [ "`echo $tag | grep $2 | wc -l`" -eq 1 ]; then
MATCHING_TAG="$tag"
break
fi
done
fi
if [ "$MATCHING_TAG" != "" ]; then
echo "git checkout $MATCHING_TAG"
git checkout $MATCHING_TAG; assertSuccess
fi
}
# Modules
for path in ~/pipeline-modules/*; do
[ -d "${path}" ] || continue # if not a directory, skip
dirname="$(basename "${path}")"
checkout ~/pipeline-modules/$dirname "$TAG"
echo $dirname
done
# Dependencies
if [ "$TAG" = "master" ]; then
checkout ~/pipeline-maven-parents/daisy-parent "master"
checkout ~/xproc-maven-plugin "master"
checkout ~/pipeline-build-utils "master"
fi
if [ "$TAG" = "1.8" ]; then
checkout ~/pipeline-maven-parents/daisy-parent "daisy-parent-2"
checkout ~/xproc-maven-plugin "xproc-engine-daisy-pipeline-1.8.1"
checkout ~/pipeline-build-utils "pax-exam-helper-1.8.1"
fi
if [ "$TAG" = "1.9" ]; then
checkout ~/pipeline-maven-parents/daisy-parent "daisy-parent-3"
checkout ~/xproc-maven-plugin "xproc-engine-daisy-pipeline-1.9"
checkout ~/pipeline-build-utils "pax-exam-helper-1.9"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment