#!/bin/env bash function checkout_commit() { # args: # PIPE_ROOT: The root path of the pipeline # STEP_NAME: The name of the step to setup # COMMIT: The commit to be used local PIPE_ROOT=$1 local STEP_NAME=$2 local COMMIT=$4 local STEPS_DIR=${PIPE_ROOT}/pipeline local STEP_DIR=${STEPS_DIR}/${STEP_NAME} cd ${STEP_DIR} git checkout ${COMMIT} > /dev/null 2>&1 if [[ $? != 0 ]]; then echo "ERROR: could not checkout the provided commit" return $? fi; local CUR_COMMIT=`git rev-parse --short HEAD` echo "The repo is now in commit: ${CUR_COMMIT}" cd ${PIPE_ROOT} return 0 } function setup_step_from_git_repo() { # args: # PIPE_ROOT: The root path of the pipeline # STEP_NAME: The name of the step to setup # REPO_URL: The https url of the repo (must be public) # COMMIT: The commit to be used local PIPE_ROOT=$1 local STEP_NAME=$2 local REPO_URL=$3 local COMMIT=$4 local STEPS_DIR="${PIPE_ROOT}/pipeline" local STEP_DIR="${STEPS_DIR}/${STEP_NAME}" echo ">>> Setup ${STEP_NAME} from ${REPO_URL}:${COMMIT}" # If the step does not exists in the pipeline if [ ! -d ${STEP_DIR} ]; then cd ${STEPS_DIR} git clone ${REPO_URL} if [[ $? != 0 ]]; then echo "ERROR: could not git clone from the provided url" return $? fi; cd ${PIPE_ROOT} fi; # if git repo then Checkout commit if [ -d ${STEP_DIR}/.git ]; then checkout_commit ${PIPE_ROOT} ${STEP_NAME} ${COMMIT} if [[ $? != 0 ]]; then return $? fi; else echo "ERROR: the source must be under Git version control" return 1 fi; return 0 } function setup_step() { # args: # PIPE_ROOT: The root path of the pipeline # STEP_NAME: The name of the step to setup local PIPE_ROOT=$1 local STEP_NAME=$2 local STEPS=`./stoml ${PIPE_ROOT}/config.toml steps` if [[ ! " ${STEPS[*]} " =~ " ${STEP_NAME} " ]]; then echo "ERROR: the step: ${STEP_NAME} is not defined." return 1 fi local TYPE=`./stoml ${PIPE_ROOT}/config.toml steps.${STEP_NAME}.type` case $TYPE in git_repo) local REPO_URL=`./stoml ${PIPE_ROOT}/config.toml steps.${STEP_NAME}.repo_url` local COMMIT=`./stoml ${PIPE_ROOT}/config.toml steps.${STEP_NAME}.commit` # setup the step setup_step_from_git_repo ${PIPE_ROOT} ${STEP_NAME} ${REPO_URL} ${COMMIT} if [[ $? != 0 ]]; then return $? fi; # create a runtime-parameters for the step if [ ! -d ${PIPE_ROOT}/${RUNTIME_PARAMS}/${STEP_NAME} ]; then mkdir ${PIPE_ROOT}/${RUNTIME_PARAMS}/${STEP_NAME} if [[ $? != 0 ]]; then echo "ERROR: Could not create the runtime-parameters folder. Do you have the write-rights there: ${PIPE_ROOT}/${RUNTIME_PARAM} ?" return $? fi; fi; ;; *) echo "ERROR: TYPE: ${TYPE} not supported." return 1 ;; esac return 0 } function setup_pipeline() { local PIPE_ROOT=`pwd` local STEP_NAMES=(`./stoml ${PIPE_ROOT}/config.toml pipeline`) echo ">>> Steps: ${STEP_NAMES[@]}" for STEP_NAME in "${STEP_NAMES[@]}"; do setup_step ${PIPE_ROOT} ${STEP_NAME} if [[ $? != 0 ]]; then echo "ERROR: Could not setup step: ${STEP_NAME}" return $? fi; done; return 0 }