@@ -2,20 +2,10 @@ name: PlatformIO CI
2
2
3
3
on :
4
4
pull_request :
5
- branches :
6
- - main
7
- - master
8
- - develop
9
- - feature/mpu6050
10
5
paths :
11
6
- " examples/**/*.ino"
12
7
- " src/**/*"
13
8
push :
14
- branches :
15
- - main
16
- - master
17
- - develop
18
- - feature/mpu6050
19
9
paths :
20
10
- " examples/**/*.ino"
21
11
- " src/**/*"
@@ -28,44 +18,28 @@ jobs:
28
18
matrix :
29
19
os : [ ubuntu-latest ]
30
20
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"
34
24
boards : [ [ uno, esp32dev ] ]
35
25
26
+ env :
27
+ PLATFORMIO_BUILD_DIR : " ~/.build/${{ matrix.example }}"
28
+
36
29
steps :
37
30
- uses : actions/checkout@v4
38
31
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
50
33
run : |
51
34
# get 2nd element from the example path as lowercase
52
35
DEVICE=$(echo "${{ matrix.example }}" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')
53
36
echo "device=$DEVICE" >> "$GITHUB_OUTPUT"
54
37
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"
66
41
67
42
- name : Cache pip
68
- if : ${{ steps.should-build.outputs.should_build == 'true' }}
69
43
uses : actions/cache@v4
70
44
with :
71
45
path : ~/.cache/pip
74
48
${{ runner.os }}-pip-
75
49
76
50
- name : Cache PlatformIO
77
- if : ${{ steps.should-build.outputs.should_build == 'true' }}
78
51
uses : actions/cache@v4
79
52
with :
80
53
path : |
@@ -85,22 +58,32 @@ jobs:
85
58
${{ runner.os }}-pio-
86
59
87
60
- name : Set up Python
88
- if : ${{ steps.should-build.outputs.should_build == 'true' }}
89
61
uses : actions/setup-python@v5
90
62
with :
91
63
python-version : " 3.9"
92
64
93
65
- name : Install PlatformIO
94
- if : ${{ steps.should-build.outputs.should_build == 'true' }}
95
66
run : |
96
67
python -m pip install --upgrade pip
97
68
pip install --upgrade platformio
98
69
pio upgrade --dev
99
70
pio pkg update --global
100
71
101
72
- name : Build example
102
- if : ${{ steps.should-build.outputs.should_build == 'true' }}
103
73
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
105
76
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