Skip to content

Commit dbec508

Browse files
authored
Merge pull request #13 from senseshift/feature/wokwi-ci
👷 (Wokwi): Run scenarios on examples
2 parents 72b274c + 4ca0eb7 commit dbec508

File tree

6 files changed

+127
-14
lines changed

6 files changed

+127
-14
lines changed

Diff for: .github/workflows/ci.yml

+86-14
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,52 @@ name: PlatformIO CI
22

33
on:
44
pull_request:
5-
branches:
6-
- main
7-
- master
8-
- develop
9-
paths-ignore:
10-
- "**/*.md"
5+
paths:
6+
- "examples/**/*"
7+
- "src/**/*"
118
push:
129
branches:
13-
- main
1410
- master
11+
- main
1512
- develop
16-
paths-ignore:
17-
- "**/*.md"
1813

1914
jobs:
2015
platformio:
2116
runs-on: ${{ matrix.os }}
2217

18+
# env:
19+
# PLATFORMIO_BUILD_DIR: ./../build
20+
2321
strategy:
2422
matrix:
2523
os: [ ubuntu-latest ]
2624
example:
27-
- "examples/PCA9685/Servo/Servo.ino"
28-
- "examples/PCA9685/VibroPulse/VibroPulse.ino"
29-
- "examples/MPU6050/BasicReadings/BasicReadings.ino"
25+
- "PCA9685/Servo"
26+
- "PCA9685/VibroPulse"
27+
- "MPU6050/BasicReadings"
3028
boards: [ [ uno, esp32dev ] ]
3129

3230
steps:
3331
- uses: actions/checkout@v4
3432

33+
- name: Prepare metadata
34+
id: metadata
35+
run: |
36+
# get 1st element from the example path as lowercase
37+
DEVICE=$(echo "${{ matrix.example }}" | cut -d'/' -f1 | tr '[:upper:]' '[:lower:]')
38+
echo "device=$DEVICE" >> "$GITHUB_OUTPUT"
39+
40+
# check if example folder contains a wokwi.toml file
41+
SHOULD_UPLOAD_ARTIFACTS=$(test -f "examples/${{ matrix.example }}/wokwi.toml" && echo "true" || echo "false")
42+
echo "upload_artifact=$SHOULD_UPLOAD_ARTIFACTS" >> "$GITHUB_OUTPUT"
43+
44+
ARTIFACT_NAME=$(echo "${{ matrix.example }}" | tr '/' '-')
45+
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
46+
47+
# mkdtemp
48+
# export PLATFORMIO_BUILD_DIR=$(mktemp -d)
49+
# echo "PLATFORMIO_BUILD_DIR=$PLATFORMIO_BUILD_DIR" >> "$GITHUB_ENV"
50+
3551
- name: Cache pip
3652
uses: actions/cache@v4
3753
with:
@@ -64,6 +80,62 @@ jobs:
6480
6581
- name: Build example
6682
run: |
67-
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }}
83+
# for whatever reason, if we specify the build dir, it doesn't work
84+
# mkdir -p ${{ env.PLATFORMIO_BUILD_DIR }}
85+
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }} --keep-build-dir 2>&1 | tee output.log
86+
87+
export PLATFORMIO_BUILD_DIR=$(grep -oP 'The following files/directories have been created in \K.*' output.log)
88+
echo "PLATFORMIO_BUILD_DIR=$PLATFORMIO_BUILD_DIR" >> "$GITHUB_ENV"
6889
env:
69-
PLATFORMIO_CI_SRC: ${{ matrix.example }}
90+
FORCE_COLOR: 2 # Enable color output
91+
PLATFORMIO_CI_SRC: "./examples/${{ matrix.example }}/*.ino"
92+
93+
- name: Upload artifacts
94+
if: steps.metadata.outputs.upload_artifact == 'true'
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: example-${{ steps.metadata.outputs.artifact_name }}
98+
path: |
99+
${{ env.PLATFORMIO_BUILD_DIR }}/.pio/build/*/firmware.*
100+
retention-days: 1
101+
102+
wokwi:
103+
runs-on: ${{ matrix.os }}
104+
105+
needs: platformio
106+
107+
strategy:
108+
matrix:
109+
os: [ ubuntu-latest ]
110+
111+
include:
112+
- example: "MPU6050/BasicReadings"
113+
- board: uno
114+
115+
steps:
116+
- uses: actions/checkout@v4
117+
118+
- name: Prepare metadata
119+
id: metadata
120+
run: |
121+
ARTIFACT_NAME=$(echo "${{ matrix.example }}" | tr '/' '-')
122+
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
123+
124+
- uses: actions/download-artifact@v4
125+
with:
126+
name: example-${{ steps.metadata.outputs.artifact_name }}
127+
path: build
128+
129+
- name: Copy compiled firmware
130+
run: |
131+
cp -ru build/${{ matrix.board }}/* examples/${{ matrix.example }}
132+
133+
- name: Run simulation
134+
uses: leon0399/wokwi-ci-action@main
135+
with:
136+
token: ${{ secrets.WOKWI_CLI_TOKEN }}
137+
timeout: 10000
138+
path: ./examples/${{ matrix.example }}
139+
scenario: 'scenario.yml'
140+
diagram_file: 'diagram.${{ matrix.board }}.json'
141+
elf: '${{ github.workspace }}/build/${{ matrix.board }}/firmware.elf'

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
.vscode/c_cpp_properties.json
44
.vscode/launch.json
55
.vscode/ipch
6+
7+
build/

Diff for: examples/MPU6050/BasicReadings/diagram.uno.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": 1,
3+
"author": "Leonid Meleshin",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 0.6, "left": -0.6, "attrs": {} },
7+
{
8+
"type": "wokwi-mpu6050",
9+
"id": "imu1",
10+
"top": -131.42,
11+
"left": 166.12,
12+
"rotate": -90,
13+
"attrs": {}
14+
}
15+
],
16+
"connections": [ [ "uno:A4.2", "imu1:SDA", "green", [ "v0" ] ], [ "uno:A5.2", "imu1:SCL", "green", [ "v0" ] ] ],
17+
"dependencies": {}
18+
}

Diff for: examples/MPU6050/BasicReadings/scenario.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Test MPU6050/BasicReadings
2+
version: 1
3+
author: Leonid Meleshin
4+
5+
steps:
6+
- wait-serial: "MPU6050 Found!"
7+
8+
- wait-serial: "Accelerometer X: 0.00 Y: 0.00 Z: 1.00"
9+
- wait-serial: "Gyroscope X: 0.00 Y: 0.00 Z: 0.00"
10+
- wait-serial: "Temperature: 24.00 C"

Diff for: examples/MPU6050/BasicReadings/wokwi.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[wokwi]
2+
version = 1
3+
firmware = "./firmware.hex"
4+
elf = "./firmware.elf"
5+
6+
gdbServerPort=3333

Diff for: platformio.ini

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
; Please visit documentation for the other options and examples
99
; https://docs.platformio.org/page/projectconf.html
1010

11+
[env:arduino_uno]
12+
platform = atmelavr
13+
board = uno
14+
framework = arduino
15+
1116
[env:esp32dev]
1217
platform = espressif32
1318
board = esp32dev

0 commit comments

Comments
 (0)