Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 17 additions & 209 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,229 +1,37 @@
name: Build Pipeline
name: Build

on:
push:
branches: [ main, experimental/*, develop ]
paths:
- 'src/**'
- 'include/**'
- 'platformio.ini'
- 'lib/**'
- '.github/workflows/build.yml'
branches: [master]
pull_request:
branches: [ main, develop ]
paths:
- 'src/**'
- 'include/**'
- 'platformio.ini'
- 'lib/**'
branches: [master]
workflow_dispatch:

concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read

jobs:
analyze:
name: Code Analysis
platformio:
name: PlatformIO (${{ matrix.environment }})
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
statuses: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'

- name: Install cppcheck
run: |
sudo apt-get update
sudo apt-get install -y cppcheck clang-tools

- name: Run cppcheck static analysis
id: cppcheck
run: |
cppcheck --version
cppcheck \
--enable=all \
--suppress=missingIncludeSystem \
--suppress=unusedFunction \
--error-exitcode=1 \
--inline-suppr \
--output-file=cppcheck-report.txt \
src/ || true

# Parse report for GitHub annotations
if [ -f cppcheck-report.txt ]; then
cat cppcheck-report.txt
fi

- name: Upload cppcheck results
uses: actions/upload-artifact@v3
if: always()
with:
name: cppcheck-report
path: cppcheck-report.txt
retention-days: 30

- name: Check code formatting
id: format
run: |
# Install clang-format
sudo apt-get install -y clang-format

# Check formatting on source files
find src/ -name "*.h" -o -name "*.cpp" | while read file; do
clang-format --dry-run --Werror "$file" || echo "Format issue in $file"
done || true

- name: Security scanning with Trivy
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: 'src/'
format: 'sarif'
output: 'trivy-results.sarif'

- name: Upload Trivy results
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
category: 'trivy'

build-matrix:
name: Build (${{ matrix.env }})
runs-on: ubuntu-latest
needs: analyze
strategy:
fail-fast: false
matrix:
include:
- env: 'esp32-s3-4mb'
variant: 'production'
description: '4MB flash variant'
- env: 'esp32-s3-16mb'
variant: 'production'
description: '16MB flash variant'
- env: 'esp32-s3-16mb-debug'
variant: 'debug'
description: 'Debug build'

permissions:
contents: read
statuses: write
environment:
- esp32-s3-16mb
- esp32-s3-sph0645

steps:
- name: Checkout repository
- name: Checkout
uses: actions/checkout@v4

- name: Cache PlatformIO
uses: actions/cache@v3
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio-${{ matrix.env }}
restore-keys: |
${{ runner.os }}-platformio-

- name: Set up PlatformIO
uses: actions/setup-python@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
python-version: "3.11"

- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install platformio

- name: Build firmware (${{ matrix.description }})
id: build
run: |
mkdir -p build/${{ matrix.env }}

# Configure build environment
export BUILD_VARIANT="${{ matrix.variant }}"
export BUILD_ENV="${{ matrix.env }}"

# Run PlatformIO build
pio run -e "${{ matrix.env }}" -d .

# Copy artifacts
cp .pio/build/${{ matrix.env }}/firmware.elf build/${{ matrix.env }}/
cp .pio/build/${{ matrix.env }}/firmware.bin build/${{ matrix.env }}/

# Generate checksums
cd build/${{ matrix.env }}
sha256sum firmware.* > checksums.txt

echo "fw_path=build/${{ matrix.env }}/firmware.bin" >> $GITHUB_OUTPUT
echo "elf_path=build/${{ matrix.env }}/firmware.elf" >> $GITHUB_OUTPUT
echo "size=$(stat -f%z build/${{ matrix.env }}/firmware.bin 2>/dev/null || stat -c%s build/${{ matrix.env }}/firmware.bin)" >> $GITHUB_OUTPUT
run: python -m pip install --upgrade platformio

- name: Check firmware size
id: size_check
run: |
MAX_SIZE=4194304 # 4MB for standard variant
ACTUAL_SIZE=$(stat -f%z build/${{ matrix.env }}/firmware.bin 2>/dev/null || stat -c%s build/${{ matrix.env }}/firmware.bin)
PERCENT=$((ACTUAL_SIZE * 100 / MAX_SIZE))

echo "**Firmware Size Report**" >> $GITHUB_STEP_SUMMARY
echo "- Variant: ${{ matrix.env }}" >> $GITHUB_STEP_SUMMARY
echo "- Size: ${ACTUAL_SIZE} bytes (${PERCENT}%)" >> $GITHUB_STEP_SUMMARY
echo "- Max: ${MAX_SIZE} bytes" >> $GITHUB_STEP_SUMMARY

if [ $ACTUAL_SIZE -gt $MAX_SIZE ]; then
echo "::error::Firmware exceeds maximum size"
exit 1
fi

- name: Analyze binary size
id: bloat
run: |
# Extract symbols and size information
pio run -e "${{ matrix.env }}" -d . -t buildfs

# Analyze using readelf if available
if command -v readelf &> /dev/null; then
readelf -SW build/${{ matrix.env }}/firmware.elf | grep -E "PROGBITS|DATA" > size_analysis.txt || true
fi

- name: Upload build artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: firmware-${{ matrix.env }}-${{ github.run_id }}
path: build/${{ matrix.env }}/
retention-days: 30

- name: Create build summary
if: always()
run: |
echo "## Build Report: ${{ matrix.env }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
echo "**Variant**: ${{ matrix.variant }}" >> $GITHUB_STEP_SUMMARY
echo "**Artifact**: firmware.bin" >> $GITHUB_STEP_SUMMARY

build-success:
name: Build Status Check
runs-on: ubuntu-latest
needs: build-matrix
if: always()
steps:
- name: Check build status
run: |
if [ "${{ needs.build-matrix.result }}" != "success" ]; then
echo "::error::Build pipeline failed"
exit 1
fi
echo "All builds completed successfully"
- name: Build firmware
run: pio run -e "${{ matrix.environment }}"
Loading
Loading