1
0

lighthouse.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # Change directory to the first argument passed to the script
  3. project_dir=$1
  4. shift
  5. pushd "$project_dir" || exit 1
  6. echo "Changed directory to $project_dir"
  7. # So we get stdout / stderr from Python ASAP. Without this, delays can be very long (e.g. on Windows, Github Actions)
  8. export PYTHONUNBUFFERED=1
  9. env_mode=$1
  10. shift
  11. check_ports=${1:-3000 8000}
  12. shift
  13. # Start the server in the background
  14. export TELEMETRY_ENABLED=false
  15. reflex run --env "$env_mode" "$@" & pid=$!
  16. # Within the context of this bash, $pid_in_bash is what we need to pass to "kill" on exit
  17. # This is true on all platforms.
  18. pid_in_bash=$pid
  19. trap "kill -INT $pid_in_bash ||:" EXIT
  20. echo "Started server with PID $pid"
  21. # Assume we run from the root of the repo
  22. popd
  23. # In Windows, our Python script below needs to work with the WINPID
  24. if [ -f /proc/$pid/winpid ]; then
  25. pid=$(cat /proc/$pid/winpid)
  26. echo "Windows detected, passing winpid $pid to port waiter"
  27. fi
  28. python scripts/wait_for_listening_port.py $check_ports --timeout=600 --server-pid "$pid"
  29. # Check if something is running on port 3000
  30. if curl --output /dev/null --silent --head --fail "http://localhost:3000"; then
  31. echo "URL exists: http://localhost:3000"
  32. else
  33. echo "URL does not exist: https://localhost:3000"
  34. fi
  35. mkdir -p ./tests/benchmarks/.lighthouseci
  36. # Create a lighthouserc.js file
  37. cat << EOF > lighthouserc.js
  38. module.exports = {
  39. ci: {
  40. collect: {
  41. isSinglePageApplication: true,
  42. numberOfRuns: 1,
  43. url: ['http://localhost:3000', "http://localhost:3000/docs/getting-started/introduction/", "http://localhost:3000/blog/2023-08-02-seed-annoucement/"]
  44. },
  45. upload: {
  46. target: 'filesystem',
  47. "outputDir": "./integration/benchmarks/.lighthouseci"
  48. },
  49. },
  50. };
  51. EOF
  52. # Install and Run LHCI
  53. npm install -g @lhci/cli
  54. lhci autorun
  55. # Check to see if the LHCI report is generated
  56. if [ -d "./integration/benchmarks/.lighthouseci" ] && [ "$(ls -A ./integration/benchmarks/.lighthouseci)" ]; then
  57. echo "LHCI report generated"
  58. else
  59. echo "LHCI report not generated"
  60. exit 1 # Exits the script with a status of 1, which will cause the GitHub Action to stop
  61. fi