From c7362b48c3738b779762ce4e873232ae981f6a0e Mon Sep 17 00:00:00 2001 From: Flavio Fernandes Date: Sat, 25 May 2024 22:30:58 -0400 Subject: [PATCH] github workflow: Create test.yml Adding an easy way for testing mqtt2kasa for pull requests. Mostly based on what is currently done in Vagrantfile Signed-off-by: Flavio Fernandes --- .github/workflows/test.yml | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6822a8f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,80 @@ +name: Test mqtt2kasa + +on: + pull_request: + branches: + - main + workflow_dispatch: + inputs: + branch_or_commit: + description: 'Branch or commit to run the workflow on' + required: true + +jobs: + test: + runs-on: ubuntu-latest + env: + VM_MEMORY: 512 + VM_CPUS: 2 + + steps: + - name: Check out the repo + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha || github.event.inputs.branch_or_commit }} + + - name: Set up environment + run: | + sudo apt-get update + sudo apt-get install -y software-properties-common + sudo add-apt-repository -y ppa:deadsnakes/ppa + sudo apt-get install -y python3.10 python3.10-venv + sudo ln -sf /usr/bin/python3.10 /usr/bin/python3 + + - name: Install Mosquitto + run: | + sudo apt-get install -y mosquitto mosquitto-clients + echo "allow_anonymous true\nbind_address 192.168.123.123" | sudo tee /etc/mosquitto/conf.d/localbroker.conf + sudo systemctl enable --now mosquitto + sudo systemctl status --full --no-pager mosquitto + + - name: Install mqtt2kasa + run: | + rm -rf env + ./mqtt2kasa/bin/create-env.sh + source env/bin/activate + pip install --upgrade pip + echo '[ -e env/bin/activate ] && source env/bin/activate' >> ~/.bashrc + ln -s data/config.yaml.vagrant ~/mqtt2kasa.config.yaml + sudo cp -v mqtt2kasa/bin/mqtt2kasa.service.vagrant /lib/systemd/system/mqtt2kasa.service + sudo systemctl enable --now mqtt2kasa.service + ln -s mqtt2kasa/bin/tail_log.sh ~/ + ln -s mqtt2kasa/bin/reload_config.sh ~/ + ln -s mqtt2kasa/tests/basic_test.sh.vagrant ~/basic_test.sh + + - name: Install and Run tplink-smarthome-simulator + run: | + if [ ! -d "tplink-smarthome-simulator" ]; then + sudo apt-get install -y nodejs npm git + git clone https://github.com/flavio-fernandes/tplink-smarthome-simulator.git + cd tplink-smarthome-simulator + npm install + for x in {201..204}; do + sudo ip a add 192.168.123.${x}/32 dev eth0 + done + sudo cp -v ../mqtt2kasa/tests/simulator.js.vagrant ./test/simulator.js + sudo cp -v ../mqtt2kasa/tests/tplink-smarthome-simulator.service.vagrant /lib/systemd/system/tplink-smarthome-simulator.service + fi + + - name: Start tplink-smarthome-simulator + run: | + sudo systemctl enable --now tplink-smarthome-simulator.service ||: + sudo systemctl status --full --no-pager tplink-smarthome-simulator.service + sudo journalctl -xeu tplink-smarthome-simulator.service + + - name: Run Tests + run: | + sudo systemctl status --full --no-pager mqtt2kasa + sudo journalctl -xeu mqtt2kasa.service + sleep 5 + ~/basic_test.sh