#!/usr/bin/env sh

export STACK_CONFIG_PATH=${CI_PROJECT_DIR}/stacks/${stack}
export STACK_CONFIG=${STACK_CONFIG_PATH}/config.json

export SPACK_VERSION=$(jq -r .spack.version ${STACK_CONFIG})
export MOUNT_POINT=$(jq -r .stack.mount_point ${STACK_CONFIG})
export STACK_VERSION=$(jq -r .stack.version ${STACK_CONFIG})
export STACK_LOCATION=${MOUNT_POINT}/${stack}/${environment}/${STACK_VERSION}

export SPACK_SYSTEM_CONFIG_PATH=${STACK_LOCATION}/spack/var/spack/environments/${environment}

#export SPACK_USER_CACHE_PATH=$(mktemp -p /tmp -d slurm_user_cache_XXXXXXX)
#export SPACK_USER_CONFIG_PATH=$(mktemp -p /tmp -d slurm_user_config_XXXXXXX)

export environment_type="local_cluster"

echo "STACK_CONFIG_PATH: ${STACK_CONFIG_PATH}"
echo "STACK_CONFIG: ${STACK_CONFIG}"
echo "SPACK_VERSION: ${SPACK_VERSION}"
echo "MOUNT_POINT: ${MOUNT_POINT}"
echo "STACK_LOCATION: ${STACK_LOCATION}"
echo "SPACK_SYSTEM_CONFIG_PATH: ${SPACK_SYSTEM_CONFIG_PATH}"
# echo "SPACK_USER_CACHE_PATH: ${SPACK_USER_CACHE_PATH}"
# echo "SPACK_USER_CONFIG_PATH: ${SPACK_USER_CONFIG_PATH}"

set +o nounset

if [ "x${CI_DEFAULT_BRANCH}" != "x" ]
then
   squash_base=${CI_DEFAULT_BRANCH}
else
   squash_base=main
fi

if [ "x${CI_MERGE_REQUEST_IID}" != "x" ]
then
    squash_id=${CI_MERGE_REQUEST_IID}
elif [ "x${CI_COMMIT_BRANCH}" != "x" ]
then
    squash_id=${CI_MERGE_REQUEST_IID}
else
    squash_id="local"
fi

set -o nounset
