Skip to content

Commit 5ac94da

Browse files
committed
👷 (PlatformIO): Upload binary if wokwi.toml present
1 parent 3e46bd3 commit 5ac94da

File tree

1 file changed

+25
-42
lines changed

1 file changed

+25
-42
lines changed

.github/workflows/ci.yml

+25-42
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,10 @@ name: PlatformIO CI
22

33
on:
44
pull_request:
5-
branches:
6-
- main
7-
- master
8-
- develop
9-
- feature/mpu6050
105
paths:
116
- "examples/**/*.ino"
127
- "src/**/*"
138
push:
14-
branches:
15-
- main
16-
- master
17-
- develop
18-
- feature/mpu6050
199
paths:
2010
- "examples/**/*.ino"
2111
- "src/**/*"
@@ -28,44 +18,28 @@ jobs:
2818
matrix:
2919
os: [ ubuntu-latest ]
3020
example:
31-
- "examples/PCA9685/Servo/Servo.ino"
32-
- "examples/PCA9685/VibroPulse/VibroPulse.ino"
33-
- "examples/MPU6050/BasicReadings/BasicReadings.ino"
21+
- "PCA9685/Servo"
22+
- "PCA9685/VibroPulse"
23+
- "MPU6050/BasicReadings"
3424
boards: [ [ uno, esp32dev ] ]
3525

26+
env:
27+
PLATFORMIO_BUILD_DIR: "~/.build/${{ matrix.example }}"
28+
3629
steps:
3730
- uses: actions/checkout@v4
3831

39-
# We will skip the build if there are no changes in the examples or src folder
40-
- name: Get changed files
41-
id: changed-files
42-
uses: tj-actions/changed-files@v44
43-
with:
44-
files: |
45-
"examples/**/*.ino"
46-
"src/**/*"
47-
48-
- name: Extract device name
49-
id: device
32+
- id: metadata
5033
run: |
5134
# get 2nd element from the example path as lowercase
5235
DEVICE=$(echo "${{ matrix.example }}" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')
5336
echo "device=$DEVICE" >> "$GITHUB_OUTPUT"
5437
55-
- name: Check if the build is necessary
56-
id: should-build
57-
run: |
58-
if [ -z "${{ steps.changed-files.outputs.all_modified_files }}" ]; then
59-
echo "No changes in the examples or src folder. Skipping the build."
60-
echo "should_build=false" >> "$GITHUB_OUTPUT"
61-
else
62-
# todo: check device name with changed files
63-
echo "Changes detected in the examples or src folder. Proceeding with the build."
64-
echo "should_build=true" >> "$GITHUB_OUTPUT"
65-
fi
38+
// check if example folder contains a wokwi.toml file
39+
SHOULD_UPLOAD_ARTIFACTS=$(test -f "examples/${{ matrix.example }}/wokwi.toml" && echo "true" || echo "false")
40+
echo "upload_artifact=$SHOULD_UPLOAD_ARTIFACTS" >> "$GITHUB_OUTPUT"
6641
6742
- name: Cache pip
68-
if : ${{ steps.should-build.outputs.should_build == 'true' }}
6943
uses: actions/cache@v4
7044
with:
7145
path: ~/.cache/pip
@@ -74,7 +48,6 @@ jobs:
7448
${{ runner.os }}-pip-
7549
7650
- name: Cache PlatformIO
77-
if : ${{ steps.should-build.outputs.should_build == 'true' }}
7851
uses: actions/cache@v4
7952
with:
8053
path: |
@@ -85,22 +58,32 @@ jobs:
8558
${{ runner.os }}-pio-
8659
8760
- name: Set up Python
88-
if : ${{ steps.should-build.outputs.should_build == 'true' }}
8961
uses: actions/setup-python@v5
9062
with:
9163
python-version: "3.9"
9264

9365
- name: Install PlatformIO
94-
if : ${{ steps.should-build.outputs.should_build == 'true' }}
9566
run: |
9667
python -m pip install --upgrade pip
9768
pip install --upgrade platformio
9869
pio upgrade --dev
9970
pio pkg update --global
10071
10172
- name: Build example
102-
if : ${{ steps.should-build.outputs.should_build == 'true' }}
10373
run: |
104-
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }}
74+
mkdir -p $PLATFORMIO_BUILD_DIR
75+
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }} --build-dir=$PLATFORMIO_BUILD_DIR --keep-build-dir
10576
env:
106-
PLATFORMIO_CI_SRC: ${{ matrix.example }}
77+
PLATFORMIO_CI_SRC: "./examples/${{ matrix.example }}/*.ino"
78+
79+
- name: Upload artifacts
80+
if: steps.metadata.outputs.upload_artifact == 'true'
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: example-${{ matrix.example }}
84+
path: |
85+
${{ env.PLATFORMIO_BUILD_DIR }}/firmware.bin
86+
${{ env.PLATFORMIO_BUILD_DIR }}/firmware.elf
87+
${{ env.PLATFORMIO_BUILD_DIR }}/firmware.hex
88+
retention-days: 1
89+

0 commit comments

Comments
 (0)