Skip to content

Commit bf6740e

Browse files
committed
Stop yelling variable names in bin/e2e
The convention is capitalised variable names are intended for environment variables that are exported and passed between processes. This change makes it clear that only RAILS_ENV and REDIS_URL are, in fact, env vars.
1 parent 1687a66 commit bf6740e

1 file changed

Lines changed: 63 additions & 63 deletions

File tree

bin/e2e

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
set -euo pipefail
33

44
# Rails
5-
RAILS_ENV="end_to_end"
6-
RAILS_PORT="4100"
7-
HEALTH_CHECK_URL="http://localhost:${RAILS_PORT}/up"
8-
MAVIS_TEST_REPO="${MAVIS_TEST_REPO:-"../manage-vaccinations-in-schools-testing"}"
9-
PYTEST_ARGS=("-m" "not accessibility and not reporting and not imms_api and not pds_api")
5+
rails_port="4100"
6+
health_check_url="http://localhost:${rails_port}/up"
7+
mavis_test_repo="${mavis_test_repo:-"../manage-vaccinations-in-schools-testing"}"
8+
pytest_args=("-m" "not accessibility and not reporting and not imms_api and not pds_api")
109

10+
export RAILS_ENV="end_to_end"
1111
export REDIS_URL="redis://localhost:6379/2"
1212

1313
# Argument handling
@@ -19,7 +19,7 @@ function print_help() {
1919
echo "run by default."
2020
echo ""
2121
echo "The pytest CLI command defaults to:"
22-
echo " uv run pytest ${PYTEST_ARGS[*]} <pytest-target>"
22+
echo " uv run pytest ${pytest_args[*]} <pytest-target>"
2323
echo ""
2424
echo "Options:"
2525
echo " --main Force sync testing repo to latest main branch. WARNING: this"
@@ -38,35 +38,35 @@ if ! command -v uv >/dev/null 2>&1; then
3838
exit 1
3939
fi
4040

41-
if [ ! -d "$MAVIS_TEST_REPO/.git" ]; then
42-
echo "[e2e] ERROR: Testing repo not found at: $MAVIS_TEST_REPO" >&2
43-
echo " Clone the repo there or set the MAVIS_TEST_REPO" >&2
41+
if [ ! -d "$mavis_test_repo/.git" ]; then
42+
echo "[e2e] ERROR: Testing repo not found at: $mavis_test_repo" >&2
43+
echo " Clone the repo there or set the mavis_test_repo" >&2
4444
echo " environment variable to the path of your repo" >&2
4545
exit 1
4646
fi
4747

4848
# Consume --main flag if present
49-
USE_MAVIS_BRANCH=false
49+
use_mavis_branch=false
5050

5151
for arg in "$@"; do
5252
case "$arg" in
5353
--main)
54-
USE_MAVIS_BRANCH=true
54+
use_mavis_branch=true
5555
;;
5656
-h|--help)
5757
print_help
5858
exit 0
5959
;;
6060
*)
61-
PYTEST_ARGS+=("$arg")
61+
pytest_args+=("$arg")
6262
;;
6363
esac
6464
done
6565

6666
# Update mavis testing repo
67-
if [ "${USE_MAVIS_BRANCH:-false}" = true ]; then
67+
if [ "${use_mavis_branch:-false}" = true ]; then
6868
echo "[e2e] Using latest main branch of testing repo."
69-
pushd "$MAVIS_TEST_REPO" > /dev/null
69+
pushd "$mavis_test_repo" > /dev/null
7070

7171
git fetch origin
7272
git checkout main
@@ -80,48 +80,48 @@ else
8080
echo "[e2e] Checking branch alignment with testing repo..."
8181

8282
# Service (main) repo branch
83-
MAVIS_REPO="$(git rev-parse --show-toplevel 2>/dev/null || echo "")"
84-
MAVIS_BRANCH="unknown"
85-
if [ -n "$MAVIS_REPO" ]; then
86-
MAVIS_BRANCH="$(git -C "$MAVIS_REPO" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "HEAD")"
83+
mavis_repo="$(git rev-parse --show-toplevel 2>/dev/null || echo "")"
84+
mavis_branch="unknown"
85+
if [ -n "$mavis_repo" ]; then
86+
mavis_branch="$(git -C "$mavis_repo" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "HEAD")"
8787
fi
8888

8989
# Testing repo branch
90-
MAVIS_TEST_BRANCH="unknown"
91-
if git -C "$MAVIS_TEST_REPO" rev-parse --git-dir >/dev/null 2>&1; then
92-
MAVIS_TEST_BRANCH="$(git -C "$MAVIS_TEST_REPO" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "HEAD")"
90+
mavis_test_branch="unknown"
91+
if git -C "$mavis_test_repo" rev-parse --git-dir >/dev/null 2>&1; then
92+
mavis_test_branch="$(git -C "$mavis_test_repo" rev-parse --abbrev-ref HEAD 2>/dev/null || echo "HEAD")"
9393
fi
9494

