From f4d271df95a0411757b48f330efe19ca1b446559 Mon Sep 17 00:00:00 2001 From: Hayden Roche Date: Thu, 27 Jun 2024 14:52:18 -0700 Subject: [PATCH] TS-534: Switch to localtunnel from tunnelmole. I'm not exactly sure why tunnelmole doesn't work anymore, but I couldn't get it to run on the Orange Pi in my HIL setup, and there were literally no logs that I could use to debug. This commit swaps out tunnelmole for localtunnel. I tested it, and it works. --- .github/workflows/notecard-binary-tests.yml | 25 +++++----- scripts/run_lt.sh | 53 +++++++++++++++++++++ scripts/run_md5srv.sh | 4 ++ scripts/run_tunnelmole.sh | 52 -------------------- 4 files changed, 71 insertions(+), 63 deletions(-) create mode 100755 scripts/run_lt.sh delete mode 100755 scripts/run_tunnelmole.sh diff --git a/.github/workflows/notecard-binary-tests.yml b/.github/workflows/notecard-binary-tests.yml index a967dcf..b5b789a 100644 --- a/.github/workflows/notecard-binary-tests.yml +++ b/.github/workflows/notecard-binary-tests.yml @@ -41,8 +41,8 @@ jobs: # START_MD5SRV set to false to skip starting the MD5 server. There should be one # already running locally with MD5SRV_PORT/ADDRESS/TOKEN set correspondingly. START_MD5SRV: true - # START_TUNNELMOLE: set to false to skip starting tunnel mole. - START_TUNNELMOLE: true + # START_LT: set to false to skip starting localtunnel (lt). + START_LT: true # When neither tunneling solution is used (because they're already instantiated outside of the workflow) # be sure to set MD5SRV_URL in the environment steps: @@ -86,15 +86,18 @@ jobs: source venv/bin/activate export PLATFORMIO_BUILD_FLAGS="'-D NOTEHUB_PROXY_ROUTE_ALIAS=\"$NOTEHUB_PROXY_ROUTE_ALIAS\"' '-D PRODUCT_UID=\"$NOTEHUB_PRODUCT_UID\"'" echo "build flags $PLATFORMIO_BUILD_FLAGS" + # Build the firmware + platformio run -e debug timeout 10 ./scripts/wait_for_file.sh "$STLINK_PROGRAMMER_PORT" + # Upload the firmware platformio test -e debug --without-testing --upload-port "$STLINK_PROGRAMMER_PORT" --project-dir "$PIO_PROJECT_DIR" timeout 10 ./scripts/wait_for_file.sh "$SWAN_SERIAL" - - name: Start tunnelmole - if: env.START_TUNNELMOLE!='false' + - name: Start lt + if: env.START_LT!='false' run: | - rm -f tmole.log - ./scripts/run_tunnelmole.sh + rm -f lt.log + ./scripts/run_lt.sh - name: Check MD5 server is available run: | @@ -196,14 +199,14 @@ jobs: fi - - name: Cleanup tunnelmole + - name: Cleanup lt if: always() run: | - if [ -n "$TMOLE_PID" ]; then - echo "Stopping tunnelmole." - kill $TMOLE_PID + if [ -n "$LT_PID" ]; then + echo "Stopping lt." + kill $LT_PID else - echo "Tunnelmole not running (TMOLE_PID is empty)." + echo "lt not running (LT_PID is empty)." fi - name: Cleanup MD5 server diff --git a/scripts/run_lt.sh b/scripts/run_lt.sh new file mode 100755 index 0000000..76e6b7d --- /dev/null +++ b/scripts/run_lt.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +if [ -n "$MD5SRV_PORT" ]; then + echo "INFO: Using MD5 server port $MD5SRV_PORT." >&2 +else + echo "ERROR: MD5SRV_PORT not defined." >&2 + exit 1 +fi + +if ! which lt > /dev/null 2>&1; then + echo "ERROR: lt command not found." >&2 + exit 1 +fi + +echo "INFO: Starting lt..." >&2 +lt --port $MD5SRV_PORT > lt.log 2>&1 & +LT_PID=$! +echo "INFO: lt PID is $LT_PID." >&2 +echo "LT_PID=$LT_PID" >> $GITHUB_ENV +timeout 10 bash -c "until test -e lt.log; do sleep 0.1; done" +if [ $? -ne 0 ]; then + echo "ERROR: lt failed to start." >&2 + exit 1 +fi + +sleep 1 + +TIMEOUT=8 +SECONDS=0 +MD5SRV_URL="" +# Check lt.log for the MD5 server URL every second. +until [ "$SECONDS" -ge "$TIMEOUT" ] +do + MD5SRV_URL=$(grep -oP "https://[\w\d\.-]+" lt.log) + + if [ -n "$MD5SRV_URL" ]; then + break + else + SECONDS=$((SECONDS+1)) + sleep 1 + fi +done + +if [ -z "$MD5SRV_URL" ]; then + echo "ERROR: Timed out waiting for MD5 server URL to get written to lt.log." >&2 + echo "lt.log contents:" >&2 + cat lt.log >&2 + exit 1 +fi + +echo "INFO: Got MD5 server URL from lt.log." >&2 +echo "MD5SRV_URL=$MD5SRV_URL" >> $GITHUB_ENV +echo "INFO: lt ready. Logging to `realpath lt.log`" >&2 diff --git a/scripts/run_md5srv.sh b/scripts/run_md5srv.sh index 4e30380..0e7a5a3 100755 --- a/scripts/run_md5srv.sh +++ b/scripts/run_md5srv.sh @@ -1,4 +1,8 @@ . venv/bin/activate python3 ./test/hitl/scripts/md5srv.py --dir md5srv-files --save > md5srv.log 2>&1 & MD5SRV_PID=$! +if [ $? -ne 0 ]; then + echo "ERROR: Failed to start md5srv.py. Check md5srv.log." >&2 + exit 1 +fi echo "MD5SRV_PID=$MD5SRV_PID" >> $GITHUB_ENV diff --git a/scripts/run_tunnelmole.sh b/scripts/run_tunnelmole.sh deleted file mode 100755 index 5979d9b..0000000 --- a/scripts/run_tunnelmole.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -if [ -n "$MD5SRV_PORT" ]; then - echo "INFO: Using MD5 server port $MD5SRV_PORT." >&2 -else - echo "ERROR: MD5SRV_PORT not defined." >&2 - exit 1 -fi - -if ! which tmole > /dev/null 2>&1; then - echo "ERROR: tmole command not found." >&2 - exit 1 -fi - -echo "INFO: Starting tmole..." >&2 -tmole $MD5SRV_PORT > tmole.log 2>&1 & -TMOLE_PID=$! -echo "INFO: tmole PID is $TMOLE_PID." >&2 -echo "TMOLE_PID=$TMOLE_PID" >> $GITHUB_ENV -timeout 10 bash -c "until test -e tmole.log; do sleep 0.1; done" -if [ $? -ne 0 ]; then - echo "ERROR: tmole failed to start." >&2 - exit 1 -fi - -sleep 1 - - -TIMEOUT=8 -SECONDS=0 -MD5SRV_URL="" -# Check tmole.log for the MD5 server URL every second. -until [ "$SECONDS" -ge "$TIMEOUT" ] -do - MD5SRV_URL=$(grep -oP "^https://[\w\d\.-]+" tmole.log) - - if [ -n "$MD5SRV_URL" ]; then - break - else - SECONDS=$((SECONDS+1)) - sleep 1 - fi -done - -if [ -z "$MD5SRV_URL" ]; then - echo "ERROR: Timed out waiting for MD5 server URL to get written to tmole.log." >&2 - exit 1 -fi - -echo "INFO: Got MD5 server URL from tmole.log." >&2 -echo "MD5SRV_URL=$MD5SRV_URL" >> $GITHUB_ENV -echo "INFO: tmole ready. Logging to `realpath tmole.log`" >&2