Skip to content

Commit

Permalink
fix(loader): provide js sdk assets from 4.x (#3415)
Browse files Browse the repository at this point in the history
Hopefully fixes getsentry/sentry#22715 (comment)

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
  • Loading branch information
aldy505 authored Nov 7, 2024
1 parent db21c6c commit 2a7abf2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
10 changes: 5 additions & 5 deletions _unit-test/js-sdk-assets-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ source install/setup-js-sdk-assets.sh
sdk_files=$(docker compose run --no-deps --rm -v "sentry-nginx-www:/var/www" nginx ls -lah /var/www/js-sdk/)
sdk_tree=$(docker compose run --no-deps --rm -v "sentry-nginx-www:/var/www" nginx tree /var/www/js-sdk/ | tail -n 1)

# `sdk_files` should contains 2 lines, `7.*` and `8.*`
# `sdk_files` should contains 5 lines, '4.*', '5.*', '6.*', `7.*` and `8.*`
echo $sdk_files
total_directories=$(echo "$sdk_files" | grep -c '[78]\.[0-9]*\.[0-9]*$')
total_directories=$(echo "$sdk_files" | grep -c '[45678]\.[0-9]*\.[0-9]*$')
echo $total_directories
test "2" == "$total_directories"
test "5" == "$total_directories"
echo "Pass"

# `sdk_tree` should outputs "2 directories, 10 files"
# `sdk_tree` should output "5 directories, 17 files"
echo "$sdk_tree"
test "2 directories, 10 files" == "$(echo "$sdk_tree")"
test "5 directories, 17 files" == "$(echo "$sdk_tree")"
echo "Pass"

report_success
26 changes: 21 additions & 5 deletions install/setup-js-sdk-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,32 @@ if [[ "${SETUP_JS_SDK_ASSETS:-}" == "1" ]]; then
# We want to remove everything before the first '{'.
loader_registry=$(echo "$loader_registry" | sed '0,/{/s/[^{]*//')

# Sentry backend provides SDK versions from v4.x up to v8.x.
latest_js_v4=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("4.")))) | .[0]')
latest_js_v5=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("5.")))) | .[0]')
latest_js_v6=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("6.")))) | .[0]')
latest_js_v7=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("7.")))) | .[0]')
latest_js_v8=$(echo "$loader_registry" | $jq -r '.versions | reverse | map(select(.|any(.; startswith("8.")))) | .[0]')

echo "Found JS SDKs v${latest_js_v7} and v${latest_js_v8}, downloading from upstream.."
echo "Found JS SDKs: v${latest_js_v4}, v${latest_js_v5}, v${latest_js_v6}, v${latest_js_v7}, v${latest_js_v8}"

# Download those two using wget
for version in "${latest_js_v7}" "${latest_js_v8}"; do
versions=("$latest_js_v4" "$latest_js_v5" "$latest_js_v6" "$latest_js_v7" "$latest_js_v8")
variants=("bundle" "bundle.tracing" "bundle.tracing.replay" "bundle.replay" "bundle.tracing.replay.feedback" "bundle.feedback")

# Download those versions & variants using curl
for version in "${versions[@]}"; do
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx mkdir -p /var/www/js-sdk/${version}
for variant in "tracing" "tracing.replay" "replay" "tracing.replay.feedback" "feedback"; do
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx wget -q -O /var/www/js-sdk/${version}/bundle.${variant}.min.js "https://browser.sentry-cdn.com/${version}/bundle.${variant}.min.js"
for variant in "${variants[@]}"; do
# We want to have a HEAD lookup. If the response status code is not 200, we will skip the variant.
# Taken from https://superuser.com/questions/272265/getting-curl-to-output-http-status-code#comment1025992_272273
status_code=$($dcr --no-deps --rm nginx curl --retry 5 -sLI "https://browser.sentry-cdn.com/${version}/${variant}.min.js" 2>/dev/null | head -n 1 | cut -d$' ' -f2)
if [[ "$status_code" != "200" ]]; then
echo "Skipping download of JS SDK v${version} for ${variant}.min.js, because the status code was ${status_code} (non 200)"
continue
fi

echo "Downloading JS SDK v${version} for ${variant}.min.js..."
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx curl --retry 10 -sLo /var/www/js-sdk/${version}/${variant}.min.js "https://browser.sentry-cdn.com/${version}/${variant}.min.js"
done
done

Expand Down
5 changes: 3 additions & 2 deletions unit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ for test_file in _unit-test/*-test.sh; do
fi
echo "🙈 Running $test_file ..."
$test_file
if [ $? != 0 ]; then
echo fail 👎
exit_code=$?
if [ $exit_code != 0 ]; then
echo fail 👎 with exit code $exit_code
fail=1
fi
done
Expand Down

0 comments on commit 2a7abf2

Please sign in to comment.