<commit_before>#!/usr/bin/env bash
set -xe


# FUNCTIONS
# NOTE (leseb): how to choose between directory for multiple change?
# using "head" as a temporary solution
function copy_dirs {
  # if base, daemon and demo exist we are testing a pushed branch and not a PR
  if [[ (! -d daemon || ! -d base) && ! -d demo ]]; then
    dir_to_test=$(git diff --name-only HEAD~1 | tr " " "\n" | awk -F '/' '/ceph-releases/ {print $1,"/",$2,"/",$3,"/",$4}' | tr -d " " | sort -u | uniq)
    if [[ "$(echo $dir_to_test | tr " " "\n" | wc -l)" -ne 1 ]]; then
      if [[ "$(echo $dir_to_test | tr " " "\n" | grep "kraken/ubuntu/16.04")" ]]; then
        dir_to_test=$(git diff --name-only HEAD~1 | tr " " "\n" | awk -F '/' '/ceph-releases/ {print $1,"/",$2,"/",$3,"/",$4}' | tr -d " " | sort -u | uniq | grep "kraken/ubuntu/16.04")
      else
        dir_to_test=$(git diff --name-only HEAD~1 | tr " " "\n" | awk -F '/' '/ceph-releases/ {print $1,"/",$2,"/",$3,"/",$4}' | tr -d " " | sort -u | uniq | head -1)
      fi
    fi
    if [[ ! -z "$dir_to_test" ]]; then
      mkdir -p {base,daemon,demo}
      cp -Lrv $dir_to_test/base/* base || true
      cp -Lrv $dir_to_test/daemon/* daemon
      cp -Lrv $dir_to_test/demo/* demo
    else
      echo "looks like your commit did not bring any changes"
      echo "building Kraken on Ubuntu 16.04"
      mkdir -p {daemon,demo}
      cp -Lrv ceph-releases/kraken/ubuntu/16.04/daemon/* daemon
      cp -Lrv ceph-releases/kraken/ubuntu/16.04/demo/* demo
    fi
  fi
}

function build_base_img {<commit_msg>build_imgs.sh: simplify non-PR case in copy_dirs()<commit_after>#!/usr/bin/env bash
set -xe


# FUNCTIONS
# NOTE (leseb): how to choose between directory for multiple change?
# using "head" as a temporary solution
function copy_dirs {
  # Are we testing a pull request?
  if [[ ( -d daemon || -d base) && -d demo ]]; then
    # We are running on a pushed "release" branch, not a PR. Do nothing here.
    return 0
  fi
  # We are testing a PR. Copy the directories.
  dir_to_test=$(git diff --name-only HEAD~1 | tr " " "\n" | awk -F '/' '/ceph-releases/ {print $1,"/",$2,"/",$3,"/",$4}' | tr -d " " | sort -u | uniq)
  if [[ "$(echo $dir_to_test | tr " " "\n" | wc -l)" -ne 1 ]]; then
    if [[ "$(echo $dir_to_test | tr " " "\n" | grep "kraken/ubuntu/16.04")" ]]; then
      dir_to_test=$(git diff --name-only HEAD~1 | tr " " "\n" | awk -F '/' '/ceph-releases/ {print $1,"/",$2,"/",$3,"/",$4}' | tr -d " " | sort -u | uniq | grep "kraken/ubuntu/16.04")
    else
      dir_to_test=$(git diff --name-only HEAD~1 | tr " " "\n" | awk -F '/' '/ceph-releases/ {print $1,"/",$2,"/",$3,"/",$4}' | tr -d " " | sort -u | uniq | head -1)
    fi
  fi
  if [[ ! -z "$dir_to_test" ]]; then
    mkdir -p {base,daemon,demo}
    cp -Lrv $dir_to_test/base/* base || true
    cp -Lrv $dir_to_test/daemon/* daemon
    cp -Lrv $dir_to_test/demo/* demo
  else
    echo "looks like your commit did not bring any changes"
    echo "building Kraken on Ubuntu 16.04"
    mkdir -p {daemon,demo}
    cp -Lrv ceph-releases/kraken/ubuntu/16.04/daemon/* daemon
    cp -Lrv ceph-releases/kraken/ubuntu/16.04/demo/* demo
  fi
}

function build_base_img {
{'fraction_non_alphanumeric': 0.19740177439797213, 'fraction_numerical': 0.02376425855513308, 'mean_word_length': 2.5793650793650795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '787574', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1233, 'n_words': 363}