<commit_before>#!/bin/sh -e

function run {
    desc="$1"
    cmd="$2"

    if [ x"$DOC" = xdoc ]; then
	echo " - $desc"
        echo "   - $cmd"
    else
        echo "===="
        echo "Phase: $desc"
        echo "  Run: $cmd"
        okay
        $cmd
        okay
    fi
}

function find_version {
    grep AC_INIT $@
    VERS=`grep AC_INIT $@ | awk -F[ '{print $3}' | sed 's/].*//'`
}

function bump_version {
    find_version ../configure.ac
    OLD_VERSION=$VERS

    vi ../configure.ac

    find_version ../configure.ac
    NEW_VERSION=$VERS

    echo "previous version: " $OLD_VERSION
    echo "new version:      " $NEW_VERSION
}

function okay {
   /bin/echo -n "proceed? "
   read OKAY
   if [ x"$OKAY" = xn -o  x"$OKAY" = xno ]; then
      echo "okay; exiting"
      exit 1;
   fi
}

if [ "$1" = "-d" ]; then
    DOC=doc
fi

echo "starting new release"

run "commit any changes" "gt commit"
run "move to master branch" "gt br master"
run "merge development changes into master" "gt merge-from develop"
run "bump version number in configure.ac" "bump_version"

run "autoconf" "autoreconf --install"
run "configure" "../configure $CONFIGURE_OPTS"
run "build and test" \
  "make clean && make && make install && make test && make dist"
run "Commit any changes" "gt commit"

run "upload any documentation changes to gh-pages/" "make upload"
run "add the release tag" "gt tag $NEW_VERSION"
run "publish packaging data to gh-pages/" "make packages"

run "move back to develop branch" "gt br develop"
run "pick up changes for configure.ac" "gt merge-from master"
run "show diffs" "gt diff ${OLD_VERSION}...${NEW_VERSION}"
run "goto https://github.com/Juniper/libslax/releases" "open https://github.com/Juniper/libslax/releases"<commit_msg>add find_git_dir and get_log_comments; find_version no longer needs an argument; look for configure.ac<commit_after>#!/bin/sh -e

function find_git_dir {
    GIT_DIR="$PWD"
    while true; do
	if [ -d "$GIT_DIR"/.git ]; then
	    return;
	fi
	GIT_DIR=`dirname "$GIT_DIR"`
	if [ x"$GIT_DIR" = x"/" ]; then
	    echo "Not running inside a git repository"
	    exit 1
	fi
    done
}

function find_version {
    # grep AC_INIT $GIT_DIR/configure.ac
    VERS=`grep AC_INIT $GIT_DIR/configure.ac \
	| awk -F[ '{print $3}' | sed 's/].*//'`
}

function get_log_comments {
    echo "Commit log:"
    git log ${1}...${2} \
	| grep '^ ' | sort -u \
	| sed -e 's/^ */- /' -e "/^ - Merge branch '/d"
}

function bump_version {
    find_version
    OLD_VERSION=$VERS

    vi $GIT_DIR/configure.ac

    find_version
    NEW_VERSION=$VERS

    echo "previous version: " $OLD_VERSION
    echo "new version:      " $NEW_VERSION
}

function run {
    desc="$1"
    cmd="$2"

    if [ x"$DOC" = xdoc ]; then
	echo " - $desc"
        echo "   - $cmd"
    else
        echo "===="
        echo "Phase: $desc"
        echo "  Run: $cmd"
        okay
        $cmd
        okay
    fi
}

function okay {
   /bin/echo -n "proceed? "
   read OKAY
   if [ x"$OKAY" = xn -o  x"$OKAY" = xno ]; then
      echo "okay; exiting"
      exit 1;
   fi
}

if [ "$1" = "-d" ]; then
    DOC=doc
fi

find_git_dir

if [ ! -f $GIT_DIR/configure.ac ]; then
    echo "$GIT_DIR/configure.ac not found"
    exit 1
fi

echo "GIT_DIR is $GIT_DIR"
find_version
echo "Current version is $VERS"

echo "Starting new release::"

run "commit any changes" "gt commit"
run "move to master branch" "gt br master"
run "merge development changes into master" "gt merge-from develop"
run "bump version number in configure.ac" "bump_version"

run "autoconf" "autoreconf --install"
run "configure" "../configure $CONFIGURE_OPTS"
run "build and test" \
    "make clean && make && make install && make test && make dist"
run "Commit any changes" "gt commit"

run "upload any documentation changes to gh-pages/" "make upload"
run "add the release tag" "gt tag $NEW_VERSION"
run "publish packaging data to gh-pages/" "make packages"

run "move back to develop branch" "gt br develop"
run "pick up changes for configure.ac" "gt merge-from master"

run "show diffs" "gt diff ${OLD_VERSION}...${NEW_VERSION}"
get_log_comments $OLD_VERSION $NEW_VERSION

run "goto https://github.com/Juniper/libslax/releases" "open https://github.com/Juniper/libslax/releases"
{'fraction_non_alphanumeric': 0.13789846517119245, 'fraction_numerical': 0.003305785123966942, 'mean_word_length': 2.8649635036496353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4495563', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1484, 'n_words': 477}