Skip to content

Commit

Permalink
Merge pull request #13 from senseshift/feature/wokwi-ci
Browse files Browse the repository at this point in the history
👷 (Wokwi): Run scenarios on examples
  • Loading branch information
leon0399 authored Jul 19, 2024
2 parents 72b274c + 4ca0eb7 commit dbec508
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 14 deletions.
100 changes: 86 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,52 @@ name: PlatformIO CI

on:
pull_request:
branches:
- main
- master
- develop
paths-ignore:
- "**/*.md"
paths:
- "examples/**/*"
- "src/**/*"
push:
branches:
- main
- master
- main
- develop
paths-ignore:
- "**/*.md"

jobs:
platformio:
runs-on: ${{ matrix.os }}

# env:
# PLATFORMIO_BUILD_DIR: ./../build

strategy:
matrix:
os: [ ubuntu-latest ]
example:
- "examples/PCA9685/Servo/Servo.ino"
- "examples/PCA9685/VibroPulse/VibroPulse.ino"
- "examples/MPU6050/BasicReadings/BasicReadings.ino"
- "PCA9685/Servo"
- "PCA9685/VibroPulse"
- "MPU6050/BasicReadings"
boards: [ [ uno, esp32dev ] ]

steps:
- uses: actions/checkout@v4

- name: Prepare metadata
id: metadata
run: |
# get 1st element from the example path as lowercase
DEVICE=$(echo "${{ matrix.example }}" | cut -d'/' -f1 | tr '[:upper:]' '[:lower:]')
echo "device=$DEVICE" >> "$GITHUB_OUTPUT"
# check if example folder contains a wokwi.toml file
SHOULD_UPLOAD_ARTIFACTS=$(test -f "examples/${{ matrix.example }}/wokwi.toml" && echo "true" || echo "false")
echo "upload_artifact=$SHOULD_UPLOAD_ARTIFACTS" >> "$GITHUB_OUTPUT"
ARTIFACT_NAME=$(echo "${{ matrix.example }}" | tr '/' '-')
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
# mkdtemp
# export PLATFORMIO_BUILD_DIR=$(mktemp -d)
# echo "PLATFORMIO_BUILD_DIR=$PLATFORMIO_BUILD_DIR" >> "$GITHUB_ENV"
- name: Cache pip
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -64,6 +80,62 @@ jobs:
- name: Build example
run: |
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }}
# for whatever reason, if we specify the build dir, it doesn't work
# mkdir -p ${{ env.PLATFORMIO_BUILD_DIR }}
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }} --keep-build-dir 2>&1 | tee output.log
export PLATFORMIO_BUILD_DIR=$(grep -oP 'The following files/directories have been created in \K.*' output.log)
echo "PLATFORMIO_BUILD_DIR=$PLATFORMIO_BUILD_DIR" >> "$GITHUB_ENV"
env:
PLATFORMIO_CI_SRC: ${{ matrix.example }}
FORCE_COLOR: 2 # Enable color output
PLATFORMIO_CI_SRC: "./examples/${{ matrix.example }}/*.ino"

- name: Upload artifacts
if: steps.metadata.outputs.upload_artifact == 'true'
uses: actions/upload-artifact@v4
with:
name: example-${{ steps.metadata.outputs.artifact_name }}
path: |
${{ env.PLATFORMIO_BUILD_DIR }}/.pio/build/*/firmware.*
retention-days: 1

wokwi:
runs-on: ${{ matrix.os }}

needs: platformio

strategy:
matrix:
os: [ ubuntu-latest ]

include:
- example: "MPU6050/BasicReadings"
- board: uno

steps:
- uses: actions/checkout@v4

- name: Prepare metadata
id: metadata
run: |
ARTIFACT_NAME=$(echo "${{ matrix.example }}" | tr '/' '-')
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
- uses: actions/download-artifact@v4
with:
name: example-${{ steps.metadata.outputs.artifact_name }}
path: build

- name: Copy compiled firmware
run: |
cp -ru build/${{ matrix.board }}/* examples/${{ matrix.example }}
- name: Run simulation
uses: leon0399/wokwi-ci-action@main
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
timeout: 10000
path: ./examples/${{ matrix.example }}
scenario: 'scenario.yml'
diagram_file: 'diagram.${{ matrix.board }}.json'
elf: '${{ github.workspace }}/build/${{ matrix.board }}/firmware.elf'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

build/
18 changes: 18 additions & 0 deletions examples/MPU6050/BasicReadings/diagram.uno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"author": "Leonid Meleshin",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 0.6, "left": -0.6, "attrs": {} },
{
"type": "wokwi-mpu6050",
"id": "imu1",
"top": -131.42,
"left": 166.12,
"rotate": -90,
"attrs": {}
}
],
"connections": [ [ "uno:A4.2", "imu1:SDA", "green", [ "v0" ] ], [ "uno:A5.2", "imu1:SCL", "green", [ "v0" ] ] ],
"dependencies": {}
}
10 changes: 10 additions & 0 deletions examples/MPU6050/BasicReadings/scenario.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Test MPU6050/BasicReadings
version: 1
author: Leonid Meleshin

steps:
- wait-serial: "MPU6050 Found!"

- wait-serial: "Accelerometer X: 0.00 Y: 0.00 Z: 1.00"
- wait-serial: "Gyroscope X: 0.00 Y: 0.00 Z: 0.00"
- wait-serial: "Temperature: 24.00 C"
6 changes: 6 additions & 0 deletions examples/MPU6050/BasicReadings/wokwi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wokwi]
version = 1
firmware = "./firmware.hex"
elf = "./firmware.elf"

gdbServerPort=3333
5 changes: 5 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:arduino_uno]
platform = atmelavr
board = uno
framework = arduino

[env:esp32dev]
platform = espressif32
board = esp32dev
Expand Down

0 comments on commit dbec508

Please sign in to comment.