Created
May 6, 2020 22:59
-
-
Save beaulac/998f627beb883b7afa4c2fe94ccbf9db to your computer and use it in GitHub Desktop.
Upload sourcemaps to Raygun from Netlify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail; | |
## | |
# NETLIFY VARS | |
# (https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables) | |
## | |
PUBLIC_URL="${URL}"; | |
if [[ -z "${PUBLIC_URL}" ]]; then | |
echo "NO PUBLIC URL SET - Is this Netlify!?"; | |
exit 1; | |
fi | |
## | |
# OUR VARS | |
## | |
BUILD_DIR='build'; | |
if [[ -z "${RAYGUN_APP_ID}" || -z "${RAYGUN_KEY}" ]]; then | |
echo "MISSING RAYGUN CONFIG, skipping sourcemap upload"; | |
exit 0; | |
fi | |
upload_to_raygun() { | |
local FILE="${1}"; | |
local FILE_URL="${2}"; | |
curl \ | |
-s -S -X POST \ | |
-F "url=${FILE_URL}" \ | |
-F "file=@${FILE}" \ | |
"https://app.raygun.com/upload/jssymbols/${RAYGUN_APP_ID}?authToken=${RAYGUN_KEY}"; | |
echo "Uploaded sourcemap for ${FILE_URL}"; | |
} | |
FILES=$( find ${BUILD_DIR} -type f \( -iname \*.js -o -iname \*.map \) ); | |
for f in ${FILES}; do | |
upload_to_raygun "${f}" "${f//${BUILD_DIR}/${PUBLIC_URL}}"; | |
# Remove sourcemap files: | |
[[ "${f}" =~ \.map$ ]] && rm "${f}"; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment