#!/bin/bash

set -euxo pipefail

usage()
{
    echo "usage: build.sh --release_tag=\$release_tag --release_version=\$release_version"
}

for i in "$@"
do
    case $i in
        -t=*|--release_tag=*)
            RELEASE_TAG="${i#*=}"
            shift # past argument=value
            ;;
        -v=*|--release_version=*)
            RELEASE_VERSION="${i#*=}"
            shift # past argument=value
            ;;
        -h | --help)
            usage
            exit 0
            ;;
        *)
            usage
            exit 128
            ;;
    esac
done

if [ -z ${RELEASE_TAG+1} ] || [ -z ${RELEASE_VERSION+1} ]
then
    echo "release tag or release version is not set"
    usage
    exit 128
fi

echo "Checking out $RELEASE_TAG"

git checkout $RELEASE_TAG
$ZOOX_WORKSPACE_ROOT/ci/test/main.py custom_jobs

echo "pipedream::param::version=$RELEASE_VERSION"
