<commit_before>#!/bin/bash

function usage() {
  echo "Usage: $0 [-c] [-r <release_branch>] [-b <branch>] [-o <old_version>] [-n <new_version>]" 1>&2;
  exit 1;
}

while getopts ":b:o:n:r:c" arg; do
    case "${arg}" in
        c)
            c="true"
            ;;
        r)
            r=${OPTARG}
            ;;
        b)
            b=${OPTARG}
            ;;
        o)
            o=${OPTARG}
            ;;
        n)
            n=${OPTARG}
            ;;
        *)
            echo "ERROR: Unknown arg ${arg}"
            usage
            ;;
    esac
done
shift $((OPTIND-1))

if [ -z "${r}" ] || [ -z "${b}" ] || [ -z "${o}" ] || [ -z "${n}" ] ; then
  echo "ERROR: Missing an argument!"
  usage
fi

if [ "$(git status --short)" != "" ] ; then 
  echo "You have uncommitted changes!"
  exit 1
fi

create_release_branch="${c}"
release_branch="${r}"
branch="${b}"
old_version="${o}"
new_version="${n}"

root="${PWD}"

echo "old_version=${old_version}"
echo "new_version=${new_version}"
echo "branch=${branch}"
echo "release_branch=${release_branch}"
if [ -n "${create_release_branch}" ] ; then
  echo "Creating release branch."
else
  echo "NOT creating release branch."
fi


function fail() {
  git submodule foreach git reset --hard origin/${branch}
  git submodule foreach git checkout ${branch}
  if [ -n "${create_release_branch}" ] ; then
    git submodule foreach git branch -d ${release_branch}
  fi
  git submodule foreach git tag -d ${new_version}

  git checkout ${branch}
  git reset --hard origin/${branch}
  git branch -d ${release_branch}
  git tag -d ${new_version}

  echo -e "\nERROR: Failed to release version ${new_version}"
  exit 1
}

# create release branch
if [ -n "${create_release_branch}" ] ; then
  if ! git branch ${release_branch} ${branch} ; then
    fail
  fi
  if ! git submodule foreach git branch ${release_branch} ${branch} ; then
    fail
  fi
fi

# checkout release branch
if ! git checkout ${release_branch} ; then
  fail
fi
if ! git submodule foreach git checkout ${release_branch} ; then
  fail
fi

# bump version
if ! ./setVersion.sh ${old_version} ${new_version} ; then
  fail
fi

# show status
if ! git status --short ; then
  fail
fi
if ! git submodule foreach git status --short ; then
  fail
fi

echo "Do you want to carry on?"
read

if ! git submodule foreach git add . ; then
  fail
fi
if ! git submodule foreach git commit -m "[Project] bumped version from ${old_version} to ${new_version}" ; then
  fail
fi
if ! git submodule foreach git tag ${new_version} ; then
  fail
fi

if ! git submodule sync ; then
  fail
fi
if ! git add . ; then
  fail
fi
if ! git commit -m "[Project] bumped version from ${old_version} to ${new_version}" ; then
  fail
fi
if ! git tag ${new_version} ; then
  fail
fi

git submodule foreach git checkout ${branch}
if [ -n "${create_release_branch}" ] ; then
  git submodule foreach git branch -d ${release_branch}
fi
git checkout ${branch}
if [ -n "${create_release_branch}" ] ; then
  git branch -d ${release_branch}
fi

echo -e "\nINFO: Released version ${new_version}"

exit 0
<commit_msg>[Project] creating release script<commit_after>#!/bin/bash

function usage() {
  echo "Usage: $0 [-c] [-r <release_branch>] [-b <branch>] [-o <old_version>] [-n <new_version>]" 1>&2;
  exit 1;
}

while getopts ":b:o:n:r:c" arg; do
    case "${arg}" in
        c)
            c="true"
            ;;
        r)
            r=${OPTARG}
            ;;
        b)
            b=${OPTARG}
            ;;
        o)
            o=${OPTARG}
            ;;
        n)
            n=${OPTARG}
            ;;
        *)
            echo "ERROR: Unknown arg ${arg}"
            usage
            ;;
    esac
done
shift $((OPTIND-1))

if [ -z "${r}" ] || [ -z "${b}" ] || [ -z "${o}" ] || [ -z "${n}" ] ; then
  echo "ERROR: Missing an argument!"
  usage
fi

if [ "$(git status --short)" != "" ] ; then 
  echo "You have uncommitted changes!"
  exit 1
fi

create_release_branch="${c}"
release_branch="${r}"
branch="${b}"
old_version="${o}"
new_version="${n}"

root="${PWD}"

echo "old_version=${old_version}"
echo "new_version=${new_version}"
echo "branch=${branch}"
echo "release_branch=${release_branch}"
if [ -n "${create_release_branch}" ] ; then
  echo "Creating release branch."
else
  echo "NOT creating release branch."
fi


function fail() {
  git submodule foreach git reset --hard origin/${branch}
  git submodule foreach git checkout ${branch}
  if [ -n "${create_release_branch}" ] ; then
    git submodule foreach git branch -D ${release_branch}
  fi
  git submodule foreach git tag -d ${new_version}

  git checkout ${branch}
  git reset --hard origin/${branch}
  if [ -n "${create_release_branch}" ] ; then
    git branch -D ${release_branch}
  fi
  git tag -d ${new_version}

  echo -e "\nERROR: Failed to release version ${new_version}"
  exit 1
}

# create release branch
if [ -n "${create_release_branch}" ] ; then
  if ! git branch ${release_branch} ${branch} ; then
    fail
  fi
  if ! git submodule foreach git branch ${release_branch} ${branch} ; then
    fail
  fi
fi

# checkout release branch
if ! git checkout ${release_branch} ; then
  fail
fi
if ! git submodule foreach git checkout ${release_branch} ; then
  fail
fi

# bump version
if ! ./setVersion.sh ${old_version} ${new_version} ; then
  fail
fi

# show status
if ! git status --short ; then
  fail
fi
if ! git submodule foreach git status --short ; then
  fail
fi

echo "Do you want to carry on?"
read

if ! git submodule foreach git add . ; then
  fail
fi
if ! git submodule foreach git commit -m "[Project] bumped version from ${old_version} to ${new_version}" ; then
  fail
fi
if ! git submodule foreach git tag ${new_version} ; then
  fail
fi

if ! git submodule sync ; then
  fail
fi
if ! git add . ; then
  fail
fi
if ! git commit -m "[Project] bumped version from ${old_version} to ${new_version}" ; then
  fail
fi
if ! git tag ${new_version} ; then
  fail
fi

if ! git submodule foreach git checkout ${branch}
  fail
fi
if [ -n "${create_release_branch}" ] ; then
  if ! git submodule foreach git branch -D ${release_branch}
    fail
  fi
fi
if ! git checkout ${branch}
  fail
fi
if [ -n "${create_release_branch}" ] ; then
  if ! git branch -D ${release_branch}
    fail
  fi
fi

echo -e "\nINFO: Released version ${new_version}"

exit 0

{'fraction_non_alphanumeric': 0.14195083267248215, 'fraction_numerical': 0.0025376685170499604, 'mean_word_length': 2.819503331314355, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '7263503', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2037, 'n_words': 730}