Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenroche5 committed Oct 6, 2024
1 parent 0bca2db commit adb8591
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 178 deletions.
263 changes: 128 additions & 135 deletions .github/workflows/notecard-binary-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ permissions:
checks: write

jobs:
md5srv-test:
uses: ./.github/workflows/md5srv-tests.yml
# md5srv-test:
# uses: ./.github/workflows/md5srv-tests.yml

notecard-binary-test:
# needs: md5srv-test
runs-on: [self-hosted, swan, notecard, stlink, notecard-serial, md5srv, notehub-client]
runs-on: ubuntu-latest
defaults:
run:
shell: bash
Expand All @@ -35,27 +35,25 @@ jobs:
DELETE_NOTEHUB_ROUTES: true
# CREATE_NOTEHUB_ROUTES set to false to use the already created routes on notehub
CREATE_NOTEHUB_ROUTES: true
# 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
# 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:
- name: Connect to Tailscale
uses: tailscale/github-action@v2
with:
# TODO: Add these to note-c repo.
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_CLIENT_SECRET }}
tags: tag:ci
- name: Checkout note-c repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Generate MD5 Server Token
run: |
[ -n "$MD5SRV_TOKEN" ] || echo "MD5SRV_TOKEN=`uuidgen`" >> $GITHUB_ENV
# propagate the environment variable so that it's available in the `env` context
echo "MD5SRV_PORT=$MD5SRV_PORT" >> $GITHUB_ENV
- name: Check env vars
run: |
. scripts/check_runner_config.sh
echo NOTEHUB_PROXY_ROUTE_ALIAS=$NOTEHUB_PROXY_ROUTE_ALIAS
# - name: Check env vars
# run: |
# . scripts/check_runner_config.sh
# echo NOTEHUB_PROXY_ROUTE_ALIAS=$NOTEHUB_PROXY_ROUTE_ALIAS

- name: Install PlatformIO dependencies
run: |
Expand All @@ -76,132 +74,127 @@ jobs:
mkdir md5srv-files
./scripts/run_md5srv.sh
- name: Start tunnelmole
if: env.START_TUNNELMOLE!='false'
run: |
rm -f tmole.log
./scripts/run_tmole.sh
- name: Check MD5 server is available
run: |
# the request will return a 401 from md5srv, but that's expected without the access token
# Curl still returns success because it could contact the server
code=`curl -s -o /dev/null -w "%{http_code}" $MD5SRV_URL`
MD5SRV_URL=$(ip addr show tailscale0 | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)
code=`curl -s -o /dev/null -w "%{http_code}" $MD5SRV_URL:8080`
if [ "$code" -ge "500" ]; then
echo "5xx error ($code) from tunnel."
exit 1
else
echo "MD5 server is available."
fi
- name: Create Notehub accesss token
if: env.CREATE_NOTEHUB_ROUTES!='false'
run: |
curl -f -X POST \
-L 'https://${{env.NOTEHUB}}/oauth2/token' \
-H 'content-type: application/x-www-form-urlencoded' \
-d grant_type=client_credentials \
-d client_id=$NOTEHUB_CLIENT_ID \
-d client_secret=$NOTEHUB_CLIENT_SECRET | \
{ token=$(jq -r .access_token); echo "NOTEHUB_ACCESS_TOKEN=$token" >> $GITHUB_ENV; }
- name: Create Notehub HTTP route
if: env.CREATE_NOTEHUB_ROUTES!='false'
run: |
# ?note=1 instructs the MD5 server to process the content as an event, extracting the path
# from the event body.
route_req=`jq -n --arg TOKEN "$MD5SRV_TOKEN" --arg LABEL "$NOTEHUB_HTTP_ROUTE_LABEL" --arg URL "$MD5SRV_URL/?note=1" --argjson TIMEOUT $NOTEHUB_ROUTE_TIMEOUT \
'{ "label":$LABEL, "type":"http", "http":{ "timeout":$TIMEOUT, "filter": { "type":"include", "files": ["cardbinary.qo"] }, "url":$URL, "http_headers": { "X-Access-Token":$TOKEN } } }'`
echo "Notehub HTTP route request: $route_req"
route=`echo "$route_req" | curl -s -f -X POST -L "https://$NOTEHUB_API/v1/projects/${NOTEHUB_PROJECT_UID}/routes" \
-H "Authorization: Bearer $NOTEHUB_ACCESS_TOKEN" -d @-`
echo "Notehub HTTP route: $route"
route_uid=`echo $route | jq -r .uid`
if [ -n "$route_uid" ]; then
echo "NOTEHUB_HTTP_ROUTE_UID=$route_uid" >> $GITHUB_ENV
else
echo "Failed to create or parse Notehub HTTP route."
exit 1
fi
- name: Create Notehub proxy route
run: |
ALIAS="$NOTEHUB_PROXY_ROUTE_ALIAS"
route=`jq -n --arg TOKEN "$MD5SRV_TOKEN" --arg LABEL "$NOTEHUB_PROXY_ROUTE_LABEL" --arg URL "$MD5SRV_URL" --arg ALIAS "$ALIAS" --argjson TIMEOUT $NOTEHUB_ROUTE_TIMEOUT \
'{ "label":$LABEL, "type":"proxy", "proxy":{ "timeout":$TIMEOUT, "url":$URL, "alias":$ALIAS, "http_headers": { "X-Access-Token":$TOKEN } } }' \
| curl -s -f -X POST -L "https://api.notefile.net/v1/projects/${NOTEHUB_PROJECT_UID}/routes" \
-H "Authorization: Bearer $NOTEHUB_ACCESS_TOKEN" -d @-`
echo "Notehub proxy route: $route"
route_uid=`echo "$route" | jq -r .uid`
if [ -n $route_uid ]; then
echo "NOTEHUB_PROXY_ROUTE_UID=$route_uid" >> $GITHUB_ENV
echo "NOTEHUB_PROXY_ROUTE_ALIAS=$ALIAS" >> $GITHUB_ENV
else
echo "Failed to create or parse Notehub proxy route."
exit 1
fi
- name: Build and upload test firmware and run tests
run: |
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"
cd $PIO_PROJECT_DIR
platformio test -v -e debug \
--json-output-path test.json \
--junit-output-path test.xml
- name: Publish test report
uses: mikepenz/action-junit-report@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: env.GITHUB_TOKEN && (success() || failure()) # always run even if the previous step fails
with:
report_paths: '**/test/hitl/card.binary/test*.xml'
check_name: Notecard Binary HIL Tests
require_tests: true

