<commit_before>#! /bin/bash

set -euo pipefail

doit() {
  echo "@@@@ $@"
  "$@"
}

get_version() {
  local VERSION=$(grep AC_INIT c++/configure.ac | sed -e 's/^[^]]*],\[\([^]]*\)].*$/\1/g')
  if [[ ! "$VERSION" =~ $1 ]]; then
    echo "Couldn't parse version: $VERSION" >&2
    exit 1
  fi
  echo "$VERSION"
}

get_release_version() {
  get_version '^[0-9]+[.][0-9]+[.][0-9]+(-rc[0-9]+)?$'
}

update_version() {
  local OLD=$1
  local NEW=$2
  local BRANCH_DESC=$3

  local OLD_REGEX=${OLD//./[.]}
  doit sed -i -e "s/$OLD_REGEX/$NEW/g" c++/configure.ac compiler/capnproto-compiler.cabal
  doit git commit -a -m "Set $BRANCH_DESC version to $NEW."
}

build_packages() {
  local VERSION=$1
  local VERSION_BASE=${VERSION%%-*}

  echo "========================================================================="
  echo "Building compiler package..."
  echo "========================================================================="
  cd compiler
  doit cabal configure
  doit cabal sdist
  doit cp dist/capnproto-compiler-$VERSION_BASE.tar.gz ../capnproto-compiler-$VERSION.tar.gz
  doit cabal clean
  cd ..

  echo "========================================================================="
  echo "Building C++ runtime package..."
  echo "========================================================================="
  cd c++
  doit ./setup-autotools.sh | tr = -
  doit autoreconf -i
  doit ./configure
  doit make dist
  doit mv capnproto-c++-$VERSION.tar.gz ..
  doit make maintainer-clean
  cd ..
}

cherry_pick() {
  shift
  if [ $# -gt 0 ]; then
    echo "========================================================================="
    echo "Cherry-picking fixes"
    echo "========================================================================="
    doit git cherry-pick "$@"
  fi
}

done_banner() {
  local VERSION=$1
  local PUSH=$2
  echo "========================================================================="
  echo "Done"
  echo "========================================================================="
  echo "Ready to release:"
  echo "  capnproto-compiler-$VERSION.tar.gz"
  echo "  capnproto-c++-$VERSION.tar.gz"
  echo "Don't forget to push changes:"
  echo "  git push origin $PUSH"
}

BRANCH=$(git rev-parse --abbrev-ref HEAD)

case "${1-}:$BRANCH" in
  # ======================================================================================
  candidate:master )
    echo "New major release."
<commit_msg>Remove old compiler from release script.<commit_after>#! /bin/bash

set -euo pipefail

doit() {
  echo "@@@@ $@"
  "$@"
}

get_version() {
  local VERSION=$(grep AC_INIT c++/configure.ac | sed -e 's/^[^]]*],\[\([^]]*\)].*$/\1/g')
  if [[ ! "$VERSION" =~ $1 ]]; then
    echo "Couldn't parse version: $VERSION" >&2
    exit 1
  fi
  echo "$VERSION"
}

get_release_version() {
  get_version '^[0-9]+[.][0-9]+[.][0-9]+(-rc[0-9]+)?$'
}

update_version() {
  local OLD=$1
  local NEW=$2
  local BRANCH_DESC=$3

  local OLD_REGEX=${OLD//./[.]}
  doit sed -i -e "s/$OLD_REGEX/$NEW/g" c++/configure.ac
  doit git commit -a -m "Set $BRANCH_DESC version to $NEW."
}

build_packages() {
  local VERSION=$1
  local VERSION_BASE=${VERSION%%-*}

  echo "========================================================================="
  echo "Building C++ package..."
  echo "========================================================================="
  cd c++
  doit ./setup-autotools.sh | tr = -
  doit autoreconf -i
  doit ./configure
  doit make dist
  doit mv capnproto-c++-$VERSION.tar.gz ..
  doit make maintainer-clean
  cd ..
}

cherry_pick() {
  shift
  if [ $# -gt 0 ]; then
    echo "========================================================================="
    echo "Cherry-picking fixes"
    echo "========================================================================="
    doit git cherry-pick "$@"
  fi
}

done_banner() {
  local VERSION=$1
  local PUSH=$2
  echo "========================================================================="
  echo "Done"
  echo "========================================================================="
  echo "Ready to release:"
  echo "  capnproto-c++-$VERSION.tar.gz"
  echo "Don't forget to push changes:"
  echo "  git push origin $PUSH"
}

BRANCH=$(git rev-parse --abbrev-ref HEAD)

case "${1-}:$BRANCH" in
  # ======================================================================================
  candidate:master )
    echo "New major release."

{'fraction_non_alphanumeric': 0.40968764146672704, 'fraction_numerical': 0.009053870529651425, 'mean_word_length': 4.292215568862275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3563974', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1348, 'n_words': 315}