reflex/scripts/benchmarks/benchmarks.sh
Elijah Ahianyo e0fedeb419
[REF-1682][REF-1683][REF-1684][REF-2283]Benchmark reflex package size and .web folder (#2880)
* remove codspeed.yml

* test upload job

* minor edits to get upload job working

* perhaps this works

* upload needs relex-install-size

* retrigger pipeline

* test only on ubuntu

* change to save to db directly

* oops

* size benchmarks

* .web for counter

* its timeout-minutes

* se integration.sh to run and kill process

* install psycopg2

* move .web runs to integration_tests.yml to save runners

* fix measurement-type for reflex-web

* add database url to env

* psycopg2

* test run ids

* commit sha gets the job done

* refactor

* add more matrices

* move reflex package size to integration_test.yml

* fix venv path

* test fix

* test fix

* use hyphen

* testing reflex build size

* ls for temp debug

* fix typo in command

* possible fix

* possible fix for windows

* remove dead code

* remove dead code

* remove unwanted comments

* refactor

* rebase on main

* pr_title

* remove pr_title from args

* debug

* should work now

* precommit fix

* print out package size for

* add shell

* test

* trying again

* dont use cached poetry to have accurate measurement of deps

* remove reflex deps calculation step from integration job

* fix script path

* precommit fix

* no real difference on different python versions so use 3.11.5

* remove ls keyword
2024-03-25 08:33:28 +00:00

77 lines
2.1 KiB
Bash

#!/bin/bash
# Change directory to the first argument passed to the script
project_dir=$1
shift
pushd "$project_dir" || exit 1
echo "Changed directory to $project_dir"
# So we get stdout / stderr from Python ASAP. Without this, delays can be very long (e.g. on Windows, Github Actions)
export PYTHONUNBUFFERED=1
env_mode=$1
shift
check_ports=${1:-3000 8000}
shift
# Start the server in the background
export TELEMETRY_ENABLED=false
reflex run --env "$env_mode" "$@" & pid=$!
# Within the context of this bash, $pid_in_bash is what we need to pass to "kill" on exit
# This is true on all platforms.
pid_in_bash=$pid
trap "kill -INT $pid_in_bash ||:" EXIT
echo "Started server with PID $pid"
# Assume we run from the root of the repo
popd
# In Windows, our Python script below needs to work with the WINPID
if [ -f /proc/$pid/winpid ]; then
pid=$(cat /proc/$pid/winpid)
echo "Windows detected, passing winpid $pid to port waiter"
fi
python scripts/wait_for_listening_port.py $check_ports --timeout=600 --server-pid "$pid"
# Check if something is running on port 3000
if curl --output /dev/null --silent --head --fail "http://localhost:3000"; then
echo "URL exists: http://localhost:3000"
else
echo "URL does not exist: https://localhost:3000"
fi
mkdir -p ./tests/benchmarks/.lighthouseci
# Create a lighthouserc.js file
cat << EOF > lighthouserc.js
module.exports = {
ci: {
collect: {
isSinglePageApplication: true,
numberOfRuns: 1,
url: ['http://localhost:3000', "http://localhost:3000/docs/getting-started/introduction/", "http://localhost:3000/blog/2023-08-02-seed-annoucement/"]
},
upload: {
target: 'filesystem',
"outputDir": "./integration/benchmarks/.lighthouseci"
},
},
};
EOF
# Install and Run LHCI
npm install -g @lhci/cli
lhci autorun
# Check to see if the LHCI report is generated
if [ -d "./integration/benchmarks/.lighthouseci" ] && [ "$(ls -A ./integration/benchmarks/.lighthouseci)" ]; then
echo "LHCI report generated"
else
echo "LHCI report not generated"
exit 1 # Exits the script with a status of 1, which will cause the GitHub Action to stop
fi