#!/bin/bash
# Generate release tar file of source
# Must be run after tree is tagged and pushed to master.
# Use --keep to keep working directory for debugging.

mydir=$(dirname $(which $0))
source ${mydir}/releaseLib.sh

keep=no
if [ $1 = '--keep' ] ; then
    keep=yes
fi
set -beEu -o pipefail

buildDir=$(realpath -m build)
srcBuildDir="${buildDir}/src-tmp"

set -x
rm -rf ${srcBuildDir}
mkdir -p ${srcBuildDir}
cd ${srcBuildDir}
git clone --recursive https://github.com/ComparativeGenomicsToolkit/cactus.git
cd cactus
git fetch --tags origin

REL_TAG=$(getLatestReleaseTag)
git checkout "${REL_TAG}"
git submodule update --init --recursive
find submodules -name ".git" -exec rm -Rf "{}" \;
cd ..
mv cactus cactus-${REL_TAG}
tar -czf ${buildDir}/cactus-${REL_TAG}.tar.gz cactus-${REL_TAG}
if [ "$keep" = "no" ] ; then
    rm -Rf ${srcBuildDir}
fi
