#!/bin/sh

BASEDIR=$(dirname $0)

#set -o allexport
#source $BASEDIR/../.env
#set +o allexport

export $(grep -v '^#' $BASEDIR/../.env | grep -v 'UID=' | grep -v 'GID=' | xargs -d '\n')

echo SENTRY_URL=${SENTRY_URL}
echo SENTRY_ORG=${SENTRY_ORG}
echo SENTRY_PROJECT=${SENTRY_PROJECT}
echo PROJECT_RELEASE=${PROJECT_RELEASE}

# echo deleting old release
# sentry-cli --url https://sentry.basehosts.de --auth-token ${SENTRY_TOKEN} releases --org ${RELEASE_ORG_SLUG} --project renz-eshop delete ${PROJECT_RELEASE:-$RELEASE_PROJECT_SLUG.dirty}

echo injecting debug id
sentry-cli sourcemaps --log-level info inject frontend/dist


echo creating release and uploading sourcemaps
#sentry-cli --url https://sentry.basehosts.de --auth-token ${SENTRY_TOKEN} releases --org ${RELEASE_ORG_SLUG} --project renz-eshop files ${PROJECT_RELEASE:-$RELEASE_PROJECT_SLUG.dirty} upload-sourcemaps --url-prefix='~/' --ext js --ext mjs --ext svelte --ext map frontend
sentry-cli sourcemaps --log-level info upload --release=${PROJECT_RELEASE:-$RELEASE_PROJECT_SLUG.dirty} --url-prefix='~/dist' --ext js --ext mjs --ext map frontend/dist