9595
# If testing repo is on main, warn if it's behind origin/main
96-
if [ "$MAVIS_TEST_BRANCH" = "main" ]; then
96+
if [ "$mavis_test_branch" = "main" ]; then
9797
# Fetch without failing the whole script if it goes wrong
98-
git -C "$MAVIS_TEST_REPO" fetch origin main >/dev/null 2>&1 || true
98+
git -C "$mavis_test_repo" fetch origin main >/dev/null 2>&1 || true
9999

100-
LOCAL_MAIN_SHA="$(git -C "$MAVIS_TEST_REPO" rev-parse main 2>/dev/null || echo "")"
101-
REMOTE_MAIN_SHA="$(git -C "$MAVIS_TEST_REPO" rev-parse origin/main 2>/dev/null || echo "")"
100+
local_main_sha="$(git -C "$mavis_test_repo" rev-parse main 2>/dev/null || echo "")"
101+
remote_main_sha="$(git -C "$mavis_test_repo" rev-parse origin/main 2>/dev/null || echo "")"
102102

103-
if [ -n "$LOCAL_MAIN_SHA" ] && [ -n "$REMOTE_MAIN_SHA" ] && [ "$LOCAL_MAIN_SHA" != "$REMOTE_MAIN_SHA" ]; then
104-
AHEAD_BEHIND="$(git -C "$MAVIS_TEST_REPO" rev-list --left-right --count main...origin/main 2>/dev/null || echo "")"
105-
set -- $AHEAD_BEHIND
106-
LOCAL_AHEAD="$1"
107-
LOCAL_BEHIND="$2"
103+
if [ -n "$local_main_sha" ] && [ -n "$remote_main_sha" ] && [ "$local_main_sha" != "$remote_main_sha" ]; then
104+
ahead_behind="$(git -C "$mavis_test_repo" rev-list --left-right --count main...origin/main 2>/dev/null || echo "")"
105+
set -- $ahead_behind
106+
local_ahead="$1"
107+
local_behind="$2"
108108

109109
# Warn if local main differs from remote
110-
if [ -n "$LOCAL_BEHIND" ] && [ "$LOCAL_BEHIND" -gt 0 ] 2>/dev/null; then
111-
echo "[e2e] !!! WARNING !!! Testing repo 'main' is behind origin/main by $LOCAL_BEHIND commit(s)."
112-
echo "[e2e] Run 'git -C \"$MAVIS_TEST_REPO\" pull --ff-only origin main' "
110+
if [ -n "$local_behind" ] && [ "$local_behind" -gt 0 ] 2>/dev/null; then
111+
echo "[e2e] !!! WARNING !!! Testing repo 'main' is behind origin/main by $local_behind commit(s)."
112+
echo "[e2e] Run 'git -C \"$mavis_test_repo\" pull --ff-only origin main' "
113113
echo "[e2e] or use --main to force-sync."
114-
elif [ -n "$LOCAL_AHEAD" ] && [ "$LOCAL_AHEAD" -gt 0 ] 2>/dev/null; then
115-
echo "[e2e] !!! WARNING !!! Testing repo 'main' is ahead of origin/main by $LOCAL_AHEAD commit(s)."
116-
echo "[e2e] Run 'git -C \"$MAVIS_TEST_REPO\" pull --ff-only origin main' "
114+
elif [ -n "$local_ahead" ] && [ "$local_ahead" -gt 0 ] 2>/dev/null; then
115+
echo "[e2e] !!! WARNING !!! Testing repo 'main' is ahead of origin/main by $local_ahead commit(s)."
116+
echo "[e2e] Run 'git -C \"$mavis_test_repo\" pull --ff-only origin main' "
117117
echo "[e2e] or use --main to force-sync."
118118
fi
119119
else
120120
echo "[e2e] Testing repo 'main' branch is up to date with origin/main."
121121
fi
122-
elif [ "$MAVIS_BRANCH" != "$MAVIS_TEST_BRANCH" ]; then
123-
echo "[e2e] !!! WARNING !!! Service repo branch ($MAVIS_BRANCH) "
124-
echo "[e2e] does not match testing repo branch ($MAVIS_TEST_BRANCH)."
122+
elif [ "$mavis_branch" != "$mavis_test_branch" ]; then
123+
echo "[e2e] !!! WARNING !!! Service repo branch ($mavis_branch) "
124+
echo "[e2e] does not match testing repo branch ($mavis_test_branch)."
125125
echo "[e2e] You may be running tests from a different branch than you desire."
126126
fi
127127
fi
@@ -130,7 +130,7 @@ fi
130130

131131
echo "[e2e] Preparing Rails test DB schema (RAILS_ENV=$RAILS_ENV)..."
132132
bin/bundle install --quiet
133-
RAILS_ENV="$RAILS_ENV" bin/rails db:prepare
133+
bin/rails db:prepare
134134

135135
# Start Rails server in end_to_end environment
136136

@@ -139,43 +139,43 @@ gem install --silent foreman
139139

