<commit_before>#!/bin/bash
set -e
# to debug:
#set -xv

sfuser='jenkins'
sfbuild='mjolnir0.galaxyproject.org'
depotuser='depot'
depothost='orval.galaxyproject.org'
depotroot='/srv/nginx/depot.galaxyproject.org/root/starforge/wheels'
base_branch='remotes/origin/master'
sfvenv='/home/jenkins/sfvenv'

if [ -z "${BUILD_NUMBER}" ]; then
    echo '$BUILD_NUMBER is unset, are you running from Jenkins?'
    exit 1
else
    output=$(realpath wheels/dist/build-${BUILD_NUMBER})
fi


function build_wheel()
{
    l_wheel=$1
    l_new=$2

    outtmp=$(ssh ${sfuser}@${sfbuild} mktemp -d)
    ssh ${sfuser}@${sfbuild} "cd $outtmp && PATH="/sbin:\$PATH" && . ${sfvenv}/bin/activate && starforge --debug wheel --wheels-config=$l_new --exit-on-failure $l_wheel"
    [ ! -d ${output} ] && mkdir -p ${output}
    scp ${sfuser}@${sfbuild}:${outtmp}/\*.whl ${sfuser}@${sfbuild}:${outtmp}/\*.tar.gz ${output}
    echo "Contents of ${output} after building ${l_wheel}:"
    ls -l ${output}
}


if [ -z "$1" -o "$1" = 'none' ]; then

    echo "Detecting changes to wheels.yml..."

    wheels_patch=$(mktemp)
    wheels_tmp=$(mktemp)

    read new old < <(ssh ${sfuser}@${sfbuild} 'mktemp && mktemp' | xargs echo)

    cp wheels/build/wheels.yml $wheels_tmp
    git diff --color=never HEAD $base_branch -- wheels/build/wheels.yml >$wheels_patch

    if [ $(stat -c %s $wheels_patch) -ne 0 ]; then
        patch -s $wheels_tmp $wheels_patch
        scp -q wheels/build/wheels.yml ${sfuser}@${sfbuild}:${new}
        scp -q $wheels_tmp ${sfuser}@${sfbuild}:${old}
        build_wheels=()
        while read op wheel; do
            case "$op" in
                A|M)
                    build_wheels+=($wheel)
                    ;;
            esac
        done < <(ssh ${sfuser}@${sfbuild} ${sfvenv}/bin/starforge wheel_diff --wheels-config=$new $old)
        for wheel in "${build_wheels[@]}"; do
            echo "Building '$wheel' wheel and sdist"
            build_wheel $wheel $new
        done
        ssh ${sfuser}@${sfbuild} "rm ${new} ${old}"
    fi

    rm ${wheels_patch} ${wheels_tmp}

else

    new=$(ssh ${sfuser}@${sfbuild} mktemp)
    scp -q wheels/build/wheels.yml ${sfuser}@${sfbuild}:${new}

    for wheel in "$@"; do
        echo "Building specified wheel: ${wheel}"
        build_wheel $wheel $new
    done

    ssh ${sfuser}@${sfbuild} "rm ${new}"

fi

if [ -d ${output} ]; then<commit_msg>Output sha256 sums of objects built by Jenkins<commit_after>#!/bin/bash
set -e
# to debug:
#set -xv

sfuser='jenkins'
sfbuild='mjolnir0.galaxyproject.org'
depotuser='depot'
depothost='orval.galaxyproject.org'
depotroot='/srv/nginx/depot.galaxyproject.org/root/starforge/wheels'
base_branch='remotes/origin/master'
sfvenv='/home/jenkins/sfvenv'

if [ -z "${BUILD_NUMBER}" ]; then
    echo '$BUILD_NUMBER is unset, are you running from Jenkins?'
    exit 1
else
    output=$(realpath wheels/dist/build-${BUILD_NUMBER})
fi


function build_wheel()
{
    l_wheel=$1
    l_new=$2

    outtmp=$(ssh ${sfuser}@${sfbuild} mktemp -d)
    ssh ${sfuser}@${sfbuild} "cd $outtmp && PATH="/sbin:\$PATH" && . ${sfvenv}/bin/activate && starforge --debug wheel --wheels-config=$l_new --exit-on-failure $l_wheel"
    [ ! -d ${output} ] && mkdir -p ${output}
    scp ${sfuser}@${sfbuild}:${outtmp}/\*.whl ${sfuser}@${sfbuild}:${outtmp}/\*.tar.gz ${output}
    echo "Contents of ${output} after building ${l_wheel}:"
    ls -l ${output}
}


if [ -z "$1" -o "$1" = 'none' ]; then

    echo "Detecting changes to wheels.yml..."

    wheels_patch=$(mktemp)
    wheels_tmp=$(mktemp)

    read new old < <(ssh ${sfuser}@${sfbuild} 'mktemp && mktemp' | xargs echo)

    cp wheels/build/wheels.yml $wheels_tmp
    git diff --color=never HEAD $base_branch -- wheels/build/wheels.yml >$wheels_patch

    if [ $(stat -c %s $wheels_patch) -ne 0 ]; then
        patch -s $wheels_tmp $wheels_patch
        scp -q wheels/build/wheels.yml ${sfuser}@${sfbuild}:${new}
        scp -q $wheels_tmp ${sfuser}@${sfbuild}:${old}
        build_wheels=()
        while read op wheel; do
            case "$op" in
                A|M)
                    build_wheels+=($wheel)
                    ;;
            esac
        done < <(ssh ${sfuser}@${sfbuild} ${sfvenv}/bin/starforge wheel_diff --wheels-config=$new $old)
        for wheel in "${build_wheels[@]}"; do
            echo "Building '$wheel' wheel and sdist"
            build_wheel $wheel $new
        done
        ssh ${sfuser}@${sfbuild} "rm ${new} ${old}"
    fi

    rm ${wheels_patch} ${wheels_tmp}

else

    new=$(ssh ${sfuser}@${sfbuild} mktemp)
    scp -q wheels/build/wheels.yml ${sfuser}@${sfbuild}:${new}

    for wheel in "$@"; do
        echo "Building specified wheel: ${wheel}"
        build_wheel $wheel $new
    done

    ssh ${sfuser}@${sfbuild} "rm ${new}"

fi

if [ -d ${output} ]; then
    sha256sum ${output}/* | tee ${output}/checksums.txt
{'fraction_non_alphanumeric': 0.17791914631643752, 'fraction_numerical': 0.004104247896572953, 'mean_word_length': 2.874403815580286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '7356630', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1740, 'n_words': 406}