Skip to content

Commit 9ac4199

Browse files
authored
Merge pull request #65 from arduino/workflow_micropython
misc: Add micropython test.
2 parents 8e2f518 + 859cd30 commit 9ac4199

File tree

3 files changed

+75
-31
lines changed

3 files changed

+75
-31
lines changed

.github/workflows/client-test.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,23 @@ jobs:
3131
- name: '⏳ Checkout repository'
3232
uses: actions/checkout@v3
3333

34+
- name: '♻ Caching dependencies'
35+
uses: actions/[email protected]
36+
id: cache
37+
with:
38+
path: ~/cache/bin/
39+
key: 'micropython'
40+
3441
- name: '🐍 Set up Python'
3542
uses: actions/setup-python@v4
3643
with:
3744
cache: 'pip'
3845
python-version: "3.10"
3946

47+
- name: '🐍 Set up MicroPython'
48+
if: steps.cache.outputs.cache-hit != 'true'
49+
run: source tests/ci.sh && ci_install_micropython
50+
4051
- name: '🛠 Install dependencies'
4152
run: |
4253
python -m pip install --upgrade pip
@@ -49,7 +60,8 @@ jobs:
4960
- name: '🛠 Install package'
5061
run: |
5162
python3 -m build
52-
pip install dist/arduino_iot_cloud-*.whl
63+
pip install --user dist/arduino_iot_cloud-*.whl
64+
pip install --target=${HOME}/.micropython/lib dist/arduino_iot_cloud-*.whl
5365
5466
- name: '🔑 Configure soft crypto device'
5567
env:
@@ -59,17 +71,26 @@ jobs:
5971
run: |
6072
source tests/ci.sh && ci_configure_softhsm
6173
62-
- name: '☁️ Connect to IoT cloud (basic auth)'
74+
- name: '☁️ Connect to IoT cloud (CPython / Basic Auth)'
6375
env:
6476
DEVICE_ID: ${{ secrets.DEVICE_ID1 }}
6577
SECRET_KEY: ${{ secrets.SECRET_KEY }}
6678
run: |
6779
python tests/ci.py
6880
69-
- name: '☁️ Connect to IoT cloud (using crypto device)'
81+
- name: '☁️ Connect to IoT cloud (CPython / Crypto Auth)'
7082
env:
7183
DEVICE_ID: ${{ secrets.DEVICE_ID2 }}
7284
SECRET_KEY: ${{ secrets.SECRET_KEY }}
7385
run: |
7486
export SOFTHSM2_CONF="${HOME}/softhsm/tokens/softhsm2.conf"
7587
python tests/ci.py --crypto-device
88+
89+
- name: '☁️ Connect to IoT cloud (MicroPython / Basic Auth)'
90+
env:
91+
DEVICE_ID: ${{ secrets.DEVICE_ID1 }}
92+
SECRET_KEY: ${{ secrets.SECRET_KEY }}
93+
run: |
94+
export PATH="${HOME}/cache/bin:${PATH}"
95+
micropython -c "import sys; print(sys.path)"
96+
micropython tests/ci.py

tests/ci.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import asyncio
88
from arduino_iot_cloud import ArduinoCloudClient
99
import argparse
10-
import arduino_iot_cloud.ussl as ssl
1110

1211

