Skip to content

Commit a4cfd3a

Browse files
committed
ci: optimize build workflow with smart change detection
- Add dorny/paths-filter to detect which files changed - Only build affected firmware when specific examples are modified - Library changes (src/) trigger all builds - Manual dispatch (workflow_dispatch) still builds all - Reduces unnecessary CI time and resources
1 parent ad1e966 commit a4cfd3a

1 file changed

Lines changed: 66 additions & 2 deletions

File tree

.github/workflows/build-firmware.yml

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,60 @@ env:
3333
NEOPIXEL_VERSION: "1.15.2"
3434

3535
jobs:
36+
# ============================================================================
37+
# DETECT CHANGES | 检测文件变化
38+
# ============================================================================
39+
40+
detect-changes:
41+
runs-on: ubuntu-latest
42+
outputs:
43+
library: ${{ steps.filter.outputs.library }}
44+
iot-button: ${{ steps.filter.outputs.iot-button }}
45+
camera-stream: ${{ steps.filter.outputs.camera-stream }}
46+
reterminal-e1001: ${{ steps.filter.outputs.reterminal-e1001 }}
47+
reterminal-e1002: ${{ steps.filter.outputs.reterminal-e1002 }}
48+
wifi-provisioning: ${{ steps.filter.outputs.wifi-provisioning }}
49+
button-switch: ${{ steps.filter.outputs.button-switch }}
50+
led-switch: ${{ steps.filter.outputs.led-switch }}
51+
ha-state-subscribe: ${{ steps.filter.outputs.ha-state-subscribe }}
52+
temp-humidity: ${{ steps.filter.outputs.temp-humidity }}
53+
steps:
54+
- uses: actions/checkout@v4
55+
- uses: dorny/paths-filter@v3
56+
id: filter
57+
with:
58+
filters: |
59+
library:
60+
- 'arduino/SeeedHADiscovery/src/**'
61+
- 'arduino/SeeedHADiscovery/library.*'
62+
- '.github/workflows/build-firmware.yml'
63+
iot-button:
64+
- 'arduino/SeeedHADiscovery/examples/IoTButtonV2_DeepSleep/**'
65+
camera-stream:
66+
- 'arduino/SeeedHADiscovery/examples/CameraStream/**'
67+
reterminal-e1001:
68+
- 'arduino/SeeedHADiscovery/examples/reTerminal_E1001_HASubscribe_Display/**'
69+
reterminal-e1002:
70+
- 'arduino/SeeedHADiscovery/examples/reTerminal_E1002_HASubscribe_Display/**'
71+
wifi-provisioning:
72+
- 'arduino/SeeedHADiscovery/examples/WiFiProvisioning/**'
73+
button-switch:
74+
- 'arduino/SeeedHADiscovery/examples/ButtonSwitch/**'
75+
led-switch:
76+
- 'arduino/SeeedHADiscovery/examples/LEDSwitch/**'
77+
ha-state-subscribe:
78+
- 'arduino/SeeedHADiscovery/examples/HAStateSubscribe/**'
79+
temp-humidity:
80+
- 'arduino/SeeedHADiscovery/examples/TemperatureHumidity/**'
81+
3682
# ============================================================================
3783
# SEEED-SPECIFIC FIRMWARE | SEEED 专用固件
3884
# ============================================================================
3985

4086
# IoT Button V2 - XIAO ESP32-C6 only
4187
build-iot-button:
88+
needs: detect-changes
89+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.iot-button == 'true' }}
4290
runs-on: ubuntu-latest
4391
steps:
4492
- uses: actions/checkout@v4
@@ -81,6 +129,8 @@ jobs:
81129

82130
# Camera Stream - XIAO ESP32-S3 Sense only
83131
build-camera-stream:
132+
needs: detect-changes
133+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.camera-stream == 'true' }}
84134
runs-on: ubuntu-latest
85135
steps:
86136
- uses: actions/checkout@v4
@@ -121,6 +171,8 @@ jobs:
121171

122172
# reTerminal E1001 - ESP32-S3 based
123173
build-reterminal-e1001:
174+
needs: detect-changes
175+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.reterminal-e1001 == 'true' }}
124176
runs-on: ubuntu-latest
125177
steps:
126178
- uses: actions/checkout@v4
@@ -164,6 +216,8 @@ jobs:
164216

165217
# reTerminal E1002 - ESP32-S3 based
166218
build-reterminal-e1002:
219+
needs: detect-changes
220+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.reterminal-e1002 == 'true' }}
167221
runs-on: ubuntu-latest
168222
steps:
169223
- uses: actions/checkout@v4
@@ -211,6 +265,8 @@ jobs:
211265

212266
# WiFi Provisioning - Universal (using XIAO boards for D-pin compatibility)
213267
build-wifi-provisioning:
268+
needs: detect-changes
269+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.wifi-provisioning == 'true' }}
214270
runs-on: ubuntu-latest
215271
strategy:
216272
fail-fast: false
@@ -259,6 +315,8 @@ jobs:
259315

260316
# Button Switch - Universal (using XIAO boards for D-pin compatibility)
261317
build-button-switch:
318+
needs: detect-changes
319+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.button-switch == 'true' }}
262320
runs-on: ubuntu-latest
263321
strategy:
264322
fail-fast: false
@@ -308,6 +366,8 @@ jobs:
308366
# LED Switch - Universal (using XIAO boards for LED_BUILTIN compatibility)
309367
# Note: XIAO ESP32-C3 has no user LED, so C3 is excluded
310368
build-led-switch:
369+
needs: detect-changes
370+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.led-switch == 'true' }}
311371
runs-on: ubuntu-latest
312372
strategy:
313373
fail-fast: false
@@ -353,6 +413,8 @@ jobs:
353413

354414
# HA State Subscribe - Universal (using XIAO boards)
355415
build-ha-state-subscribe:
416+
needs: detect-changes
417+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.ha-state-subscribe == 'true' }}
356418
runs-on: ubuntu-latest
357419
strategy:
358420
fail-fast: false
@@ -401,6 +463,8 @@ jobs:
401463

402464
# Temperature Humidity - Universal (using XIAO boards)
403465
build-temp-humidity:
466+
needs: detect-changes
467+
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.library == 'true' || needs.detect-changes.outputs.temp-humidity == 'true' }}
404468
runs-on: ubuntu-latest
405469
strategy:
406470
fail-fast: false
@@ -452,8 +516,8 @@ jobs:
452516
# ============================================================================
453517

454518
combine:
455-
needs: [build-iot-button, build-camera-stream, build-wifi-provisioning, build-button-switch, build-led-switch, build-ha-state-subscribe, build-temp-humidity]
456-
if: always()
519+
needs: [detect-changes, build-iot-button, build-camera-stream, build-reterminal-e1001, build-reterminal-e1002, build-wifi-provisioning, build-button-switch, build-led-switch, build-ha-state-subscribe, build-temp-humidity]
520+
if: always() && !cancelled()
457521
runs-on: ubuntu-latest
458522
steps:
459523
- name: Download all artifacts

0 commit comments

Comments
 (0)