Skip to content

Commit 3662331

Browse files
committed
Add CI on GitHub Actions
1 parent e0736ba commit 3662331

File tree

5 files changed

+130
-7
lines changed

5 files changed

+130
-7
lines changed

.github/workflows/tests.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Tests
2+
on:
3+
push:
4+
branches: [ master ]
5+
pull_request:
6+
branches: [ master ]
7+
jobs:
8+
9+
tests:
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os: [ ubuntu-latest ] # , macos-latest, windows-latest ]
15+
python-version: [ "3.6", "3.7", "3.8" ]
16+
include:
17+
- os: ubuntu-latest
18+
path: ~/.cache/pip
19+
#- os: macos-latest
20+
# path: ~/Library/Caches/pip
21+
#- os: windows-latest
22+
# path: ~\AppData\Local\pip\Cache
23+
24+
# https://docs.github.com/en/free-pro-team@latest/actions/guides/about-service-containers
25+
services:
26+
27+
# TODO: Maybe use https://github.com/marketplace/actions/mosquitto-mqtt-broker-in-github-actions
28+
mosquitto:
29+
image: eclipse-mosquitto:1.6.12
30+
ports:
31+
- 1883:1883
32+
- 9001:9001
33+
34+
influxdb:
35+
image: influxdb:1.8.3
36+
ports:
37+
- 8083:8083
38+
- 8086:8086
39+
40+
grafana:
41+
image: grafana/grafana:7.3.3
42+
ports:
43+
- 3000:3000
44+
env:
45+
GF_SECURITY_ADMIN_PASSWORD: admin
46+
47+
mongodb:
48+
image: mongo:4.4.3
49+
ports:
50+
- 27017:27017
51+
52+
env:
53+
OS: ${{ matrix.os }}
54+
PYTHON: ${{ matrix.python-version }}
55+
56+
name: Python ${{ matrix.python-version }} on OS ${{ matrix.os }}
57+
steps:
58+
59+
- name: Acquire sources
60+
uses: actions/checkout@v2
61+
62+
- name: Setup Python
63+
uses: actions/setup-python@v2
64+
with:
65+
python-version: ${{ matrix.python-version }}
66+
architecture: x64
67+
68+
- name: Apply caching of dependencies
69+
uses: actions/cache@v2
70+
with:
71+
path: ${{ matrix.path }}
72+
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py', 'requirements-dev.txt', 'requirements-test.txt', 'requirements-docs.txt') }}
73+
restore-keys: |
74+
${{ runner.os }}-pip-
75+
76+
- name: Install program
77+
run: |
78+
pip install --requirement=requirements-dev.txt
79+
pip install --requirement=requirements-test.txt
80+
pip install --editable=.[daq,daq_geospatial,export,scientific,firmware]
81+
82+
- name: Run tests
83+
run: |
84+
85+
# Run unit- and integration-tests
86+
pytest kotori test
87+
88+
# Run doctests
89+
export NOSE_IGNORE_FILES="test_.*\.py"
90+
nosetests \
91+
--with-doctest --doctest-tests --doctest-extension=rst \
92+
kotori/*.py \
93+
kotori/daq/{application,graphing,services,storage,strategy} \
94+
kotori/daq/intercom/{mqtt/paho.py,udp.py,wamp.py} \
95+
kotori/firmware kotori/io kotori/vendor/hiveeyes
96+
97+
- name: Setup Graphviz
98+
uses: ts-graphviz/setup-graphviz@v1
99+
100+
- name: Build documentation
101+
run: |
102+
pip install --requirement=requirements-docs.txt
103+
SPHINXOPTS="-j auto" make --directory=doc html

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ check-bump-options:
226226
pytest: virtualenv-dev
227227

228228
# Run pytest.
229-
$(pytest) kotori test --verbose --log-level DEBUG --log-cli-level DEBUG --log-format='%(asctime)-15s [%(name)-35s] %(levelname)-8s: %(message)s' --log-date-format='%Y-%m-%dT%H:%M:%S%z'
229+
$(pytest) kotori test -vvv --log-level DEBUG --log-cli-level DEBUG --log-format='%(asctime)-15s [%(name)-35s] %(levelname)-8s: %(message)s' --log-date-format='%Y-%m-%dT%H:%M:%S%z'
230230

231231
nosetest: virtualenv-dev
232232

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Kotori
3333

3434
- **Status**:
3535

36+
.. image:: https://github.com/daq-tools/kotori/workflows/Tests/badge.svg
37+
:target: https://github.com/daq-tools/kotori/actions?workflow=Tests
38+
3639
.. image:: https://img.shields.io/pypi/pyversions/kotori.svg
3740
:target: https://python.org
3841

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
# Data export: Basic formats
7777
'export': [
7878
'pyinfluxql==0.0.1',
79-
'pandas>=1.2.0,<1.3',
79+
'pandas>=1.1.5,<1.3',
8080
'numpy>=1.19.2,<1.20',
8181
'XlsxWriter>=1.3.6,<1.4',
8282
],

test/util.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import random
77
import string
8+
import sys
89

910
import pytest
1011
import requests
@@ -25,9 +26,9 @@ def boot_kotori(config):
2526
options = {
2627
'--config': config,
2728
'--debug': True,
28-
'--debug-io': True,
29-
'--debug-mqtt': True,
30-
'--debug-influx': True,
29+
'--debug_io': True,
30+
'--debug_mqtt': True,
31+
'--debug_influx': True,
3132
}
3233
loader = kotori.boot(options)
3334
return loader
@@ -145,10 +146,26 @@ def mqtt_json_sensor(topic, data):
145146

146147

147148
def mqtt_sensor(topic, payload):
149+
148150
logger.info('MQTT: Submitting reading')
149-
command = "mosquitto_pub -h localhost -t '{topic}' -m '{payload}'".format(topic=topic, payload=payload)
151+
152+
# When running on CI (GHA), run ``mosquitto_pub`` from Docker image.
153+
# https://stackoverflow.com/questions/24319662
154+
if os.environ.get("CI"):
155+
if sys.platform == "linux":
156+
mosquitto_pub = "docker run --rm --network=host eclipse-mosquitto:1.6.12 mosquitto_pub -h localhost"
157+
elif sys.platform == "darwin":
158+
mosquitto_pub = "docker run --rm eclipse-mosquitto:1.6.12 mosquitto_pub -h host.docker.internal"
159+
else:
160+
raise NotImplementedError(f"Invoking 'mosquitto_pub' through Docker on '{sys.platform}' not supported yet")
161+
else:
162+
mosquitto_pub = "mosquitto_pub -h localhost"
163+
command = f"{mosquitto_pub} -t '{topic}' -m '{payload}'"
164+
150165
logger.info('Running command {}'.format(command))
151-
os.system(command)
166+
exitcode = os.system(command)
167+
if exitcode != 0:
168+
raise ChildProcessError(f"Invoking command failed: {command}. Exit code: {exitcode}")
152169

153170

154171
def http_json_sensor(topic, data):

0 commit comments

Comments
 (0)