<commit_before>#!/bin/bash

set -e

WORKSPACE=$(dirname "$(readlink -f "$0")")
GTV=${WORKSPACE}/src/git-tag-version
BUILD_DIR=${WORKSPACE}/build
TEST_DIR=${WORKSPACE}/test
TEST_RESULTS=${BUILD_DIR}/test.results
cd "${WORKSPACE}"

function echoBold {
  echo -e "\033[1m${1}\033[0m"
}

function cmd_help {
  echo "$0 COMMAND

COMMAND
  help    print this help text
  test    run tests, returns 0 on success, test results in \"TEST_RESULTS\"
  tag     create a new patch version
  build   create a release artifact in \"${BUILD_DIR}/git-tag-version\"
"
}

function cmd_clean {
  echoBold "\nCleaning up"
  rm -rfv "${BUILD_DIR}"
}

function cmd_test {
  echoBold "\nExecuting tests"
  mkdir -p "${WORKSPACE}/build"
  # make bats available and execute tests
  git clone https://github.com/sstephenson/bats.git &> /dev/null || : # do not abort if clone exists
  PATH=$PATH:${WORKSPACE}/bats/bin
  date > "${TEST_RESULTS}"

  target=$1
  if [ -z "$target" ]; then
    target="*"
  fi
  env GTV="${GTV}" bats ${TEST_DIR}/${target}.bats | tee "${TEST_RESULTS}"
  echo "Test results saved to ${TEST_RESULTS}"
}

function cmd_validate {
  echoBold "\nValidating files"
  bash -n "${GTV}"
  if travis &> /dev/null; then
    travis lint "${WORKSPACE}/.travis.yml"
  fi

  # we don't fail on static analysis findings, we fix them best as we can
  set +e
  if shellcheck -V &> /dev/null; then
    shellcheck "${GTV}"
  fi
  set -e
}

function cmd_tag {
  echoBold "\nTagging version"
  ${GTV} new patch --strict
}

# build the gtv release artifact, expects version string number as first argument, auto generates it otherwise
function cmd_build {
  echoBold "\nBuilding artifact"<commit_msg>Add message on skipped validation steps<commit_after>#!/bin/bash

set -e

WORKSPACE=$(dirname "$(readlink -f "$0")")
GTV=${WORKSPACE}/src/git-tag-version
BUILD_DIR=${WORKSPACE}/build
TEST_DIR=${WORKSPACE}/test
TEST_RESULTS=${BUILD_DIR}/test.results
cd "${WORKSPACE}"

function echoBold {
  echo -e "\033[1m${1}\033[0m"
}

function echoYellow {
  echo -e "\033[1;33m${1}\033[0m"
}

function cmd_help {
  echo "$0 COMMAND

COMMAND
  help    print this help text
  test    run tests, returns 0 on success, test results in \"TEST_RESULTS\"
  tag     create a new patch version
  build   create a release artifact in \"${BUILD_DIR}/git-tag-version\"
"
}

function cmd_clean {
  echoBold "\nCleaning up"
  rm -rfv "${BUILD_DIR}"
}

function cmd_test {
  echoBold "\nExecuting tests"
  mkdir -p "${WORKSPACE}/build"
  # make bats available and execute tests
  git clone https://github.com/sstephenson/bats.git &> /dev/null || : # do not abort if clone exists
  PATH=$PATH:${WORKSPACE}/bats/bin
  date > "${TEST_RESULTS}"

  target=$1
  if [ -z "$target" ]; then
    target="*"
  fi
  env GTV="${GTV}" bats ${TEST_DIR}/${target}.bats | tee "${TEST_RESULTS}"
  echo "Test results saved to ${TEST_RESULTS}"
}

function cmd_validate {
  echoBold "\nValidating files"
  bash -n "${GTV}"
  if travis &> /dev/null; then
    travis lint "${WORKSPACE}/.travis.yml"
  else
    echoYellow "Skipping travis file validation"
  fi

  # we don't fail on static analysis findings, we fix them best as we can
  set +e
  if shellcheck -V &> /dev/null; then
    shellcheck "${GTV}"
  else
    echoYellow "Skipping static analysis with shellcheck"
  fi
  set -e
}

function cmd_tag {
  echoBold "\nTagging version"
  ${GTV} new patch --strict
}

# build the gtv release artifact, expects version string number as first argument, auto generates it otherwise
function cmd_build {
  echoBold "\nBuilding artifact"
{'fraction_non_alphanumeric': 0.13455056179775282, 'fraction_numerical': 0.010393258426966293, 'mean_word_length': 3.6855263157894735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '5942875', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1219, 'n_words': 380}