#!/usr/bin/env bash

#############################################################################
#                                                                           #
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN     #
#                                                                           #
#############################################################################

# script exit when a command fails
set -o errexit
# catch a command error in pipe execution
set -o pipefail
# exit when try to use undeclared variables
# set -o nounset
# print and expand each command to stdout before executing it
set -o xtrace

if [ $# -eq 0 ]; then
  echo "Missing required argument: environment"
  exit 1
fi

export ENV=$1
export AWS_DEFAULT_REGION="eu-west-1"
export VERSION="${DRONE_TAG:-$DRONE_COMMIT_SHA}"

version=$(grep -m1 version Cargo.toml | cut -d'"' -f2)

if [[ "$DRONE_TAG" != "$version" ]]; then
  echo "Package version $version does not match release version $DRONE_TAG"
  exit 1
fi

git checkout .
cargo login "$CARGO_AUTH_KEY"
cargo publish --all-features
