Skip to content

Commit

Permalink
👷 (PlatformIO): Skip if no code was changed
Browse files Browse the repository at this point in the history
  • Loading branch information
leon0399 committed Jul 19, 2024
1 parent fc17baf commit ccbc643
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ on:
- main
- master
- develop
- feature/mpu6050
paths-ignore:
- "**/*.md"
push:
branches:
- main
- master
- develop
- feature/mpu6050
paths-ignore:
- "**/*.md"

Expand All @@ -31,7 +33,36 @@ jobs:
steps:
- uses: actions/checkout@v4

# We will skip the build if there are no changes in the examples or src folder
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
"examples/**/*.ino"
"src/**/*"
- name: Extract device name
id: device
run: |
# get 2nd element from the example path as lowercase
DEVICE=$(echo "${{ matrix.example }}" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')
echo "device=$DEVICE" >> "$GITHUB_OUTPUT"
- name: Check if the build is necessary
id: should-build
run: |
if [ -z "${{ steps.changed-files.outputs.all_modified_files }}" ]; then
echo "No changes in the examples or src folder. Skipping the build."
echo "should_build=false" >> "$GITHUB_OUTPUT"
else
# todo: check device name with changed files
echo "Changes detected in the examples or src folder. Proceeding with the build."
echo "should_build=true" >> "$GITHUB_OUTPUT"
fi
- name: Cache pip
if : ${{ steps.should-build.outputs.should_build == 'true' }}
uses: actions/cache@v4
with:
path: ~/.cache/pip
Expand All @@ -40,6 +71,7 @@ jobs:
${{ runner.os }}-pip-
- name: Cache PlatformIO
if : ${{ steps.should-build.outputs.should_build == 'true' }}
uses: actions/cache@v4
with:
path: |
Expand All @@ -50,18 +82,21 @@ jobs:
${{ runner.os }}-pio-
- name: Set up Python
if : ${{ steps.should-build.outputs.should_build == 'true' }}
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install PlatformIO
if : ${{ steps.should-build.outputs.should_build == 'true' }}
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
pio upgrade --dev
pio pkg update --global
- name: Build example
if : ${{ steps.should-build.outputs.should_build == 'true' }}
run: |
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }}
env:
Expand Down

0 comments on commit ccbc643

Please sign in to comment.