#!/bin/bash
# Run a given test against the publicly released packages
#
# - Install the latest CLI somewhere and put it on the PATH.
# - Run the script
set -eu
scriptdir=$(cd $(dirname $0) && pwd)

# NPM Workspace. Will have CDK CLI installed into it.
npmws=/tmp/cdk-runrelease
rm -rf $npmws
mkdir -p $npmws

# Install the CLI and put it on the PATH
(cd $npmws && npm install aws-cdk@${RELEASE_TAG:-latest})

# FRAMEWORK_VERSION is the version that will be 'npm install'ed by the tests
if [[ "${FRAMEWORK_VERSION:-}" = "" ]]; then
  cli_version=$(cd $npmws && node -p "require('aws-cdk/package.json').version")
  export FRAMEWORK_VERSION=${cli_version}
fi

export PATH=$npmws/node_modules/.bin:$PATH
export TEST_RUNNER=release

# Run the inner script
exec "$@"
