<commit_before>#!/bin/bash

set -e

# ==============================================================================
# Set paths and files
# ==============================================================================
readonly VM_DOWNLOAD="https://www.hpi.uni-potsdam.de/hirschfeld/artefacts/filetreeci/vms"
readonly IMAGE_DOWNLOAD="https://www.hpi.uni-potsdam.de/hirschfeld/artefacts/filetreeci/images"

# Optional environment variables
[[ -z "${baseline_group}" ]] && export baseline_group="TravisCI"
[[ -z "${exclude_categories}" ]] && exclude_categories="nil"
[[ -z "${exclude_classes}" ]] && exclude_classes="nil"
[[ -z "${force_update}" ]] && force_update="false"
[[ -z "${keep_open}" ]] && keep_open="false"
if [[ -z "${run_script}" ]]; then
    run_script="${SMALLTALK_CI_HOME}/squeak/run.st"
else
    run_script="${project_home}/${run_script}"
fi
# ==============================================================================

# ==============================================================================
# Check and specify Squeak image
# ==============================================================================
SPUR_IMAGE=true
case "$SMALLTALK" in
    "Squeak-trunk"|"Squeak-Trunk"|"SqueakTrunk")
        IMAGE_TAR="Squeak-Trunk.tar.gz"
        ;;
    "Squeak-5.0"|"Squeak5.0")
        IMAGE_TAR="Squeak-5.0.tar.gz"
        ;;
    "Squeak-4.6"|"Squeak4.6")
        IMAGE_TAR="Squeak-4.6.tar.gz"
        SPUR_IMAGE=false
        ;;
    "Squeak-4.5"|"Squeak4.5")
        IMAGE_TAR="Squeak-4.5.tar.gz"
        SPUR_IMAGE=false
        ;;
    *)
        print_error "Unsupported Squeak version '${SMALLTALK}'"
        exit 1
        ;;
esac
# ==============================================================================

# ==============================================================================
# Identify OS and select virtual machine
# ==============================================================================
case "$(uname -s)" in
    "Linux")
        print_info "Linux detected..."
        if [[ "${SPUR_IMAGE}" = true ]]; then
            readonly COG_VM_FILE_BASE="cog_linux_spur"
            readonly COG_VM="${SMALLTALK_CI_VMS}/cogspurlinux/bin/squeak"
        else
            readonly COG_VM_FILE_BASE="cog_linux"
            readonly COG_VM="${SMALLTALK_CI_VMS}/coglinux/bin/squeak"
        fi
        readonly COG_VM_FILE="${COG_VM_FILE_BASE}.tar.gz"
        if [[ "${TRAVIS}" = "true" ]]; then
            readonly COG_VM_FILE="${COG_VM_FILE_BASE}.min.tar.gz"
            readonly COG_VM_PARAM="-nosound -nodisplay"
        fi
        ;;
    "Darwin")
        print_info "OS X detected..."
        if [[ "${SPUR_IMAGE}" = true ]]; then
            readonly COG_VM_FILE_BASE="cog_osx_spur"
            readonly COG_VM="${SMALLTALK_CI_VMS}/CogSpur.app/Contents/MacOS/Squeak"
        else
            readonly COG_VM_FILE_BASE="cog_osx"
            readonly COG_VM="${SMALLTALK_CI_VMS}/Cog.app/Contents/MacOS/Squeak"
        fi
        readonly COG_VM_FILE="${COG_VM_FILE_BASE}.tar.gz"
        ;;
    *)
        print_error "Unsupported platform '$(uname -s)'"
        exit 1
        ;;
esac
# ==============================================================================

# ==============================================================================
# Download files accordingly if not available
# ==============================================================================
if [[ ! -f "${SMALLTALK_CI_CACHE}/${COG_VM_FILE}" ]]; then
    print_timed "Downloading virtual machine..."
    download_file "${VM_DOWNLOAD}/${COG_VM_FILE}" > "${SMALLTALK_CI_CACHE}/${COG_VM_FILE}"
    print_timed_result
fi
if [[ ! -f "$COG_VM" ]]; then
    print_info "Extracting virtual machine..."
    tar xzf "${SMALLTALK_CI_CACHE}/${COG_VM_FILE}" -C "${SMALLTALK_CI_VMS}"
fi
if [[ ! -f "${SMALLTALK_CI_CACHE}/${IMAGE_TAR}" ]]; then
    print_timed "Downloading ${SMALLTALK} testing image..."
    download_file "${IMAGE_DOWNLOAD}/${IMAGE_TAR}" > "${SMALLTALK_CI_CACHE}/${IMAGE_TAR}"
    print_timed_result
fi
# ==============================================================================

# ==============================================================================
# Extract image and run on virtual machine
# ==============================================================================
print_info "Extracting image..."
tar xzf "${SMALLTALK_CI_CACHE}/${IMAGE_TAR}" -C "${SMALLTALK_CI_BUILD}"

print_info "Load project into image and run tests..."
readonly VM_ARGS="${run_script} ${packages} ${baseline} ${baseline_group} ${exclude_categories} ${exclude_classes} ${force_update} ${keep_open}"
"${COG_VM}" $COG_VM_PARAM "${SMALLTALK_CI_IMAGE}" $VM_ARGS || exit_status=$?
# ==============================================================================<commit_msg>Fix readonly errors<commit_after>#!/bin/bash

set -e

