Skip to content

Commit 0f7c360

Browse files
committed
👷 (PlatformIO): Skip if no code was changed
1 parent fc17baf commit 0f7c360

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ on:
66
- main
77
- master
88
- develop
9+
- feature/mpu6050
910
paths-ignore:
1011
- "**/*.md"
1112
push:
1213
branches:
1314
- main
1415
- master
1516
- develop
17+
- feature/mpu6050
1618
paths-ignore:
1719
- "**/*.md"
1820

@@ -31,7 +33,35 @@ jobs:
3133
steps:
3234
- uses: actions/checkout@v4
3335

36+
# We will skip the build if there are no changes in the examples or src folder
37+
- name: Get changed files
38+
id: changed-files
39+
uses: tj-actions/changed-files@v44
40+
with:
41+
files: |
42+
"examples/**/*.ino"
43+
"src/**/*"
44+
45+
- name: Extract device name
46+
id: device
47+
run: |
48+
# get 2nd element from the example path as lowercase
49+
DEVICE=$(echo "${{ matrix.example }}" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')
50+
echo "device=$DEVICE" >> "$GITHUB_OUTPUT"
51+
52+
- name: Check if the build is necessary
53+
id: should-build
54+
run: |
55+
if [ -z "${{ steps.changed-files.outputs.all_modified_files }}" ]; then
56+
echo "No changes in the examples or src folder. Skipping the build."
57+
echo "should_build=false" >> "$GITHUB_OUTPUT"
58+
else
59+
echo "Changes detected in the examples or src folder. Proceeding with the build."
60+
echo "should_build=true" >> "$GITHUB_OUTPUT"
61+
fi
62+
3463
- name: Cache pip
64+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
3565
uses: actions/cache@v4
3666
with:
3767
path: ~/.cache/pip
@@ -40,6 +70,7 @@ jobs:
4070
${{ runner.os }}-pip-
4171
4272
- name: Cache PlatformIO
73+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
4374
uses: actions/cache@v4
4475
with:
4576
path: |
@@ -50,18 +81,21 @@ jobs:
5081
${{ runner.os }}-pio-
5182
5283
- name: Set up Python
84+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
5385
uses: actions/setup-python@v5
5486
with:
5587
python-version: "3.9"
5688

5789
- name: Install PlatformIO
90+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
5891
run: |
5992
python -m pip install --upgrade pip
6093
pip install --upgrade platformio
6194
pio upgrade --dev
6295
pio pkg update --global
6396
6497
- name: Build example
98+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
6599
run: |
66100
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }}
67101
env:

0 commit comments

Comments
 (0)