I am in reference to the excellent article by David Gageot: Serverless CI with git.
Let me include David's script here:
#!/bin/bash
if [ 0 -eq `git remote -v | grep -c push` ]; then
REMOTE_REPO=`git remote -v | sed 's/origin//'`
else
REMOTE_REPO=`git remote -v | grep "(push)" | sed 's/origin//' | sed 's/(push)//'`
fi
if [ ! -z "$1" ]; then
git add .
git commit -a -m "$1"
fi
git pull
if [ ! -d ".privatebuild" ]; then
git clone . .privatebuild
fi
cd .privatebuild
git clean -df
git pull
if [ -e "pom.xml" ]; then
mvn clean install
if [ $? -eq 0 ]; then
echo "Publishing to: $REMOTE_REPO"
git push $REMOTE_REPO master
else
echo "Unable to build"
exit $?
fi
fi
If I understand correctly this script, it will clone the initial git repository to a second hidden git repository where unit tests will be run.
If unit tests pass, the second hidden repository is pushed to the initial working repository.
My questions are as follows:
git commit
command? As a pre-commit hook?The script is a little outdated but here's how it worked: You'd use the script either to push local changes or commit AND push local changes. The latter behaviour I got rid of in newer versions of the script because it should have a single responsibility. Before running the build, it would pull from remote, clone the whole repo, run the build from this clone then push. If changes are pushed by someone else in the meantime, the push will simply fail. If you make changes in your repo in the meantime, theses changes are unknown to the clone.
Here's the version I use everyday now https://github.com/dgageot/dotfiles/blob/master/bin/git-build
Hope this helps.