Skip to content

Instantly share code, notes, and snippets.

@paulp
Forked from jsuereth/scala-merge-integration.sh
Created December 6, 2011 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulp/1440136 to your computer and use it in GitHub Desktop.
Save paulp/1440136 to your computer and use it in GitHub Desktop.
Merge script to make sure develop commits actually build before pushing to master.
#!/usr/bin/env bash
#
# ^-- don't assume bash is in /bin
# we need a git library of stuff like this, since there are lots
# of ways to get it subtly wrong
git_branch_exists () {
git show-ref --verify --quiet refs/heads/$1
}
# TODO - Create a branch by build number?
declare -r integration_branch="integration"
# try this for one with actual stuff in it
declare -r remote_devel_branch="xsbt"
# declare -r remote_devel_branch="develop"
declare -r remote_master_branch="master"
# use https urls rather than git urls, they work more places
declare -r origin_url="https://github.com/scala/scala"
declare -r build_opts="all.clean test"
declare -r logfile="$(pwd)/integration.log"
echo "Scala integration build @ $(date)..." > $logfile
# Don't use "function" keyword
execute() {
cat >>"$logfile" <<EOM
---------------------------------
> $@
EOM
# I think &>> requires bash 4
"$@" &>> $logfile
}
# clone the repo if it doesn't exist.
[[ -d scala/.git ]] || echo "Cloning fresh repository..." && execute git clone "$origin_url" scala
# Pull in all latest changes.
echo "Pulling latest commits..."
cd scala && execute git fetch --all
# Reset or create integration branch
if git_branch_exists "$integration_branch"; then
execute git checkout -f $integration_branch
execute git reset --hard "origin/$remote_master_branch"
else
execute git checkout -b $integration_branch "origin/$remote_master_branch"
fi
# Merge in latest changes.
echo "Merging $remote_devel_branch and $remote_master_branch into $integration_branch..."
execute git merge "origin/$remote_devel_branch"
commits () {
git --no-pager log --no-merges --oneline --abbrev=10 ^"origin/$remote_master_branch" "origin/$remote_devel_branch"
}
[[ -z $(commits) ]] && {
cat <<EOM
-----------------------------
No new commits to validate.
-----------------------------
EOM
exit 0
}
echo "New commits to test:"
commits
# build nightly
echo "Building Scala..."
ant $build_opts
# if successful, push new commits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment