Skip to content

Build Firmware

Build Firmware #6

Workflow file for this run

name: Build Firmware
on:
workflow_dispatch:
inputs:
build_type:
description: 'Build type to create'
required: true
default: 'all'
type: choice
options:
- all
- standard_load
- soft_load
- high_force_load
publish_release:
description: 'Publish a GitHub Release with the built artifacts'
required: true
default: false
type: boolean
prerelease:
description: 'Mark the release as a pre-release (beta)'
required: true
default: true
type: boolean
use_version_file:
description: 'Use the root "version" file as the release version (unchecked = use run number)'
required: true
default: true
type: boolean
version_override:
description: 'Manual version/tag override (leave blank to use version file or run number)'
required: false
default: ''
type: string
jobs:
# Figures out which matrix entries should actually run based on the
# build_type input, since a plain matrix always runs everything.
plan:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
version: ${{ steps.set-version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Compute build matrix
id: set-matrix
env:
BUILD_TYPE: ${{ inputs.build_type }}
run: |
case "$BUILD_TYPE" in
all)
matrix='{"include":[
{"name":"Standard Load","soft_load":"0","p1s":"0","artifact_prefix":"standard_load"},
{"name":"Soft Load","soft_load":"1","p1s":"0","artifact_prefix":"soft_load"},
{"name":"High Force Load","soft_load":"0","p1s":"1","artifact_prefix":"high_force_load"}
]}'
;;
standard_load)
matrix='{"include":[
{"name":"Standard Load","soft_load":"0","p1s":"0","artifact_prefix":"standard_load"}
]}'
;;
soft_load)
matrix='{"include":[
{"name":"Soft Load","soft_load":"1","p1s":"0","artifact_prefix":"soft_load"}
]}'
;;
high_force_load)
matrix='{"include":[
{"name":"High Force Load","soft_load":"0","p1s":"1","artifact_prefix":"high_force_load"}
]}'
;;
*)
echo "Unknown build_type: $BUILD_TYPE"
exit 1
;;
esac
echo "matrix=$(echo "$matrix" | jq -c .)" >> "$GITHUB_OUTPUT"
- name: Compute version string
id: set-version
env:
USE_VERSION_FILE: ${{ inputs.use_version_file }}
VERSION_OVERRIDE: ${{ inputs.version_override }}
run: |
if [[ -n "$VERSION_OVERRIDE" ]]; then
version="$VERSION_OVERRIDE"
elif [[ "$USE_VERSION_FILE" == "true" && -f version ]]; then
version="$(tr -d '[:space:]' < version)"
else
version="run${{ github.run_number }}-${GITHUB_SHA::7}"
fi
echo "Resolved version: $version"
echo "version=$version" >> "$GITHUB_OUTPUT"
build:
needs: plan
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.plan.outputs.matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: |
~/.platformio
~/.cache/pip
key: ${{ runner.os }}-platformio-${{ hashFiles('platformio.ini') }}
restore-keys: |
${{ runner.os }}-platformio-
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install platformio
- name: Build firmware - ${{ matrix.name }}
env:
BMCU_DM_TWO_MICROSWITCH: '1'
BMCU_ONLINE_LED_FILAMENT_RGB: '1'
DBMCU_P1S: ${{ matrix.p1s }}
BMCU_SOFT_LOAD: ${{ matrix.soft_load }}
BAMBU_BUS_AMS_NUM: '0'
AMS_RETRACT_LEN: '0.095f'
run: |
pio run -e fw
mkdir -p build/${{ matrix.artifact_prefix }}
cp .pio/build/fw/firmware.bin build/${{ matrix.artifact_prefix }}/firmware.bin
- name: Upload firmware artifacts
uses: actions/upload-artifact@v4
with:
name: firmware-${{ matrix.artifact_prefix }}
path: build/${{ matrix.artifact_prefix }}/firmware.bin
retention-days: 30
package:
name: Package Firmware Artifacts
runs-on: ubuntu-latest
needs: [plan, build]
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: firmware-artifacts
- name: Create release summary
env:
VERSION: ${{ needs.plan.outputs.version }}
BUILD_TYPE: ${{ inputs.build_type }}
run: |
cat > FIRMWARE_SUMMARY.md << EOF
# Build summary
## Build Information
- **Version**: ${VERSION}
- **Requested build type**: ${BUILD_TYPE}
- **Build Run**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- **Commit**: ${{ github.sha }}
- **Branch**: ${{ github.ref_name }}
EOF
cat FIRMWARE_SUMMARY.md
- name: Upload firmware summary
uses: actions/upload-artifact@v4
with:
name: build-summary
path: FIRMWARE_SUMMARY.md
retention-days: 30
- name: List downloaded artifacts
run: find firmware-artifacts -type f
- name: Publish GitHub Release
if: ${{ inputs.publish_release == true }}
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.plan.outputs.version }}
name: ${{ needs.plan.outputs.version }}${{ inputs.prerelease == true && ' (beta)' || '' }}
prerelease: ${{ inputs.prerelease }}
body_path: FIRMWARE_SUMMARY.md
files: |
firmware-artifacts/**/firmware.bin
notify:
name: Build Status Notification
runs-on: ubuntu-latest
needs: [build, package]
if: always()
steps:
- name: Check build status
run: |
if [[ "${{ needs.build.result }}" == "success" && "${{ needs.package.result }}" == "success" ]]; then
echo "✅ Firmware build completed successfully!"
else
echo "❌ Build failed"
exit 1
fi