@@ -2,36 +2,52 @@ name: PlatformIO CI
2
2
3
3
on :
4
4
pull_request :
5
- branches :
6
- - main
7
- - master
8
- - develop
9
- paths-ignore :
10
- - " **/*.md"
5
+ paths :
6
+ - " examples/**/*"
7
+ - " src/**/*"
11
8
push :
12
9
branches :
13
- - main
14
10
- master
11
+ - main
15
12
- develop
16
- paths-ignore :
17
- - " **/*.md"
18
13
19
14
jobs :
20
15
platformio :
21
16
runs-on : ${{ matrix.os }}
22
17
18
+ # env:
19
+ # PLATFORMIO_BUILD_DIR: ./../build
20
+
23
21
strategy :
24
22
matrix :
25
23
os : [ ubuntu-latest ]
26
24
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"
30
28
boards : [ [ uno, esp32dev ] ]
31
29
32
30
steps :
33
31
- uses : actions/checkout@v4
34
32
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
+
35
51
- name : Cache pip
36
52
uses : actions/cache@v4
37
53
with :
64
80
65
81
- name : Build example
66
82
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"
68
89
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'
0 commit comments