Skip to content

Instantly share code, notes, and snippets.

@kubijo
Last active July 20, 2024 19:08
Show Gist options
  • Save kubijo/e2f62a33808fd17ac5b35c6700b9ee98 to your computer and use it in GitHub Desktop.
Save kubijo/e2f62a33808fd17ac5b35c6700b9ee98 to your computer and use it in GitHub Desktop.
Download $release source maps from sentry
#!/usr/bin/env bash
SELF="${0##*/}"
function usage {
cat <<EOF
Download & server production release source-map files
if they exist in the sentry release files archive.
usage:
$0 [-h|--help] <HASH>
EOF
}
if [[ "$1" == "-h" || "$1" == "--help" || $# -eq 0 ]]; then
usage
exit 0
fi
function fail {
printf >&2 "${SELF} / Error: $1\n"
exit 1
}
set -e
HASH="$1"
PORT=5050
[[ -n $2 ]] && PORT=$2
# Check params & environment
[[ -z "${HASH}" ]] && fail "Deploy hash is required!"
[[ -z "$(which jq)" ]] && fail "\`jq\` command is required!"
[[ -z "$(which curl)" ]] && fail "\`curl\` command is required!"
[[ -z "$(which python3)" ]] && fail "\`python3\` command is required!"
DIR=/tmp/js-source-maps/${HASH}
function cleanup {
rm -rf "${DIR:?}"
}
# Remove the artifacts on EXIT
cleanup
trap cleanup EXIT
set -x
# Get the artifacts
# - fetch the list of release files
# - select only javascript source maps (id & name)
# - fetch the files into temporary directory
mkdir -p "${DIR}"
cd "${DIR}"
curl \
-s -L "${SENTRY_URL}/api/0/projects/${SENTRY_ORG}/${SENTRY_PROJECT}/releases/${HASH}/files/" \
-H "Authorization: Bearer ${SENTRY_AUTH_TOKEN}" \
| jq -r '.[] | select(.name|endswith(".js.map")) | [.id, .name] | @tsv' \
| while IFS=$'\t' read -r FILE_ID FILE_PATH; do
curl \
-s -L "${SENTRY_URL}/api/0/projects/${SENTRY_ORG}/${SENTRY_PROJECT}/releases/${HASH}/files/${FILE_ID}/" \
-H "Authorization: Bearer ${SENTRY_AUTH_TOKEN}" \
--output "$(basename "${FILE_PATH}")"
done
# Print the files list
{
printf '\n'
ls -1AhgG --time-style='+' --hyperlink=always --color=always "${DIR}"
printf '\n'
} 2>/dev/null
# Run the server
python3 -m http.server "${PORT}" --directory="${DIR}" --bind 127.0.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment