-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (119 loc) · 4.29 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: PlatformIO CI
on:
pull_request:
paths:
- "examples/**/*"
- "src/**/*"
push:
branches:
- master
- main
- develop
jobs:
platformio:
runs-on: ${{ matrix.os }}
# env:
# PLATFORMIO_BUILD_DIR: ./../build
strategy:
matrix:
os: [ ubuntu-latest ]
example:
- "PCA9685/Servo"
- "PCA9685/VibroPulse"
- "MPU6050/BasicReadings"
- "MAX170XX/Simple"
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:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: |
~/.platformio/.cache
./.pio
key: ${{ runner.os }}-pio-${{ hashFiles('**/*.ini') }}
restore-keys: |
${{ runner.os }}-pio-
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
pio upgrade --dev
pio pkg update --global
- name: Build example
shell: bash
run: |
# 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:
FORCE_COLOR: 2 # Enable color output
PLATFORMIO_CI_SRC: "./examples/${{ matrix.example }}/*.ino"
PLATFORMIO_BUILD_FLAGS: "-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG"
- 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: 60000
path: ./examples/${{ matrix.example }}
scenario: 'scenario.yml'
diagram_file: 'diagram.${{ matrix.board }}.json'
elf: '${{ github.workspace }}/build/${{ matrix.board }}/firmware.elf'