From ce1106875ee3d3c4ef8691ed241a56c928014930 Mon Sep 17 00:00:00 2001 From: Leonid Meleshin Date: Fri, 19 Jul 2024 21:47:18 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20(PlatformIO):=20Upload=20binary?= =?UTF-8?q?=20if=20`wokwi.toml`=20present?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 86 +++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 139f0e7..b11f010 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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: | @@ -85,13 +67,11 @@ 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 @@ -99,8 +79,24 @@ jobs: 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 +