Skip to content

Commit

Permalink
👷 (PlatformIO): Upload binary if wokwi.toml present
Browse files Browse the repository at this point in the history
  • Loading branch information
leon0399 committed Jul 19, 2024
1 parent fa50aae commit ce11068
Showing 1 changed file with 41 additions and 45 deletions.
86 changes: 41 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,53 @@ name: PlatformIO CI

on:
pull_request:
branches:
- main
- master
- develop
- feature/mpu6050
paths:
- "examples/**/*.ino"
- "examples/**/*"
- "src/**/*"
push:
branches:
- main
- master
- main
- develop
- feature/mpu6050
paths:
- "examples/**/*.ino"
- "src/**/*"

jobs:
platformio:
runs-on: ${{ matrix.os }}

# env:
# PLATFORMIO_BUILD_DIR: ./../build

strategy:
matrix:
os: [ ubuntu-latest ]
example:
- "examples/PCA9685/Servo/Servo.ino"
- "examples/PCA9685/VibroPulse/VibroPulse.ino"
- "examples/MPU6050/BasicReadings/BasicReadings.ino"
- "PCA9685/Servo"
- "PCA9685/VibroPulse"
- "MPU6050/BasicReadings"
boards: [ [ uno, esp32dev ] ]

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
- name: Prepare metadata
id: metadata
run: |
# get 2nd element from the example path as lowercase
DEVICE=$(echo "${{ matrix.example }}" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')
# get 1st element from the example path as lowercase
DEVICE=$(echo "${{ matrix.example }}" | cut -d'/' -f1 | 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
# check if example folder contains a wokwi.toml file
SHOULD_UPLOAD_ARTIFACTS=$(test -f "examples/${{ matrix.example }}/wokwi.toml" && echo "true" || echo "false")
echo "upload_artifact=$SHOULD_UPLOAD_ARTIFACTS" >> "$GITHUB_OUTPUT"
ARTIFACT_NAME=$(echo "${{ matrix.example }}" | tr '/' '-')
echo "artifact_name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
# mkdtemp
# export PLATFORMIO_BUILD_DIR=$(mktemp -d)
# echo "PLATFORMIO_BUILD_DIR=$PLATFORMIO_BUILD_DIR" >> "$GITHUB_ENV"
- name: Cache pip
if : ${{ steps.should-build.outputs.should_build == 'true' }}
uses: actions/cache@v4
with:
path: ~/.cache/pip
Expand All @@ -74,7 +57,6 @@ jobs:
${{ runner.os }}-pip-
- name: Cache PlatformIO
if : ${{ steps.should-build.outputs.should_build == 'true' }}
uses: actions/cache@v4
with:
path: |
Expand All @@ -85,22 +67,36 @@ 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=') }}
# for whatever reason, if we specify the build dir, it doesn't work
# mkdir -p ${{ env.PLATFORMIO_BUILD_DIR }}
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }} --keep-build-dir 2>&1 | tee output.log
export PLATFORMIO_BUILD_DIR=$(grep -oP 'The following files/directories have been created in \K.*' output.log)
echo "PLATFORMIO_BUILD_DIR=$PLATFORMIO_BUILD_DIR" >> "$GITHUB_ENV"
env:
PLATFORMIO_CI_SRC: ${{ matrix.example }}
PLATFORMIO_CI_SRC: "./examples/${{ matrix.example }}/*.ino"

- name: Upload artifacts
if: steps.metadata.outputs.upload_artifact == 'true'
uses: actions/upload-artifact@v4
with:
# change the slash to a dash
name: example-${{ steps.metadata.outputs.artifact_name }}
# name: example-${{ matrix.example }}
path: |
${{ env.PLATFORMIO_BUILD_DIR }}/.pio/build/*/firmware.*
retention-days: 1

0 comments on commit ce11068

Please sign in to comment.