<commit_before>#!/bin/bash

KSP_VERSION_DEFAULT="1.0.2"
KSP_NAME_DEFAULT="dummy"

# Function for creating dummy KSP directories to test on. Takes version as an argument.
create_dummy_ksp () {
    # Set the version to the requested KSP version if supplied.
    _KSP_VERSION=$KSP_VERSION_DEFAULT
    _KSP_NAME=$KSP_NAME_DEFAULT
    
    if [ $# -eq 2 ]
    then
        _KSP_VERSION=$1
        _KSP_NAME=$2
    fi
    
    if [ "$_KSP_VERSION" == "0.90" ]
    then
        _KSP_VERSION="0.90.0"
    fi
    
    echo "Creating a dummy KSP ${_KSP_VERSION} install"
    
    # Remove any existing KSP dummy install.
    rm -rf dummy_ksp
    
    # Create a new dummy KSP.
    mkdir dummy_ksp
    mkdir dummy_ksp/CKAN
    mkdir dummy_ksp/GameData
    mkdir dummy_ksp/Ships/
    mkdir dummy_ksp/Ships/VAB
    mkdir dummy_ksp/Ships/SPH
    mkdir dummy_ksp/Ships/@thumbs
    mkdir dummy_ksp/Ships/@thumbs/VAB
    mkdir dummy_ksp/Ships/@thumbs/SPH
    
    echo "Version ${_KSP_VERSION}" > dummy_ksp/readme.txt
    
    # Copy in resources.
    cp ckan.exe dummy_ksp/ckan.exe
    
    # Reset the Mono registry.
    if [ "${USER}" = "jenkins" ]
    then
        REGISTRY_FILE=${HOME}/.mono/registry/CurrentUser/software/ckan/values.xml
        if [ -r ${REGISTRY_FILE} ]
        then
            rm -f ${REGISTRY_FILE}
        fi
    fi
    
    # Register the new dummy install.
    mono ckan.exe ksp add ${_KSP_NAME} "`pwd`/dummy_ksp"
    
    # Set the instance to default.
    mono ckan.exe ksp default ${_KSP_NAME}
    
    # Point to the local metadata instead of GitHub.
    mono ckan.exe repo add local "file://`pwd`/master.tar.gz"
    mono ckan.exe repo remove default
    
    # Link to the downloads cache.
    ln -s downloads_cache dummy_ksp/CKAN/downloads
}

# Function for injecting metadata into a tar.gz archive.
# Assummes metadata.tar.gz to be present.
inject_metadata () {
    # Check input, requires at least 1 argument.
    if [ $# -ne 1 ]
    then
        echo "Nothing to inject."
        cp metadata.tar.gz master.tar.gz
        return 0
    fi
    
    echo "Injecting into metadata."
    
    # Extract the metadata into a new folder.
    rm -rf CKAN-meta-master
    tar -xzf metadata.tar.gz
    
    # Copy in the files to inject.
    for f in $1
    do
        cp f CKAN-meta-master
    done
    
    # Recompress the archive.
    rm -f master.tar.gz
    tar -czf master.tar.gz CKAN-meta-master
}

# ----------------------------------------------
# Main entry point.
# ----------------------------------------------

# Make sure we start from a clean slate.
rm -rf built
rm -rf downloads_cache
rm -f master.tar.gz
rm -f metadata.tar.gz

create_dummy_ksp $KSP_VERSION_DEFAULT $KSP_NAME_DEFAULT

# Run basic tests.
echo "Running basic sanity tests on metadata."
echo "If these fail, then fix whatever is causing them first."

#if ! prove
#then
    #echo "prove step failed."
    #exit 1
#fi

# Find the changes to test.
echo "Finding changes to test..."

if [ -z ${ghprbActualCommit} ]
then
    echo "No commit hash, running all netkan files"
    export COMMIT_CHANGES=NetKAN/*.netkan
else
    echo "Commit hash: ${ghprbActualCommit}"
    export COMMIT_CHANGES="`git diff --diff-filter=AM --name-only --stat origin/master NetKAN`"
fi

if [ "${COMMIT_CHANGES}" = "" ]<commit_msg>Forgot to re-enable the prove step.<commit_after>#!/bin/bash

KSP_VERSION_DEFAULT="1.0.2"
KSP_NAME_DEFAULT="dummy"

# Function for creating dummy KSP directories to test on. Takes version as an argument.
create_dummy_ksp () {
    # Set the version to the requested KSP version if supplied.
    _KSP_VERSION=$KSP_VERSION_DEFAULT
    _KSP_NAME=$KSP_NAME_DEFAULT
    
    if [ $# -eq 2 ]
    then
        _KSP_VERSION=$1
        _KSP_NAME=$2
    fi
    
    if [ "$_KSP_VERSION" == "0.90" ]
    then
        _KSP_VERSION="0.90.0"
    fi
    
    echo "Creating a dummy KSP ${_KSP_VERSION} install"
    
    # Remove any existing KSP dummy install.
    rm -rf dummy_ksp
    
    # Create a new dummy KSP.
    mkdir dummy_ksp
    mkdir dummy_ksp/CKAN
    mkdir dummy_ksp/GameData
    mkdir dummy_ksp/Ships/
    mkdir dummy_ksp/Ships/VAB
    mkdir dummy_ksp/Ships/SPH
    mkdir dummy_ksp/Ships/@thumbs
    mkdir dummy_ksp/Ships/@thumbs/VAB
    mkdir dummy_ksp/Ships/@thumbs/SPH
    
    echo "Version ${_KSP_VERSION}" > dummy_ksp/readme.txt
    
    # Copy in resources.
    cp ckan.exe dummy_ksp/ckan.exe
    
    # Reset the Mono registry.
    if [ "${USER}" = "jenkins" ]
    then
        REGISTRY_FILE=${HOME}/.mono/registry/CurrentUser/software/ckan/values.xml
        if [ -r ${REGISTRY_FILE} ]
        then
            rm -f ${REGISTRY_FILE}
        fi
    fi
    
    # Register the new dummy install.
    mono ckan.exe ksp add ${_KSP_NAME} "`pwd`/dummy_ksp"
    
    # Set the instance to default.
    mono ckan.exe ksp default ${_KSP_NAME}
    
    # Point to the local metadata instead of GitHub.
    mono ckan.exe repo add local "file://`pwd`/master.tar.gz"
    mono ckan.exe repo remove default
    
    # Link to the downloads cache.
    ln -s downloads_cache dummy_ksp/CKAN/downloads
}

# Function for injecting metadata into a tar.gz archive.
# Assummes metadata.tar.gz to be present.
inject_metadata () {
    # Check input, requires at least 1 argument.
    if [ $# -ne 1 ]
    then
        echo "Nothing to inject."
        cp metadata.tar.gz master.tar.gz
        return 0
    fi
    
    echo "Injecting into metadata."
    
    # Extract the metadata into a new folder.
    rm -rf CKAN-meta-master
    tar -xzf metadata.tar.gz
    
    # Copy in the files to inject.
    for f in $1
    do
        cp f CKAN-meta-master
    done
    
    # Recompress the archive.
    rm -f master.tar.gz
    tar -czf master.tar.gz CKAN-meta-master
}

# ----------------------------------------------
# Main entry point.
# ----------------------------------------------

# Make sure we start from a clean slate.
rm -rf built
rm -rf downloads_cache
rm -f master.tar.gz
rm -f metadata.tar.gz

create_dummy_ksp $KSP_VERSION_DEFAULT $KSP_NAME_DEFAULT

# Run basic tests.
echo "Running basic sanity tests on metadata."
echo "If these fail, then fix whatever is causing them first."

if ! prove
then
    echo "prove step failed."
    exit 1
fi

# Find the changes to test.
echo "Finding changes to test..."

if [ -z ${ghprbActualCommit} ]
then
    echo "No commit hash, running all netkan files"
    export COMMIT_CHANGES=NetKAN/*.netkan
else
    echo "Commit hash: ${ghprbActualCommit}"
    export COMMIT_CHANGES="`git diff --diff-filter=AM --name-only --stat origin/master NetKAN`"
fi

if [ "${COMMIT_CHANGES}" = "" ]
{'fraction_non_alphanumeric': 0.11854655563966691, 'fraction_numerical': 0.005450416351249054, 'mean_word_length': 2.197483059051307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3118392', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2231, 'n_words': 671}