1312
def exception_handler(loop, context):
@@ -47,8 +46,9 @@ def on_value_changed(client, value):
4746
# be used to authenticate, for example:
4847
# client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY)
4948
if args.crypto_device:
49+
import arduino_iot_cloud.ussl as ssl
5050
client = ArduinoCloudClient(
51-
device_id=os.environ["DEVICE_ID"],
51+
device_id=os.getenv("DEVICE_ID"),
5252
ssl_params={
5353
"pin": "1234",
5454
"keyfile": "pkcs11:token=arduino",
@@ -61,9 +61,9 @@ def on_value_changed(client, value):
6161
)
6262
else:
6363
client = ArduinoCloudClient(
64-
device_id=os.environ["DEVICE_ID"],
65-
username=os.environ["DEVICE_ID"],
66-
password=os.environ["SECRET_KEY"],
64+
device_id=os.getenv("DEVICE_ID"),
65+
username=os.getenv("DEVICE_ID"),
66+
password=os.getenv("SECRET_KEY"),
6767
)
6868

6969
# Register cloud objects.

tests/ci.sh

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,58 @@
11
#!/bin/bash
22

3+
ci_install_micropython() {
4+
CACHE_DIR=${HOME}/cache/bin
5+
mkdir -p ${CACHE_DIR}
6+
7+
sudo apt-get install gcc-arm-none-eabi libnewlib-arm-none-eabi
8+
9+
git clone --depth=1 https://github.com/micropython/micropython.git
10+
11+
cat > micropython/ports/unix/manifest.py <<-EOF
12+
include("\$(PORT_DIR)/variants/manifest.py")
13+
include("\$(MPY_DIR)/extmod/asyncio")
14+
require("bundle-networking")
15+
require("time")
16+
require("senml")
17+
require("logging")
18+
EOF
19+
20+
make -C micropython/mpy-cross/
21+
make -C micropython/ports/unix/ submodules
22+
make -C micropython/ports/unix/ FROZEN_MANIFEST=manifest.py CFLAGS_EXTRA="-DMICROPY_PY_SELECT=1"
23+
cp micropython/ports/unix/build-standard/micropython ${CACHE_DIR}
24+
}
25+
326
ci_configure_softhsm() {
4-
TOKEN_DIR=${HOME}/softhsm/tokens/
5-
TOKEN_URI="pkcs11:token=arduino"
6-
PROVIDER=/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so
27+
TOKEN_DIR=${HOME}/softhsm/tokens/
28+
TOKEN_URI="pkcs11:token=arduino"
29+
PROVIDER=/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so
730

8-
mkdir -p ${TOKEN_DIR}
9-
cat > ${TOKEN_DIR}/softhsm2.conf << EOF
10-
directories.tokendir = ${TOKEN_DIR}
11-
objectstore.backend = file
31+
mkdir -p ${TOKEN_DIR}
32+
cat > ${TOKEN_DIR}/softhsm2.conf <<-EOF
33+
directories.tokendir = ${TOKEN_DIR}
34+
objectstore.backend = file
1235
13-
# ERROR, WARNING, INFO, DEBUG
14-
log.level = ERROR
36+
# ERROR, WARNING, INFO, DEBUG
37+
log.level = ERROR
1538
16-
# If CKF_REMOVABLE_DEVICE flag should be set
17-
slots.removable = false
39+
# If CKF_REMOVABLE_DEVICE flag should be set
40+
slots.removable = false
1841
19-
# Enable and disable PKCS#11 mechanisms using slots.mechanisms.
20-
slots.mechanisms = ALL
42+
# Enable and disable PKCS#11 mechanisms using slots.mechanisms.
43+
slots.mechanisms = ALL
2144
22-
# If the library should reset the state on fork
23-
library.reset_on_fork = false
24-
EOF
45+
# If the library should reset the state on fork
46+
library.reset_on_fork = false
47+
EOF
2548

26-
export SOFTHSM2_CONF=${TOKEN_DIR}/softhsm2.conf
49+
export SOFTHSM2_CONF=${TOKEN_DIR}/softhsm2.conf
2750

28-
echo "$KEY_PEM" >> key.pem
29-
echo "$CERT_PEM" >> cert.pem
30-
echo "$CA_PEM" >> ca-root.pem
51+
echo "$KEY_PEM" >> key.pem
52+
echo "$CERT_PEM" >> cert.pem
53+
echo "$CA_PEM" >> ca-root.pem
3154

32-
softhsm2-util --init-token --slot 0 --label "arduino" --pin 1234 --so-pin 1234
33-
p11tool --provider=${PROVIDER} --login --set-pin=1234 --write ${TOKEN_URI} --load-privkey key.pem --label "mykey"
34-
p11tool --provider=${PROVIDER} --login --set-pin=1234 --write ${TOKEN_URI} --load-certificate cert.pem --label "mycert"
55+
softhsm2-util --init-token --slot 0 --label "arduino" --pin 1234 --so-pin 1234
56+
p11tool --provider=${PROVIDER} --login --set-pin=1234 --write ${TOKEN_URI} --load-privkey key.pem --label "mykey"
57+
p11tool --provider=${PROVIDER} --login --set-pin=1234 --write ${TOKEN_URI} --load-certificate cert.pem --label "mycert"
3558
}

0 commit comments

Comments
 (0)