- name: Cleanup Notehub proxy route
if: always()
run: |
if [ "$DELETE_NOTEHUB_ROUTES" == "true" ] && [ -n "$NOTEHUB_PROXY_ROUTE_UID" ]; then
echo "Deleting Notehub proxy route."
curl -f -s -X DELETE \
-L "https://api.notefile.net/v1/projects/$NOTEHUB_PROJECT_UID/routes/$NOTEHUB_PROXY_ROUTE_UID" \
-H "Authorization: Bearer $NOTEHUB_ACCESS_TOKEN"
fi
- name: Cleanup Notehub HTTP route
if: always()
run: |
if [ "$DELETE_NOTEHUB_ROUTES" == "true" ] && [ -n "$NOTEHUB_HTTP_ROUTE_UID" ]; then
echo "Deleting Notehub HTTP route."
curl -f -s -X DELETE \
-L "https://$NOTEHUB_API/v1/projects/$NOTEHUB_PROJECT_UID/routes/$NOTEHUB_HTTP_ROUTE_UID" \
-H "Authorization: Bearer $NOTEHUB_ACCESS_TOKEN"
fi
- name: Cleanup tmole
if: always()
run: |
if [ -n "$TMOLE_PID" ]; then
echo "Stopping tmole."
kill $TMOLE_PID
else
echo "tmole not running (TMOLE_PID is empty)."
fi
- name: Cleanup MD5 server
if: always()
run: |
if [ -d md5srv-files ]; then
echo "Deleting md5srv-files directory."
rm -rf md5srv-files
fi
if [ -n "$MD5SRV_PID" ]; then
echo "Stopping MD5 server."
kill $MD5SRV_PID
else
echo "MD5 server not running (MD5SRV_PID is empty)."
fi
# - name: Create Notehub accesss token
# if: env.CREATE_NOTEHUB_ROUTES!='false'
# run: |
# curl -f -X POST \
# -L 'https://${{env.NOTEHUB}}/oauth2/token' \
# -H 'content-type: application/x-www-form-urlencoded' \
# -d grant_type=client_credentials \
# -d client_id=$NOTEHUB_CLIENT_ID \
# -d client_secret=$NOTEHUB_CLIENT_SECRET | \
# { token=$(jq -r .access_token); echo "NOTEHUB_ACCESS_TOKEN=$token" >> $GITHUB_ENV; }

# - name: Create Notehub HTTP route
# if: env.CREATE_NOTEHUB_ROUTES!='false'
# run: |
# # ?note=1 instructs the MD5 server to process the content as an event, extracting the path
# # from the event body.
# route_req=`jq -n --arg TOKEN "$MD5SRV_TOKEN" --arg LABEL "$NOTEHUB_HTTP_ROUTE_LABEL" --arg URL "$MD5SRV_URL/?note=1" --argjson TIMEOUT $NOTEHUB_ROUTE_TIMEOUT \
# '{ "label":$LABEL, "type":"http", "http":{ "timeout":$TIMEOUT, "filter": { "type":"include", "files": ["cardbinary.qo"] }, "url":$URL, "http_headers": { "X-Access-Token":$TOKEN } } }'`
# echo "Notehub HTTP route request: $route_req"
# route=`echo "$route_req" | curl -s -f -X POST -L "https://$NOTEHUB_API/v1/projects/${NOTEHUB_PROJECT_UID}/routes" \
# -H "Authorization: Bearer $NOTEHUB_ACCESS_TOKEN" -d @-`
# echo "Notehub HTTP route: $route"
# route_uid=`echo $route | jq -r .uid`
# if [ -n "$route_uid" ]; then
# echo "NOTEHUB_HTTP_ROUTE_UID=$route_uid" >> $GITHUB_ENV
# else
# echo "Failed to create or parse Notehub HTTP route."
# exit 1
# fi

