Commit f4a917bf authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Merge branch 'hotfix/0.1.6'

parents aa1c5794 7f008172
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

AC_INIT([git-hooks], [0.1.2])
AC_INIT([git-hooks], [0.1.6])
AM_INIT_AUTOMAKE

gitcoredir=`git --exec-path`
+32 −29
Original line number Diff line number Diff line
#! /bin/bash

config ()
{
	git config --get auto-build`printf ".%s" "$@"`
}
config () { git config --get auto-build`printf ".%s" "$@"`; }
config-all () { git config --get-all auto-build`printf ".%s" "$@"`; }

profile ()
{
@@ -93,7 +91,7 @@ _get_config_section ()
		echo "Finding match for $1 in"
		printf "  %s\n" "${sections[@]}"
	} >&2
	for prefix in '' heads/ tags/ refs/ refs/heads/ refs/tags/; do
	for prefix in refs/tags/ refs/heads/ refs/ heads/ tags/ ''; do
		for sec in "${sections[@]}"; do
			case "$1" in
				$prefix$sec)
@@ -160,6 +158,7 @@ build ()
{
	export PATH="/bin:/usr/bin:/usr/local/bin:$PATH"
	local ref=`_normalise_ref "$1"`
	local commit="$2"
	local confsec=`_get_config_section "$ref"`
	local dbuild=`config location || echo /tmp/build/`
	local dmax=`config max-builds || echo 4`
@@ -176,9 +175,10 @@ build ()
	fi

	# lock the build dir
	mkdir -p "`dirname "$dbuild".`"
	while true; do
		for i in `seq 1 $dmax`; do
			dir="$dbuild$i"
			dir=`readlink -f "$dbuild$i"`
			lock="$dir.lock"
			until _acquired_lock "$lock"; do
				_clear_stale_lock "$lock" || break
@@ -188,7 +188,8 @@ build ()
		_acquired_lock "$lock" && break
		sleep 4
	done
	trap "[ -L '$lock' ] && rm '$lock'" EXIT
	trap "[ -e '$dir' ] && rm -r '$dir'; [ -L '$lock' ] && rm '$lock'" \
		RETURN EXIT

	# create the build dir if it does not exist & remove any stickbits set by 
	# the parent; prevents permissions from being forced to values that may 
@@ -204,27 +205,28 @@ build ()

	# create the git repository if it does not exist
	is_git_workspace "$dir" || git clone "$GIT_DIR" "$dir" >&2
	git push "$dir" "$commit":refs/"$ref"

	# switch to build dir, clean it out & get the correct commit
	cd "$dir"
	(
		unset GIT_DIR
		git fetch origin
		git checkout "${ref/heads/remotes/origin}"
		git checkout "$commit"
		git clean -f -d -q -x
		git reset --hard
	) >&2
	)

	# get the settings for this build
	profile=`config "$confsec" profile || determine_profile`
	cmd=`config "$confsec" command || profile "$profile" build`
	pattern=`config "$confsec" pattern || profile "$profile" pattern`
	replace_cmd=`profile "$profile" replace_cmd`
	backup=`config "$confsec" backup | tr '[:upper:]' '[:lower:]' || echo yes`

	IFS=$'\n' cmds=( `config-all "$confsec" command || profile "$profile" build` )
	for cmd in "${cmds[@]}"; do
		# normalise $cmd
		pushd "$GIT_DIR" >/dev/null
	eval cmd=( $cmd )
		eval "cmd=( $cmd )"
		cmd[0]=`readlink -e "${cmd[0]}" || echo "${cmd[0]}"`
		popd >/dev/null

@@ -237,6 +239,7 @@ build ()
				return 1
			fi
		)
	done

	# find the generated files
	pattern=`$replace_cmd "$pattern"`
@@ -261,20 +264,20 @@ main ()
{
	local old new ref
	local log log_dir log_current
	local dbuild=`config location || echo /tmp/build/`
	dbuild=`dirname "$dbuild".`
	local dlog=`config log-location || echo /var/log/auto-build`
	local repo=`basename "$PWD"`
	while read old new ref; do
		if [ $((0x$new)) -eq 0 ]; then
			continue
		fi
		if [ "$ref" ]; then
			log="$dbuild/logs/$ref/`date +%s`.log"
			log="$dlog/$repo/$ref/`date +%s`.log"
			log_dir=`dirname "$log"`
			log_current="$log_dir/current.log"
			mkdir -p "$log_dir"
			[ -e "$log_current" ] && rm "$log_current" || true
			ln -s `basename "$log"` "$log_current"
			build "$ref" </dev/null &>>"$log" &
			build "$ref" "$new" </dev/null &>>"$log" &
		fi
	done
}