# ==============================================================================
# Set paths and files
# ==============================================================================
readonly VM_DOWNLOAD="https://www.hpi.uni-potsdam.de/hirschfeld/artefacts/filetreeci/vms"
readonly IMAGE_DOWNLOAD="https://www.hpi.uni-potsdam.de/hirschfeld/artefacts/filetreeci/images"

# Optional environment variables
[[ -z "${baseline_group}" ]] && export baseline_group="TravisCI"
[[ -z "${exclude_categories}" ]] && exclude_categories="nil"
[[ -z "${exclude_classes}" ]] && exclude_classes="nil"
[[ -z "${force_update}" ]] && force_update="false"
[[ -z "${keep_open}" ]] && keep_open="false"
if [[ -z "${run_script}" ]]; then
    run_script="${SMALLTALK_CI_HOME}/squeak/run.st"
else
    run_script="${project_home}/${run_script}"
fi
# ==============================================================================

# ==============================================================================
# Check and specify Squeak image
# ==============================================================================
case "$SMALLTALK" in
    "Squeak-trunk"|"Squeak-Trunk"|"SqueakTrunk")
        readonly IMAGE_TAR="Squeak-Trunk.tar.gz"
        readonly SPUR_IMAGE=true
        ;;
    "Squeak-5.0"|"Squeak5.0")
        readonly IMAGE_TAR="Squeak-5.0.tar.gz"
        readonly SPUR_IMAGE=true
        ;;
    "Squeak-4.6"|"Squeak4.6")
        readonly IMAGE_TAR="Squeak-4.6.tar.gz"
        readonly SPUR_IMAGE=false
        ;;
    "Squeak-4.5"|"Squeak4.5")
        readonly IMAGE_TAR="Squeak-4.5.tar.gz"
        readonly SPUR_IMAGE=false
        ;;
    *)
        print_error "Unsupported Squeak version '${SMALLTALK}'"
        exit 1
        ;;
esac
# ==============================================================================

# ==============================================================================
# Identify OS and select virtual machine
# ==============================================================================
case "$(uname -s)" in
    "Linux")
        print_info "Linux detected..."
        if [[ "${SPUR_IMAGE}" = true ]]; then
            cog_vm_file_base="cog_linux_spur"
            cog_vm="${SMALLTALK_CI_VMS}/cogspurlinux/bin/squeak"
        else
            cog_vm_file_base="cog_linux"
            cog_vm="${SMALLTALK_CI_VMS}/coglinux/bin/squeak"
        fi
        cog_vm_file="${cog_vm_file_base}.tar.gz"
        if [[ "${TRAVIS}" = "true" ]]; then
            cog_vm_file="${cog_vm_file_base}.min.tar.gz"
            cog_vm_param="-nosound -nodisplay"
        fi
        ;;
    "Darwin")
        print_info "OS X detected..."
        if [[ "${SPUR_IMAGE}" = true ]]; then
            cog_vm_file_base="cog_osx_spur"
            cog_vm="${SMALLTALK_CI_VMS}/CogSpur.app/Contents/MacOS/Squeak"
        else
            cog_vm_file_base="cog_osx"
            cog_vm="${SMALLTALK_CI_VMS}/Cog.app/Contents/MacOS/Squeak"
        fi
        cog_vm_file="${cog_vm_file_base}.tar.gz"
        ;;
    *)
        print_error "Unsupported platform '$(uname -s)'"
        exit 1
        ;;
esac
# ==============================================================================

# ==============================================================================
# Download files accordingly if not available
# ==============================================================================
if [[ ! -f "${SMALLTALK_CI_CACHE}/${cog_vm_file}" ]]; then
    print_timed "Downloading virtual machine..."
    download_file "${VM_DOWNLOAD}/${cog_vm_file}" > "${SMALLTALK_CI_CACHE}/${cog_vm_file}"
    print_timed_result
fi
if [[ ! -f "$cog_vm" ]]; then
    print_info "Extracting virtual machine..."
    tar xzf "${SMALLTALK_CI_CACHE}/${cog_vm_file}" -C "${SMALLTALK_CI_VMS}"
fi
if [[ ! -f "${SMALLTALK_CI_CACHE}/${IMAGE_TAR}" ]]; then
    print_timed "Downloading ${SMALLTALK} testing image..."
    download_file "${IMAGE_DOWNLOAD}/${IMAGE_TAR}" > "${SMALLTALK_CI_CACHE}/${IMAGE_TAR}"
    print_timed_result
fi
# ==============================================================================

# ==============================================================================
# Extract image and run on virtual machine
# ==============================================================================
print_info "Extracting image..."
tar xzf "${SMALLTALK_CI_CACHE}/${IMAGE_TAR}" -C "${SMALLTALK_CI_BUILD}"

print_info "Load project into image and run tests..."
readonly VM_ARGS="${run_script} ${packages} ${baseline} ${baseline_group} ${exclude_categories} ${exclude_classes} ${force_update} ${keep_open}"
"${cog_vm}" $cog_vm_param "${SMALLTALK_CI_IMAGE}" $VM_ARGS || exit_status=$?
# ==============================================================================
{'fraction_non_alphanumeric': 0.36640982923781756, 'fraction_numerical': 0.004164931278633903, 'mean_word_length': 4.526467203682394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2429694', 'n_tokens_mistral': 3028, 'n_tokens_neox': 2779, 'n_words': 435}