Skip to content

Commit ec4f416

Browse files
spawniaaminvakil
andauthored
Reference paths relative to project root (#1800)
* Reference paths relative to the current script or project root Before this PR: - some scripts change the current working directory and use relative paths - different approaches are taken to know which directory a script is running in - paths are sometimes relative, sometimes absolute, sometimes traversing directories After this PR: - scripts do neither change nor care much about the current working directory - a unified approach determines the directory of the current script - paths are always relative to the project root This should resolve an issue I already tried to fix with #1798, where the contents of `./sentry` were not copied into the built container image, thus `enhance-image.sh` did not apply. Co-authored-by: Amin Vakil <[email protected]>
1 parent 4e6ddae commit ec4f416

28 files changed

+123
-143
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ repos:
1717
hooks:
1818
- id: check-case-conflict
1919
- id: check-executables-have-shebangs
20-
exclude: ^(install/|_unit-test/_test_setup.sh)
2120
- id: check-merge-conflict
2221
- id: check-symlinks
2322
- id: end-of-file-fixer

_integration-test/custom-ca-roots/setup.sh

100755100644
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#! /usr/bin/env bash
21
set -e
2+
export COMPOSE_FILE=docker-compose.yml:_integration-test/custom-ca-roots/docker-compose.test.yml
33

4-
export COMPOSE_FILE="../docker-compose.yml:./custom-ca-roots/docker-compose.test.yml"
5-
6-
TEST_NGINX_CONF_PATH="./custom-ca-roots/nginx"
7-
CUSTOM_CERTS_PATH="../certificates"
4+
TEST_NGINX_CONF_PATH=_integration-test/custom-ca-roots/nginx
5+
CUSTOM_CERTS_PATH=certificates
86

97
# generate tightly constrained CA
108
# NB: `-addext` requires LibreSSL 3.1.0+, or OpenSSL (brew install openssl)
@@ -42,6 +40,6 @@ openssl req -x509 -newkey rsa:2048 -nodes -days 1 -keyout $TEST_NGINX_CONF_PATH/
4240

4341
# openssl x509 -in nginx/fake.test.crt -text -noout
4442

45-
cp ./custom-ca-roots/test.py ../sentry/test-custom-ca-roots.py
43+
cp _integration-test/custom-ca-roots/test.py sentry/test-custom-ca-roots.py
4644

4745
$dc up -d fixture-custom-ca-roots

_integration-test/custom-ca-roots/teardown.sh

100755100644
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env bash
21
$dc rm -s -f -v fixture-custom-ca-roots
3-
rm -f ../certificates/test-custom-ca-roots.crt ../sentry/test-custom-ca-roots.py
2+
rm -f certificates/test-custom-ca-roots.crt sentry/test-custom-ca-roots.py
43
unset COMPOSE_FILE

_integration-test/ensure-customizations-not-present.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
source "$(dirname $0)/../install/_lib.sh"
5-
6-
source ../install/dc-detect-version.sh
4+
source install/_lib.sh
5+
source install/dc-detect-version.sh
76

87
# Negated version of ensure-customizations-work.sh, make changes in sync
98
echo "${_group}Ensure customizations not present"

_integration-test/ensure-customizations-work.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
source "$(dirname $0)/../install/_lib.sh"
5-
6-
source ../install/dc-detect-version.sh
4+
source install/_lib.sh
5+
source install/dc-detect-version.sh
76

87
# Negated version of ensure-customizations-not-present.sh, make changes in sync
98
echo "${_group}Ensure customizations work"

_integration-test/run.sh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env bash
22
set -ex
33

4-
source "$(dirname $0)/../install/_lib.sh"
5-
6-
source ../install/dc-detect-version.sh
4+
source install/_lib.sh
5+
source install/dc-detect-version.sh
76

87
echo "${_group}Setting up variables and helpers ..."
98
export SENTRY_TEST_HOST="${SENTRY_TEST_HOST:-http://localhost:9000}"
@@ -51,14 +50,14 @@ echo "${_endgroup}"
5150

5251
echo "${_group}Running tests ..."
5352
get_csrf_token() { awk '$6 == "sc" { print $7 }' $COOKIE_FILE; }
54-
sentry_api_request() { curl -s -H 'Accept: application/json; charset=utf-8' -H "Referer: $SENTRY_TEST_HOST" -H 'Content-Type: application/json' -H "X-CSRFToken: $(get_csrf_token)" -b "$COOKIE_FILE" -c "$COOKIE_FILE" "$SENTRY_TEST_HOST/$1" ${@:2}; }
53+
sentry_api_request() { curl -s -H 'Accept: application/json; charset=utf-8' -H "Referer: $SENTRY_TEST_HOST" -H 'Content-Type: application/json' -H "X-CSRFToken: $(get_csrf_token)" -b "$COOKIE_FILE" -c "$COOKIE_FILE" "$SENTRY_TEST_HOST/$1" "${@:2}"; }
5554

5655
login() {
5756
INITIAL_AUTH_REDIRECT=$(curl -sL -o /dev/null $SENTRY_TEST_HOST -w %{url_effective})
5857
if [ "$INITIAL_AUTH_REDIRECT" != "$SENTRY_TEST_HOST/auth/login/sentry/" ]; then
5958
echo "Initial /auth/login/ redirect failed, exiting..."
6059
echo "$INITIAL_AUTH_REDIRECT"
61-
exit -1
60+
exit 1
6261
fi
6362

6463
CSRF_TOKEN_FOR_LOGIN=$(curl $SENTRY_TEST_HOST -sL -c "$COOKIE_FILE" | awk -F "['\"]" '
@@ -78,7 +77,7 @@ declare -a LOGIN_TEST_STRINGS=(
7877
)
7978
for i in "${LOGIN_TEST_STRINGS[@]}"; do
8079
echo "Testing '$i'..."
81-
echo "$LOGIN_RESPONSE" | grep "$i[,}]" >&/dev/null
80+
echo "$LOGIN_RESPONSE" | grep "${i}[,}]" >&/dev/null
8281
echo "Pass."
8382
done
8483
echo "${_endgroup}"
@@ -117,7 +116,7 @@ declare -a EVENT_TEST_STRINGS=(
117116
)
118117
for i in "${EVENT_TEST_STRINGS[@]}"; do
119118
echo "Testing '$i'..."
120-
echo "$EVENT_RESPONSE" | grep "$i[,}]" >&/dev/null
119+
echo "$EVENT_RESPONSE" | grep "${i}[,}]" >&/dev/null
121120
echo "Pass."
122121
done
123122
echo "${_endgroup}"
@@ -145,16 +144,16 @@ SCOPES=$(jq -n -c --argjson scopes '["event:admin", "event:read", "member:read",
145144
SENTRY_AUTH_TOKEN=$(sentry_api_request "api/0/api-tokens/" -X POST --data "$SCOPES" | jq -r '.token')
146145
SENTRY_DSN=$(sentry_api_request "api/0/projects/sentry/native/keys/" | jq -r '.[0].dsn.secret')
147146
# Then upload the symbols to that project (note the container mounts pwd to /work)
148-
SENTRY_URL="$SENTRY_TEST_HOST" sentry-cli upload-dif --org "$SENTRY_ORG" --project "$SENTRY_PROJECT" --auth-token "$SENTRY_AUTH_TOKEN" windows.sym
147+
SENTRY_URL="$SENTRY_TEST_HOST" sentry-cli upload-dif --org "$SENTRY_ORG" --project "$SENTRY_PROJECT" --auth-token "$SENTRY_AUTH_TOKEN" _integration-test/windows.sym
149148
# Get public key for minidump upload
150149
PUBLIC_KEY=$(sentry_api_request "api/0/projects/sentry/native/keys/" | jq -r '.[0].public')
151150
# Upload the minidump to be processed, this returns the event ID of the crash dump
152-
EVENT_ID=$(sentry_api_request "api/$NATIVE_PROJECT_ID/minidump/?sentry_key=$PUBLIC_KEY" -X POST -F '[email protected]' | sed 's/\-//g')
151+
EVENT_ID=$(sentry_api_request "api/$NATIVE_PROJECT_ID/minidump/?sentry_key=$PUBLIC_KEY" -X POST -F 'upload_file_minidump=@_integration-test/windows.dmp' | sed 's/\-//g')
153152
# We have to wait for the item to be processed
154153
for i in {0..60..10}; do
155154
EVENT_PROCESSED=$(sentry_api_request "api/0/projects/$SENTRY_ORG/$SENTRY_PROJECT/events/" | jq -r '.[]|select(.id == "'"$EVENT_ID"'")|.id')
156155
if [ -z "$EVENT_PROCESSED" ]; then
157-
sleep $i
156+
sleep "$i"
158157
else
159158
break
160159
fi
@@ -167,9 +166,9 @@ fi
167166
echo "${_endgroup}"
168167

169168
echo "${_group}Test custom CAs work ..."
170-
source ./custom-ca-roots/setup.sh
169+
source _integration-test/custom-ca-roots/setup.sh
171170
$dcr --no-deps web python3 /etc/sentry/test-custom-ca-roots.py
172-
source ./custom-ca-roots/teardown.sh
171+
source _integration-test/custom-ca-roots/teardown.sh
173172
echo "${_endgroup}"
174173

175174
# Table formatting based on https://stackoverflow.com/a/39144364

_unit-test/_test_setup.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
set -euo pipefail
2-
source "$(dirname $0)/../install/_lib.sh"
2+
3+
source install/_lib.sh
4+
5+
_ORIGIN=$(pwd)
36

47
rm -rf /tmp/sentry-self-hosted-test-sandbox.*
58
_SANDBOX="$(mktemp -d /tmp/sentry-self-hosted-test-sandbox.XXX)"
69

7-
source "$basedir/install/detect-platform.sh"
8-
docker build -t sentry-self-hosted-jq-local --platform=$DOCKER_PLATFORM "$basedir/jq"
10+
source install/detect-platform.sh
11+
docker build -t sentry-self-hosted-jq-local --platform="$DOCKER_PLATFORM" jq
912

1013
report_success() {
1114
echo "$(basename $0) - Success 👍"
1215
}
1316

1417
teardown() {
1518
test "${DEBUG:-}" || rm -rf "$_SANDBOX"
19+
cd "$_ORIGIN"
1620
}
1721

1822
setup() {
19-
cd ..
20-
2123
# Clone the local repo into a temp dir. FWIW `git clone --local` breaks for
2224
# me because it depends on hard-linking, which doesn't work across devices,
2325
# and I happen to have my workspace and /tmp on separate devices.
24-
git -c advice.detachedHead=false clone --depth=1 "file://$(pwd)" "$_SANDBOX"
26+
git -c advice.detachedHead=false clone --depth=1 "file://$_ORIGIN" "$_SANDBOX"
2527

2628
# Now propagate any local changes from the working copy to the sandbox. This
2729
# provides a pretty nice dev experience: edit the files in the working copy,
@@ -47,7 +49,7 @@ setup() {
4749
esac
4850
done
4951

50-
cd "$_SANDBOX/install"
52+
cd "$_SANDBOX"
5153

5254
trap teardown EXIT
5355
}

_unit-test/create-docker-volumes-test.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
source "$(dirname $0)/_test_setup.sh"
2+
3+
source _unit-test/_test_setup.sh
34

45
get_volumes() {
56
# If grep returns no strings, we still want to return without error
@@ -20,9 +21,9 @@ before=$(get_volumes)
2021

2122
test "$before" == "" || test "$before" == "$expected_volumes"
2223

23-
source create-docker-volumes.sh
24-
source create-docker-volumes.sh
25-
source create-docker-volumes.sh
24+
source install/create-docker-volumes.sh
25+
source install/create-docker-volumes.sh
26+
source install/create-docker-volumes.sh
2627

2728
after=$(get_volumes)
2829
test "$after" == "$expected_volumes"

_unit-test/ensure-relay-credentials-test.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
#!/usr/bin/env bash
2-
source "$(dirname $0)/_test_setup.sh"
3-
source dc-detect-version.sh
2+
3+
source _unit-test/_test_setup.sh
4+
source install/dc-detect-version.sh
45

56
# using _file format for these variables since there is a creds defined in dc-detect-version.sh
6-
cfg_file="../relay/config.yml"
7-
creds_file="../relay/credentials.json"
7+
cfg_file=relay/config.yml
8+
creds_file=relay/credentials.json
89

910
# Relay files don't exist in a clean clone.
1011
test ! -f $cfg_file
1112
test ! -f $creds_file
1213

1314
# Running the install script adds them.
14-
source ensure-relay-credentials.sh
15+
source install/ensure-relay-credentials.sh
1516
test -f $cfg_file
1617
test -f $creds_file
17-
test "$(jq -r 'keys[2]' $creds_file)" = "secret_key"
18+
test "$(jq -r 'keys[2]' "$creds_file")" = "secret_key"
1819

1920
# If the files exist we don't touch it.
2021
echo GARBAGE >$cfg_file
2122
echo MOAR GARBAGE >$creds_file
22-
source ensure-relay-credentials.sh
23+
source install/ensure-relay-credentials.sh
2324
test "$(cat $cfg_file)" = "GARBAGE"
2425
test "$(cat $creds_file)" = "MOAR GARBAGE"
2526

_unit-test/error-handling-test.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env bash
2-
source "$(dirname $0)/_test_setup.sh"
2+
3+
source _unit-test/_test_setup.sh
34

45
export REPORT_SELF_HOSTED_ISSUES=1
56

67
# This is set up in dc-detect-version.sh, but for
78
# our purposes we don't care about proxies.
89
dbuild="docker build"
9-
source error-handling.sh
10+
source install/error-handling.sh
1011

1112
# mock send_envelope
1213
send_envelope() {
@@ -15,15 +16,15 @@ send_envelope() {
1516

1617
export -f send_envelope
1718
echo "Testing initial send_event"
18-
export log_path="$basedir/test_log.txt"
19-
echo "Test Logs" >"$log_path"
20-
echo "Error Msg" >>"$log_path"
19+
export log_file=test_log.txt
20+
echo "Test Logs" >"$log_file"
21+
echo "Error Msg" >>"$log_file"
2122
breadcrumbs=$(generate_breadcrumb_json | sed '$d' | $jq -s -c)
2223
SEND_EVENT_RESPONSE=$(send_event "12345123451234512345123451234512" "Test exited with status 1" "{\"ignore\": \"me\"}" "$breadcrumbs")
23-
rm "$log_path"
24+
rm "$log_file"
2425
test "$SEND_EVENT_RESPONSE" == 'Test Sending sentry-envelope-12345123451234512345123451234512'
2526
ENVELOPE_CONTENTS=$(cat /tmp/sentry-envelope-12345123451234512345123451234512)
26-
test "$ENVELOPE_CONTENTS" == "$(cat "$basedir/_unit-test/snapshots/sentry-envelope-12345123451234512345123451234512")"
27+
test "$ENVELOPE_CONTENTS" == "$(cat _unit-test/snapshots/sentry-envelope-12345123451234512345123451234512)"
2728
echo "Pass."
2829

2930
echo "Testing send_event duplicate"
@@ -36,10 +37,10 @@ echo "Testing cleanup without minimizing downtime"
3637
export REPORT_SELF_HOSTED_ISSUES=0
3738
export MINIMIZE_DOWNTIME=''
3839
export dc=':'
39-
echo "Test Logs" >"$log_path"
40+
echo "Test Logs" >"$log_file"
4041
CLEANUP_RESPONSE=$(cleanup ERROR)
41-
rm "$log_path"
42-
test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:40.
42+
rm "$log_file"
43+
test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:41.
4344
'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0
4445
4546
Cleaning up...'
@@ -48,10 +49,10 @@ echo "Pass."
4849
echo "Testing cleanup while minimizing downtime"
4950
export REPORT_SELF_HOSTED_ISSUES=0
5051
export MINIMIZE_DOWNTIME=1
51-
echo "Test Logs" >"$log_path"
52+
echo "Test Logs" >"$log_file"
5253
CLEANUP_RESPONSE=$(cleanup ERROR)
53-
rm "$log_path"
54-
test "$CLEANUP_RESPONSE" == 'Error in ./_unit-test/error-handling-test.sh:52.
54+
rm "$log_file"
55+
test "$CLEANUP_RESPONSE" == 'Error in _unit-test/error-handling-test.sh:53.
5556
'\''local cmd="${BASH_COMMAND}"'\'' exited with status 0
5657
5758
*NOT* cleaning up, to clean your environment run "docker compose stop".'

0 commit comments

Comments
 (0)