140140
echo "[e2e] Starting end_to_end stack with foreman..."
141141
if command -v setsid >/dev/null 2>&1; then
142-
START_FOREMAN=(setsid foreman start -f Procfile.e2e)
142+
start_foreman=(setsid foreman start -f Procfile.e2e)
143143
else
144144
# macOS does not ship a setsid binary; use Perl to create a new session.
145-
START_FOREMAN=(perl -MPOSIX -e 'POSIX::setsid() or die "setsid failed: $!"; exec @ARGV' foreman start -f Procfile.e2e)
145+
start_foreman=(perl -MPOSIX -e 'POSIX::setsid() or die "setsid failed: $!"; exec @ARGV' foreman start -f Procfile.e2e)
146146
fi
147147

148148
echo "[e2e] Starting rails server with foreman. Logs will be written to /tmp/e2e-foreman.log"
149-
RAILS_ENV="$RAILS_ENV" "${START_FOREMAN[@]}" >/tmp/e2e-foreman.log 2>&1 &
150-
E2E_PGID=$!
149+
"${start_foreman[@]}" >/tmp/e2e-foreman.log 2>&1 &
150+
e2e_pgid=$!
151151

152152

153153
cleanup() {
154154
echo "[e2e] Cleaning up end_to_end stack..."
155155

156-
if [[ -n "${E2E_PGID:-}" ]]; then
157-
echo "[e2e] Stopping process group PGID=$E2E_PGID..."
156+
if [[ -n "${e2e_pgid:-}" ]]; then
157+
echo "[e2e] Stopping process group PGID=$e2e_pgid..."
158158

159159
# Try INT (like Ctrl‑C) then TERM then KILL for the whole group
160-
for SIG in INT TERM KILL; do
160+
for sig in INT TERM KILL; do
161161
# If nothing in the group, stop
162-
if ! kill -0 "-$E2E_PGID" 2>/dev/null; then
163-
echo "[e2e] Process group $E2E_PGID already gone."
162+
if ! kill -0 "-$e2e_pgid" 2>/dev/null; then
163+
echo "[e2e] Process group $e2e_pgid already gone."
164164
break
165165
fi
166166

167-
echo "[e2e] Sending $SIG to process group $E2E_PGID..."
168-
kill "-$SIG" "-$E2E_PGID" 2>/dev/null || true
167+
echo "[e2e] Sending $sig to process group $e2e_pgid..."
168+
kill "-$sig" "-$e2e_pgid" 2>/dev/null || true
169169
sleep 3
170170
done
171171
fi
172172

173-
# Final safety net: ensure nothing is listening on $RAILS_PORT
173+
# Final safety net: ensure nothing is listening on $rails_port
174174
if command -v lsof >/dev/null 2>&1; then
175-
PIDS="$(lsof -ti tcp:"$RAILS_PORT" || true)"
176-
if [ -n "$PIDS" ]; then
177-
echo "[e2e] Forcing kill of processes on port $RAILS_PORT: $PIDS"
178-
kill -KILL $PIDS 2>/dev/null || true
175+
pids="$(lsof -ti tcp:"$rails_port" || true)"
176+
if [ -n "$pids" ]; then
177+
echo "[e2e] Forcing kill of processes on port $rails_port: $pids"
178+
kill -KILL $pids 2>/dev/null || true
179179
fi
180180
fi
181181
}
@@ -184,10 +184,10 @@ trap cleanup EXIT INT TERM
184184

185185
# Wait for Rails health
186186

187-
echo "[e2e] Waiting for Rails to become healthy on $HEALTH_CHECK_URL"
187+
echo "[e2e] Waiting for Rails to become healthy on $health_check_url"
188188
for i in {1..10}; do
189189
printf "."
190-
if curl -fsS "$HEALTH_CHECK_URL" > /dev/null 2>&1; then
190+
if curl -fsS "$health_check_url" > /dev/null 2>&1; then
191191
printf "\n[e2e] Rails is up.\n"
192192
break
193193
fi
@@ -203,13 +203,13 @@ done
203203

204204
# Run pytest via uv
205205

206-
pushd "$MAVIS_TEST_REPO" > /dev/null
206+
pushd "$mavis_test_repo" > /dev/null
207207

208208
echo "[e2e] Running end-to-end tests:"
209-
echo "[e2e] BASE_URL=\"http://localhost:${RAILS_PORT}\" uv run pytest ${PYTEST_ARGS[*]}"
210-
BASE_URL="http://localhost:${RAILS_PORT}" uv run pytest -m "not accessibility and not reporting and not imms_api and not pds_api" "${PYTEST_ARGS[@]}"
211-
PYTEST_EXIT_CODE=$?
209+
echo "[e2e] BASE_URL=\"http://localhost:${rails_port}\" uv run pytest ${pytest_args[*]}"
210+
BASE_URL="http://localhost:${rails_port}" uv run pytest -m "not accessibility and not reporting and not imms_api and not pds_api" "${pytest_args[@]}"
211+
pytest_exit_code=$?
212212

213213
popd > /dev/null
214214

215-
exit $PYTEST_EXIT_CODE
215+
exit $pytest_exit_code

0 commit comments

Comments
 (0)