Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: start HA, test client-cli #61

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
run: meson setup ${{github.workspace}}/build
- name: Build
run: meson compile -C ${{github.workspace}}/build
- name: start HA in the background
run: scripts/background-ha.sh
- name: test client-cli
run: LD_LIBRARY_PATH=./build/subprojects/curl-8.5.0/build/lib/.libs/ HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN=$(cat scripts/docker/longtoken.txt) build/client-cli list-entities
- uses: actions/upload-artifact@v4
with:
name: ubuntu-build
Expand Down
12 changes: 12 additions & 0 deletions scripts/background-ha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh -x

# FIXME: this started as a copy of tmux.sh, and we should see if we can unify them

PWD=`pwd`
ROOT=`dirname $0`/..

docker pull ghcr.io/home-assistant/home-assistant:stable

cp -r ${ROOT}/scripts/docker/config ${ROOT}/scripts/docker/ha-config
( cd ${ROOT}/scripts/docker && docker-compose up -d )
( cd ${ROOT}/scripts/docker && ./register.sh )
4 changes: 3 additions & 1 deletion scripts/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ services:
- /etc/localtime:/etc/localtime:ro
# restart: unless-stopped
privileged: true
network_mode: host
# network_mode: host
ports:
- 8123:8123
26 changes: 13 additions & 13 deletions scripts/docker/register.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh

CHECK_COUNT=0
curl -s 'http://localhost:8123/' 1>/dev/null
curl -s 'http://0.0.0.0:8123/' 1>/dev/null
while [ $? -ne 0 ]
do
if [ $CHECK_COUNT -gt 10 ]; then
if [ $CHECK_COUNT -gt 15 ]; then
echo "HA doesn't seem to be started after a while, giving up."
exit 1
fi
Expand All @@ -14,41 +14,41 @@ do
CHECK_COUNT=$((CHECK_COUNT+1))

# Keep on the last line because of exit status check
curl -s 'http://localhost:8123' 1>/dev/null
curl -s 'http://0.0.0.0:8123' 1>/dev/null
done


# Create voorkant user
curl 'http://localhost:8123/api/onboarding/users' -s -X POST --data-raw '{"client_id":"http://localhost:8123/","name":"voorkant","username":"voorkant","password":"v00rk4nt","language":"en-GB"}' > auth_code.json
curl 'http://0.0.0.0:8123/api/onboarding/users' -s -X POST --data-raw '{"client_id":"http://0.0.0.0:8123/","name":"voorkant","username":"voorkant","password":"v00rk4nt","language":"en-GB"}' > auth_code.json
MSG=`jq -r '.message' auth_code.json`
if [ "${MSG}" != "User step already done" ]; then
CODE=`jq -r '.auth_code' auth_code.json`
curl 'http://localhost:8123/auth/token' -s -X POST -F "grant_type=authorization_code" -F "code=${CODE}" -F "client_id=http://localhost:8123/" > token.json
curl 'http://0.0.0.0:8123/auth/token' -s -X POST -F "grant_type=authorization_code" -F "code=${CODE}" -F "client_id=http://0.0.0.0:8123/" > token.json
TOKEN=`jq -r '.access_token' token.json`
# To complete setup, you have to set some other stuff. For whatever reason (might be because demo mode) these requests are empty in our capture.
curl 'http://localhost:8123/api/onboarding/core_config' -s -X POST -H "authorization: Bearer ${TOKEN}" > /dev/null
curl 'http://localhost:8123/api/onboarding/analytics' -s -X POST -H "authorization: Bearer ${TOKEN}" > /dev/null
curl 'http://localhost:8123/api/onboarding/integration' -s -X POST -H "authorization: Bearer ${TOKEN}" -d '{"client_id":"http://localhost:8123/","redirect_uri":"http://localhost:8123/?auth_callback=1"}' > /dev/null
curl 'http://0.0.0.0:8123/api/onboarding/core_config' -s -X POST -H "authorization: Bearer ${TOKEN}" > /dev/null
curl 'http://0.0.0.0:8123/api/onboarding/analytics' -s -X POST -H "authorization: Bearer ${TOKEN}" > /dev/null
curl 'http://0.0.0.0:8123/api/onboarding/integration' -s -X POST -H "authorization: Bearer ${TOKEN}" -d '{"client_id":"http://0.0.0.0:8123/","redirect_uri":"http://0.0.0.0:8123/?auth_callback=1"}' > /dev/null

rm auth_code.json
rm token.json

if [ -x "../../build/client-cli" ]
then
HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN="${TOKEN}" LD_LIBRARY_PATH=../../build/subprojects/curl-8.5.0/build/lib/.libs/ ../../build/client-cli ha-get-token 2>register.log 1>longtoken.txt
HA_WS_URL=ws://0.0.0.0:8123/api/websocket HA_API_TOKEN="${TOKEN}" LD_LIBRARY_PATH=../../build/subprojects/curl-8.5.0/build/lib/.libs/ ../../build/client-cli ha-get-token 2>register.log 1>longtoken.txt
echo "Providing long lived token"
echo HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN="`cat longtoken.txt`"
echo HA_WS_URL=ws://0.0.0.0:8123/api/websocket HA_API_TOKEN="`cat longtoken.txt`"
else
echo "WARNING - could not find build/client-cli. Providing SHORT lived token"
echo HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN="${TOKEN}"
echo HA_WS_URL=ws://0.0.0.0:8123/api/websocket HA_API_TOKEN="${TOKEN}"
fi
else
if [ -e "longtoken.txt" ]
then
echo "Registration in HA was already completed, but found old long lived token."
echo HA_WS_URL=ws://localhost:8123/api/websocket HA_API_TOKEN="`cat longtoken.txt`"
echo HA_WS_URL=ws://0.0.0.0:8123/api/websocket HA_API_TOKEN="`cat longtoken.txt`"
else
echo "Registration in HA has already been completed, can't provide a token."
echo HA_WS_URL=ws://localhost:8123/api/websocket
echo HA_WS_URL=ws://0.0.0.0:8123/api/websocket
fi
fi
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ int main(int argc, char* argv[])

// running the uithread in the main thread makes LVGL/SDL work on macOS
uithread(backend, argc, argv);
return 0;
}

return 1;
}