diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0f5c07..956ed78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: - main - master - develop + - feature/mpu6050 paths-ignore: - "**/*.md" push: @@ -13,6 +14,7 @@ on: - main - master - develop + - feature/mpu6050 paths-ignore: - "**/*.md" @@ -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 @@ -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: | @@ -50,11 +82,13 @@ 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 @@ -62,6 +96,7 @@ 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=') }} env: