keep_updated
author Hal Wine <hwine@mozilla.com>
Wed, 24 Jul 2013 13:41:41 -0700
changeset 124 ac1ed25c3533
parent 119 451af4634443
child 134 4bda35ac3cbd
permissions -rwxr-xr-x
update script & docs for autocreate of git repos

Also some PEP-8 changes
#!/bin/bash

export LOGDIR=${LOGDIR:-$PWD}

export LOGFILE="$LOGDIR/update.log"
export UPDATE_DETAIL_LOG="$LOGDIR/details.log"

export progDir=$(cd $(dirname "$0") ; /bin/pwd )
PATH=$progDir:$PATH

g18_branch=b2g18
g18_v100_branch=b2g18_v1_0_0
g18_v101_branch=b2g18_v1_0_1
g18_v110_hd_branch=b2g18_v1_1_0_hd

# boilerplate
warn() { for m; do echo "$m"; done 1>&2; }
die() { warn "$@"; exit 1; }
usage() { warn "$@" "${USAGE:-}"; test $# -eq 0; exit $?; }

run_cmd() {
    local -i ec=0
    # we need a date to correlate detail log with run log
    echo "$(date $date_fmt): starting: $@" >>$UPDATE_DETAIL_LOG
    $dry_run timeit "$@" >>$UPDATE_DETAIL_LOG 2>&1 || ec=$?
    # we don't care if these failed, as that data is already logged
    return 0
}

do_update_pass() {
    for f in default beta b2g18 b2g18_v1_0_0 b2g18_v1_0_1 b2g18_v1_1_0_hd ; do
	cur_tip=$(hg id $(hg path $f))
	run_cmd hg --cwd $PWD pull -r $cur_tip $f
	# map "well known" hg -> git branch names
	case "$f" in
	    default) git_branch="master" ;;
	    *) git_branch=$f ;;
	esac
	# some branches need to be known by both their hg & git names
	if test $git_branch == $g18_branch; then
	    git_branch+=" gecko-18"
	elif test $git_branch == $g18_v100_branch; then
	    git_branch+=" v1.0.0"
	elif test $git_branch == $g18_v101_branch; then
	    git_branch+=" v1.0.1"
	elif test $git_branch == $g18_v110_hd_branch; then
	    git_branch+=" v1.1.0hd"
	fi
	for branch in $git_branch; do
	    run_cmd hg --cwd $PWD bookmark -f -r $cur_tip $branch
	done
    done
    run_cmd hg --cwd $PWD gexport
    # we only want to push B2G tags - get the list and create the
    # commands we need. At this point, we know we have at least one tag
    tag_refs=$(git tag -l | grep ^B2G | sed 's,^,tag ,')

    timeit git --git-dir $PWD/.git  push git.m.o +refs/heads/$g18_branch:refs/heads/gecko-18 \
                                                +refs/heads/$g18_v100_branch:refs/heads/v1.0.0 \
                                                +refs/heads/$g18_v101_branch:refs/heads/v1.0.1 \
                                                +refs/heads/$g18_v110_hd_branch:refs/heads/v1.1.0hd \
                                                +refs/heads/master:refs/heads/master \
						$tag_refs || page "git.m.o push failed: $?"

}

update_gitmapfile() {
    local tmpDir=/tmp/vcs-sync
    mkdir -p $tmpDir &>/dev/null && chmod 755 $tmpDir
    if ! cmp --quiet $tmpDir/git-mapfile .hg/git-mapfile; then
	cp -f $tmpDir/gecko-mapfile $tmpDir/gecko-mapfile.old &>/dev/null
	ln -sf gecko-mapfile.old $tmpDir/gecko-latest
	cp -f .hg/git-mapfile $tmpDir/gecko-mapfile
	chmod 444 $tmpDir/gecko-mapfile
	ln -sf gecko-mapfile $tmpDir/gecko-latest
    fi
}

cd /opt/vcs2vcs/b2g/mc-cvs-ma-update-test3/ ||
    die "can't cd to repo dir"

##do_update_pass ; exit $?
while true; do
    date --iso=min
    do_update_pass
    update_gitmapfile
    sleep 600
done


# vim: sts=4 sw=4 ai :