Skip to content

Commit ccbc643

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

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Diff for: .github/workflows/ci.yml

+35
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,36 @@ 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+
# todo: check device name with changed files
60+
echo "Changes detected in the examples or src folder. Proceeding with the build."
61+
echo "should_build=true" >> "$GITHUB_OUTPUT"
62+
fi
63+
3464
- name: Cache pip
65+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
3566
uses: actions/cache@v4
3667
with:
3768
path: ~/.cache/pip
@@ -40,6 +71,7 @@ jobs:
4071
${{ runner.os }}-pip-
4172
4273
- name: Cache PlatformIO
74+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
4375
uses: actions/cache@v4
4476
with:
4577
path: |
@@ -50,18 +82,21 @@ jobs:
5082
${{ runner.os }}-pio-
5183
5284
- name: Set up Python
85+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
5386
uses: actions/setup-python@v5
5487
with:
5588
python-version: "3.9"
5689

5790
- name: Install PlatformIO
91+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
5892
run: |
5993
python -m pip install --upgrade pip
6094
pip install --upgrade platformio
6195
pio upgrade --dev
6296
pio pkg update --global
6397
6498
- name: Build example
99+
if : ${{ steps.should-build.outputs.should_build == 'true' }}
65100
run: |
66101
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }}
67102
env:

0 commit comments

Comments
 (0)