Skip to content

Commit 2a7abf2

Browse files
authored
fix(loader): provide js sdk assets from 4.x (#3415)
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.
1 parent db21c6c commit 2a7abf2

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

_unit-test/js-sdk-assets-test.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ source install/setup-js-sdk-assets.sh
1111
sdk_files=$(docker compose run --no-deps --rm -v "sentry-nginx-www:/var/www" nginx ls -lah /var/www/js-sdk/)
1212
sdk_tree=$(docker compose run --no-deps --rm -v "sentry-nginx-www:/var/www" nginx tree /var/www/js-sdk/ | tail -n 1)
1313

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

21-
# `sdk_tree` should outputs "2 directories, 10 files"
21+
# `sdk_tree` should output "5 directories, 17 files"
2222
echo "$sdk_tree"
23-
test "2 directories, 10 files" == "$(echo "$sdk_tree")"
23+
test "5 directories, 17 files" == "$(echo "$sdk_tree")"
2424
echo "Pass"
2525

2626
report_success

install/setup-js-sdk-assets.sh

+21-5
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,32 @@ if [[ "${SETUP_JS_SDK_ASSETS:-}" == "1" ]]; then
2121
# We want to remove everything before the first '{'.
2222
loader_registry=$(echo "$loader_registry" | sed '0,/{/s/[^{]*//')
2323

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

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

29-
# Download those two using wget
30-
for version in "${latest_js_v7}" "${latest_js_v8}"; do
33+
versions=("$latest_js_v4" "$latest_js_v5" "$latest_js_v6" "$latest_js_v7" "$latest_js_v8")
34+
variants=("bundle" "bundle.tracing" "bundle.tracing.replay" "bundle.replay" "bundle.tracing.replay.feedback" "bundle.feedback")
35+
36+
# Download those versions & variants using curl
37+
for version in "${versions[@]}"; do
3138
$dcr --no-deps --rm -v "sentry-nginx-www:/var/www" nginx mkdir -p /var/www/js-sdk/${version}
32-
for variant in "tracing" "tracing.replay" "replay" "tracing.replay.feedback" "feedback"; do
33-
$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"
39+
for variant in "${variants[@]}"; do
40+
# We want to have a HEAD lookup. If the response status code is not 200, we will skip the variant.
41+
# Taken from https://superuser.com/questions/272265/getting-curl-to-output-http-status-code#comment1025992_272273
42+
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)
43+
if [[ "$status_code" != "200" ]]; then
44+
echo "Skipping download of JS SDK v${version} for ${variant}.min.js, because the status code was ${status_code} (non 200)"
45+
continue
46+
fi
47+
48+
echo "Downloading JS SDK v${version} for ${variant}.min.js..."
49+
$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"
3450
done
3551
done
3652

unit-test.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ for test_file in _unit-test/*-test.sh; do
1111
fi
1212
echo "🙈 Running $test_file ..."
1313
$test_file
14-
if [ $? != 0 ]; then
15-
echo fail 👎
14+
exit_code=$?
15+
if [ $exit_code != 0 ]; then
16+
echo fail 👎 with exit code $exit_code
1617
fail=1
1718
fi
1819
done

0 commit comments

Comments
 (0)