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 (macos) #43

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
91c22b2
try to start HA in tmux
Habbie Jan 25, 2024
a40734a
check for token
Habbie Jan 25, 2024
7bbbccf
try calling docker compose directly
Habbie Jan 25, 2024
e6b2e74
logs
Habbie Jan 25, 2024
d2bc3fd
register
Habbie Jan 25, 2024
ca31f42
exit 1 if we cannot connect to HA
Habbie Jan 25, 2024
1cea668
test client-cli
Habbie Jan 25, 2024
517f788
curl ld path
Habbie Jan 25, 2024
acf2462
note
Habbie Jan 26, 2024
34f4e94
move a few steps into background-ha.sh, for reuse on macos
Habbie Feb 29, 2024
e7236c8
subshells
Habbie Feb 29, 2024
1ca4efe
restore tmux.sh
Habbie Feb 29, 2024
3cc8143
cleanup; test on macos too
Habbie Feb 29, 2024
38fe838
install docker on macos
Habbie Feb 29, 2024
8c769e7
rebuild curl with websockets
Habbie Mar 1, 2024
471a456
install bottled curl first to get deps?
Habbie Mar 1, 2024
d213c98
don't upgrade curl deps
Habbie Mar 1, 2024
a9e7d33
debug: homebrew-core git diff
Habbie Mar 1, 2024
baef91d
debug: homebrew-core pwd
Habbie Mar 1, 2024
cc79622
be less picky about whitespace
Habbie Mar 1, 2024
51992f6
use 0.0.0.0 instead of localhost
Habbie Mar 1, 2024
4717f98
expose ports for macos docker where network_mode: host does not mean …
Habbie Mar 2, 2024
060e233
and then drop host mode
Habbie Mar 2, 2024
9c7bee2
docker-compose logs
Habbie Mar 2, 2024
e52d752
bump check count to 20
Habbie Mar 3, 2024
8bbbe3b
bump check count to a ridiculous 120
Habbie Mar 3, 2024
d656ebc
now it worked in 7 seconds. setting default to 30
Habbie Mar 3, 2024
1c73a52
undebug
Habbie Mar 3, 2024
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
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,39 @@ 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
path: ${{github.workspace}}/build
build-macos:
runs-on: macos-latest
steps:
- name: Setup Docker on macOS
uses: douglascamata/setup-docker-macos-action@v1-alpha
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install dependencies (brew)
run: brew install gcc meson nlohmann-json sdl2 curl
- name: Custom curl build
run: |
HOMEBREW_NO_INSTALL_FROM_API=1 brew tap homebrew/core
perl -i -pe 's/^(\s*args = %W\[)/$1\n--enable-websockets/' /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/c/curl.rb
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core && pwd && git diff
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 HOMEBREW_NO_INSTALL_FROM_API=1 brew reinstall -s curl
- name: Meson setup
run: PKG_CONFIG_PATH="/usr/local/opt/curl/lib/pkgconfig" meson setup ${{github.workspace}}/build
env:
CC: gcc
- run: meson compile -C ${{github.workspace}}/build -v
- 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: macos-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 30 ]; 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;
}
Loading