Skip to content

Commit

Permalink
setup ci using github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bw-hro committed Oct 13, 2024
1 parent 69419e1 commit f08b9a8
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Ubuntu

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup vcpkg
run: |
chmod +x ./tools/install-vcpkg.sh
./tools/install-vcpkg.sh
- name: Build
run: |
chmod +x ./build.sh
./build.sh clean release
chmod +x ./build/examples/single-thing
chmod +x ./build/examples/multiple-things
chmod +x ./build/examples/gui-thing
chmod +x ./build/test/tests
- name: Integration tests
working-directory: ${{github.workspace}}/tools
run: |
chmod +x ./run-webthing-tester.sh
./run-webthing-tester.sh
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries
path: |
./build/examples/single-thing
./build/examples/multiple-things
./build/examples/gui-thing
./build/test/tests
45 changes: 45 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Windows

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build-and-test:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2

- name: Setup vcpkg
run: |
.\tools\install-vcpkg.bat
- name: Build
run: |
.\build.bat clean release
- name: Integration tests
working-directory: .\tools
run: |
python run-webthing-tester-windows.py
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries
path: |
.\build\examples\Release\single-thing.exe
.\build\examples\Release\multiple-things.exe
.\build\examples\Release\gui-thing.exe
.\build\test\Release\tests.exe
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if %errorlevel% equ 0 (
echo Project SSL support: %ssl_support%
copy %vcpkg_file% vcpkg.json

cmake -B "%build_dir%" -S . -DWT_WITH_SSL=%ssl_support% -DCMAKE_BUILD_TYPE=%build_type% -DCMAKE_TOOLCHAIN_FILE="%toolchain_file%" -DVCPKG_TARGET_TRIPLET="%vcpkg_triplet%" -G "Visual Studio 15 2017" -A "%build_arch%"
cmake -B "%build_dir%" -S . -DWT_WITH_SSL=%ssl_support% -DCMAKE_BUILD_TYPE=%build_type% -DCMAKE_TOOLCHAIN_FILE="%toolchain_file%" -DVCPKG_TARGET_TRIPLET="%vcpkg_triplet%" -G "Visual Studio 17 2022" -A "%build_arch%"
cmake --build "%build_dir%" --config "%build_type%"

ctest --test-dir "%build_dir%\test\"
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Webthing-CPP

[![CI Ubuntu](https://github.com/bw-hro/webthing-cpp/actions/workflows/ubuntu.yml/badge.svg?branch=master)](https://github.com/bw-hro/webthing-cpp/actions/workflows/ubuntu.yml)
[![CI Windows](https://github.com/bw-hro/webthing-cpp/actions/workflows/windows.yml/badge.svg?branch=master)](https://github.com/bw-hro/webthing-cpp/actions/workflows/windows.yml)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/bw-hro/webthing-cpp/master/LICENSE.txt)

Webthing-CPP is a modern CPP/C++17 implementation of the [WebThings API](https://webthings.io/api). Goal of the project is to offer an easy way to set up digital twins with web interface for arbitrary things by just specifying their properties, actions and events. This projects focus lies on an easy to use API heavily inspired by similar projects from the [Java](https://github.com/WebThingsIO/webthing-java) and [Python](https://github.com/WebThingsIO/webthing-python) world.

Webthing-CPP comes with MIT license without any warranty. DISCLAIMER: At the moment this project is in an early stage. Please make sure to perform sufficient number of tests if it suits your needs regarding stability before using it in production.
Expand Down
80 changes: 80 additions & 0 deletions tools/run-webthing-tester-windows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import subprocess
import sys
import time
import signal

def run_command(command, cwd=None):
"""Run a shell command."""
result = subprocess.run(command, shell=True, cwd=cwd, check=True)
return result

def clone_or_update_webthing_tester_repo():
"""Clone the repository if it doesn't exist, otherwise update it."""

repo_dir = "webthing-tester"
branch = "time-regex-option"

if os.path.isdir(repo_dir):
print(f"Updating repository in {repo_dir}...")
run_command(f"git pull origin {branch}", cwd=repo_dir)
else:
print(f"Cloning repository to {repo_dir}...")
run_command(f"git clone -b {branch} https://github.com/bw-hro/webthing-tester.git")

def install_python_dependencies():
"""Install required Python packages."""
print("Installing Python dependencies...")
run_command("pip3 install --user -r webthing-tester/requirements.txt")

def build_webthing_cpp():
"""Build Webthing-CPP if the binaries do not exist."""
single_bin = "../build/examples/Release/single-thing.exe"
multis_bin = "../build/examples/Release/multiple-things.exe"

if not os.path.exists(single_bin) or not os.path.exists(multis_bin):
print("Building Webthing-CPP with examples...")
run_command("build.bat clean release", cwd="..")
else:
print("Binaries already exist, skipping build.")

def run_example(example_path, time_regex, path_prefix=""):
"""Run the example and test it with webthing-tester."""
print(f"Running example {example_path}...")
process = subprocess.Popen([example_path])

try:
time.sleep(15) # Wait for the example to start
test_command = [
"python",
"webthing-tester/test-client.py",
"--time-regex", time_regex,
"--debug"
]
if path_prefix:
test_command.extend(["--path-prefix", path_prefix])

print(f"Running webthing-tester with {test_command}...")
run_command(" ".join(test_command))

finally:
print(f"Terminating example process {example_path}...")
process.terminate()
process.wait()

def main():
clone_or_update_webthing_tester_repo()
install_python_dependencies()
build_webthing_cpp()

# Configure time regex to match timestamps with milliseconds
time_regex = r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}[+-]\d{2}:\d{2}$"

single_example_path = "../build/examples/Release/single-thing.exe"
run_example(single_example_path, time_regex)

multiple_example_path = "../build/examples/Release/multiple-things.exe"
run_example(multiple_example_path, time_regex, path_prefix="/0")

if __name__ == "__main__":
main()

0 comments on commit f08b9a8

Please sign in to comment.