Merge pull request #1459 from folecr/jenkinsscript

Add capability to generate pull requests
This commit is contained in:
minggo 2012-10-15 18:40:41 -07:00
commit f96e558b66
1 changed files with 58 additions and 21 deletions

View File

@ -17,13 +17,26 @@
#
# For automatically pushing changes:
#
# * REMOTE_COCOS2DX_REPOSITORY
# * REMOTE_AUTOGEN_BINDINGS_REPOSITORY
# * Ensure you have ssh access to above repositories
# * REMOTE_COCOS2DX_REPOSITORY
# * Note : Ensure you have commit access to above repositories
# * COCOS2DX_PULL_BASE
# * hub
# * see http://defunkt.io/hub/
# * Ensure that hub has an OAuth token to REMOTE_COCOS2DX_REPOSITORY
# * see http://defunkt.io/hub/hub.1.html#CONFIGURATION
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
COCOS2DX_ROOT="$DIR"/../../../..
if [ -z "${HUB+aaa}" ]; then
# ... if HUB is not set, use "$HOME/bin/hub"
HUB="$HOME/bin/hub"
fi
# Exit on error
set -e
# 1. Generate JS bindings
COCOS2DX_ROOT="$COCOS2DX_ROOT" /bin/bash ../../../tojs/genbindings.sh
@ -36,12 +49,12 @@ if [ -z "${REMOTE_AUTOGEN_BINDINGS_REPOSITORY+aaa}" ]; then
echo Environment variable must be set REMOTE_AUTOGEN_BINDINGS_REPOSITORY
echo This script expects to automatically push changes
echo to this repo
echo example
echo REMOTE_AUTOGEN_BINDINGS_REPOSITORY=\"git@github.com:folecr/cocos2dx-autogen-bindings.git\"
echo REMOTE_AUTOGEN_BINDINGS_REPOSITORY=\"\$HOME/test/cocos2dx-autogen-bindings\"
echo
echo Exiting with failure.
echo
# example
# REMOTE_AUTOGEN_BINDINGS_REPOSITORY="git@github.com:folecr/cocos2dx-autogen-bindings.git"
# REMOTE_AUTOGEN_BINDINGS_REPOSITORY="$HOME/test/cocos2dx-autogen-bindings"
exit 1
fi
@ -58,21 +71,23 @@ ELAPSEDSECS=`date +%s`
echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness
GENERATED_BRANCH=autogeneratedbindings_"$ELAPSEDSECS"
GENERATED_GITDIR="$COCOS2DX_ROOT"/.git/modules/scripting/javascript/bindings/generated
GENERATED_WORKTREE="$COCOS2DX_ROOT"/scripting/javascript/bindings/generated
# git command shortcut
gitcmd_GEN="git --git-dir=$GENERATED_GITDIR --work-tree=$GENERATED_WORKTREE"
# 2. In JSBindings repo, Check if there are any files that are different from the index
pushd "$GENERATED_WORKTREE"
# Run status to record the output in the log
${gitcmd_GEN} status
git status
echo
echo Diffing...
echo Comparing with origin/master ...
echo
${gitcmd_GEN} diff --stat --exit-code
# Don't exit on non-zero return value
set +e
git diff --stat --exit-code origin/master
DIFF_RETVAL=$?
if [ $DIFF_RETVAL -eq 0 ]
@ -84,29 +99,34 @@ then
exit 0
else
echo
echo "Generated files differ from the version checked in to the index. Continuing."
echo "Generated files differ from origin/master. Continuing."
echo
fi
# Exit on error
set -e
# 3. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it
${gitcmd_GEN} add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js
${gitcmd_GEN} checkout origin/master -b "$GENERATED_BRANCH"
${gitcmd_GEN} commit --verbose -m "$COMMITTAG : autogenerated bindings"
git checkout origin/master -b "$GENERATED_BRANCH"
git add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js
git commit --verbose -m "$COMMITTAG : autogenerated bindings"
# 4. In JSBindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository
${gitcmd_GEN} push --verbose "$REMOTE_AUTOGEN_BINDINGS_REPOSITORY" "$GENERATED_BRANCH":master
git push --verbose "$REMOTE_AUTOGEN_BINDINGS_REPOSITORY" "$GENERATED_BRANCH":master
popd
if [ -z "${REMOTE_COCOS2DX_REPOSITORY+aaa}" ]; then
echo
echo Environment variable is not set REMOTE_COCOS2DX_REPOSITORY
echo This script will NOT automatically push changes
echo unless this variable is set.
echo example
echo REMOTE_COCOS2DX_REPOSITORY=\"git@github.com:cocos2d/cocos2d-x.git\"
echo REMOTE_COCOS2DX_REPOSITORY=\"\$HOME/test/cocos2d-x\"
echo
echo Exiting with success.
echo
# example
# REMOTE_COCOS2DX_REPOSITORY="git@github.com:cocos2d/cocos2d-x.git"
# REMOTE_COCOS2DX_REPOSITORY="$HOME/test/cocos2d-x"
exit 0
fi
@ -121,6 +141,23 @@ git checkout origin/gles20 -b "$COCOS_BRANCH"
git commit -m "$COMMITTAG : updating submodule reference to latest autogenerated bindings"
# 6. In Cocos2D-X repo, Push the commit with updated submodule to "gles20" of the cocos2d-x repository
git push "$REMOTE_COCOS2DX_REPOSITORY" "$COCOS_BRANCH":gles20
git push "$REMOTE_COCOS2DX_REPOSITORY" "$COCOS_BRANCH"
if [ -z "${COCOS2DX_PULL_BASE+aaa}" ]; then
echo
echo Environment variable is not set COCOS2DX_PULL_BASE
echo This script will NOT automatically generate pull requests
echo unless this variable is set.
echo example
echo COCOS2DX_PULL_BASE=\"cocos2d/cocos2d-x:gles20\"
echo COCOS2DX_PULL_BASE=\"username/repository:branch\"
echo
echo Exiting with success.
echo
exit 0
fi
# 7.
${HUB} pull-request "$COMMITTAG : updating submodule reference to latest autogenerated bindings" -b "$COCOS2DX_PULL_BASE" -h "$COCOS_BRANCH"
popd