# - name: Create Notehub proxy route
# run: |
# ALIAS="$NOTEHUB_PROXY_ROUTE_ALIAS"
# route=`jq -n --arg TOKEN "$MD5SRV_TOKEN" --arg LABEL "$NOTEHUB_PROXY_ROUTE_LABEL" --arg URL "$MD5SRV_URL" --arg ALIAS "$ALIAS" --argjson TIMEOUT $NOTEHUB_ROUTE_TIMEOUT \
# '{ "label":$LABEL, "type":"proxy", "proxy":{ "timeout":$TIMEOUT, "url":$URL, "alias":$ALIAS, "http_headers": { "X-Access-Token":$TOKEN } } }' \
# | curl -s -f -X POST -L "https://api.notefile.net/v1/projects/${NOTEHUB_PROJECT_UID}/routes" \
# -H "Authorization: Bearer $NOTEHUB_ACCESS_TOKEN" -d @-`
# echo "Notehub proxy route: $route"
# route_uid=`echo "$route" | jq -r .uid`
# if [ -n $route_uid ]; then
# echo "NOTEHUB_PROXY_ROUTE_UID=$route_uid" >> $GITHUB_ENV
# echo "NOTEHUB_PROXY_ROUTE_ALIAS=$ALIAS" >> $GITHUB_ENV
# else
# echo "Failed to create or parse Notehub proxy route."
# exit 1
# fi

# - name: Build and upload test firmware and run tests
# run: |
# 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"
# cd $PIO_PROJECT_DIR
# platformio test -v -e debug \
# --json-output-path test.json \
# --junit-output-path test.xml

# - name: Publish test report
# uses: mikepenz/action-junit-report@v3
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# if: env.GITHUB_TOKEN && (success() || failure()) # always run even if the previous step fails
# with:
# report_paths: '**/test/hitl/card.binary/test*.xml'
# check_name: Notecard Binary HIL Tests
# require_tests: true

# - name: Cleanup Notehub proxy route
# if: always()
# run: |
# if [ "$DELETE_NOTEHUB_ROUTES" == "true" ] && [ -n "$NOTEHUB_PROXY_ROUTE_UID" ]; then
# echo "Deleting Notehub proxy route."
# curl -f -s -X DELETE \
# -L "https://api.notefile.net/v1/projects/$NOTEHUB_PROJECT_UID/routes/$NOTEHUB_PROXY_ROUTE_UID" \
# -H "Authorization: Bearer $NOTEHUB_ACCESS_TOKEN"
# fi

# - name: Cleanup Notehub HTTP route
# if: always()
# run: |
# if [ "$DELETE_NOTEHUB_ROUTES" == "true" ] && [ -n "$NOTEHUB_HTTP_ROUTE_UID" ]; then
# echo "Deleting Notehub HTTP route."
# curl -f -s -X DELETE \
# -L "https://$NOTEHUB_API/v1/projects/$NOTEHUB_PROJECT_UID/routes/$NOTEHUB_HTTP_ROUTE_UID" \
# -H "Authorization: Bearer $NOTEHUB_ACCESS_TOKEN"
# fi


# - name: Cleanup tmole
# if: always()
# run: |
# if [ -n "$TMOLE_PID" ]; then
# echo "Stopping tmole."
# kill $TMOLE_PID
# else
# echo "tmole not running (TMOLE_PID is empty)."
# fi

# - name: Cleanup MD5 server
# if: always()
# run: |
# if [ -d md5srv-files ]; then
# echo "Deleting md5srv-files directory."
# rm -rf md5srv-files
# fi
# if [ -n "$MD5SRV_PID" ]; then
# echo "Stopping MD5 server."
# kill $MD5SRV_PID
# else
# echo "MD5 server not running (MD5SRV_PID is empty)."
# fi
12 changes: 11 additions & 1 deletion scripts/run_md5srv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
. venv/bin/activate
python3 ./test/hitl/scripts/md5srv.py --dir md5srv-files --save > md5srv.log 2>&1 &

ADDR=$(ip addr show tailscale0 | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)
if [[ -z "$ADDR" ]]; then
echo "Couldn't find tailscale0 IP address."
exit 1
fi

python3 ./test/hitl/scripts/md5srv.py \
--dir md5srv-files \
--address $ADDR \
--save > md5srv.log 2>&1 &
MD5SRV_PID=$!
echo "MD5SRV_PID=$MD5SRV_PID" >> $GITHUB_ENV
Loading

0 comments on commit adb8591

Please sign in to comment.