<commit_before>#!/bin/bash

set -e

# Helper functions
# ==============================================================================
function print_info {
    printf "\e[0;34m$1\e[0m\n"
}

function print_notice {
    printf "\e[1;33m$1\e[0m\n"
}

function print_success {
    printf "\e[1;32m$1\e[0m\n"
}

function print_error {
    printf "\e[1;31m$1\e[0m\n"
}
# ==============================================================================

# Determine Pharo download url
# ==============================================================================
case "$SMALLTALK" in
    "Pharo-5.0")
        PHARO_GET_VERSION="50"
        ;;
    "Pharo-4.0")
        PHARO_GET_VERSION="40"
        ;;
    "Pharo-3.0")
        PHARO_GET_VERSION="30"
        ;;
    # "Pharo-2.0")
    #     PHARO_GET_VERSION="20"
    #     ;;
    *)
        print_error "Unsupported Pharo version ${SMALLTALK}"
        exit 1
        ;;
esac
# ==============================================================================

# Set paths and files
# ==============================================================================
PHARO_IMAGE="$SMALLTALK.image"
PHARO_CHANGES="$SMALLTALK.changes"
PHARO_VM="$FILETREE_CI_VMS/$SMALLTALK/pharo"
# ==============================================================================

# Download files accordingly if not available
# ==============================================================================
if [ ! -f "$FILETREE_CI_CACHE/$PHARO_IMAGE" ]; then
    print_info "Downloading $SMALLTALK image..."
    pushd $FILETREE_CI_CACHE > /dev/null
    wget --quiet -O - get.pharo.org/${PHARO_GET_VERSION} | bash
    mv Pharo.image "$SMALLTALK.image"
    mv Pharo.changes "$SMALLTALK.changes"
    popd > /dev/null
fi

if [ ! -d "$FILETREE_CI_VMS/$SMALLTALK" ]; then
    print_info "Downloading $SMALLTALK vm..."
    mkdir "$FILETREE_CI_VMS/$SMALLTALK"
    pushd $FILETREE_CI_VMS/$SMALLTALK > /dev/null
    wget --quiet -O - get.pharo.org/vm${PHARO_GET_VERSION} | bash
    # Remove libFT2Plugin if present
    rm -f "$FILETREE_CI_VMS/$SMALLTALK/pharo-vm/libFT2Plugin.so"
    popd > /dev/null
    # Make sure vm is now available
    [ -f "$PHARO_VM" ] || exit 1
fi

# ==============================================================================

# Prepare image and virtual machine
# ==============================================================================
print_info "Preparing image..."
cp "$FILETREE_CI_CACHE/$PHARO_IMAGE" "$FILETREE_CI_BUILD"
cp "$FILETREE_CI_CACHE/$PHARO_CHANGES" "$FILETREE_CI_BUILD"

# ==============================================================================

# Load project and run tests
# ==============================================================================
print_info "Loading project..."
$PHARO_VM "$FILETREE_CI_BUILD/$PHARO_IMAGE" eval --save "<commit_msg>adding latest(alpha) and stable versions<commit_after>#!/bin/bash

set -e

# Helper functions
# ==============================================================================
function print_info {
    printf "\e[0;34m$1\e[0m\n"
}

function print_notice {
    printf "\e[1;33m$1\e[0m\n"
}

function print_success {
    printf "\e[1;32m$1\e[0m\n"
}

function print_error {
    printf "\e[1;31m$1\e[0m\n"
}
# ==============================================================================

# Determine Pharo download url
# ==============================================================================
case "$SMALLTALK" in
    "Pharo-latest")
        PHARO_GET_VERSION="alpha"
        ;;
    "Pharo-stable")
        PHARO_GET_VERSION="stable"
        ;;
    "Pharo-5.0")
        PHARO_GET_VERSION="50"
        ;;
    "Pharo-4.0")
        PHARO_GET_VERSION="40"
        ;;
    #"Pharo-3.0")
    #    PHARO_GET_VERSION="30"
    #    ;;
    # "Pharo-2.0")
    #     PHARO_GET_VERSION="20"
    #     ;;
    *)
        print_error "Unsupported Pharo version ${SMALLTALK}"
        exit 1
        ;;
esac
# ==============================================================================

# Set paths and files
# ==============================================================================
PHARO_IMAGE="$SMALLTALK.image"
PHARO_CHANGES="$SMALLTALK.changes"
PHARO_VM="$FILETREE_CI_VMS/$SMALLTALK/pharo"
# ==============================================================================

# Download files accordingly if not available
# ==============================================================================
if [ ! -f "$FILETREE_CI_CACHE/$PHARO_IMAGE" ]; then
    print_info "Downloading $SMALLTALK image..."
    pushd $FILETREE_CI_CACHE > /dev/null
    wget --quiet -O - get.pharo.org/${PHARO_GET_VERSION}+vm | bash
    mv Pharo.image "$SMALLTALK.image"
    mv Pharo.changes "$SMALLTALK.changes"
    popd > /dev/null
fi

if [ ! -d "$FILETREE_CI_VMS/$SMALLTALK" ]; then
    print_info "Downloading $SMALLTALK vm..."
    mkdir "$FILETREE_CI_VMS/$SMALLTALK"
    pushd $FILETREE_CI_VMS/$SMALLTALK > /dev/null
    wget --quiet -O - get.pharo.org/vm${PHARO_GET_VERSION} | bash
    # Remove libFT2Plugin if present
    rm -f "$FILETREE_CI_VMS/$SMALLTALK/pharo-vm/libFT2Plugin.so"
    popd > /dev/null
    # Make sure vm is now available
    [ -f "$PHARO_VM" ] || exit 1
fi

# ==============================================================================

# Prepare image and virtual machine
# ==============================================================================
print_info "Preparing image..."
cp "$FILETREE_CI_CACHE/$PHARO_IMAGE" "$FILETREE_CI_BUILD"
cp "$FILETREE_CI_CACHE/$PHARO_CHANGES" "$FILETREE_CI_BUILD"

# ==============================================================================

# Load project and run tests
# ==============================================================================
print_info "Loading project..."
$PHARO_VM "$FILETREE_CI_BUILD/$PHARO_IMAGE" eval --save "
{'fraction_non_alphanumeric': 0.39580467675378267, 'fraction_numerical': 0.013755158184319119, 'mean_word_length': 4.631171345595353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3042366', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1720, 'n_words': 300}