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
139 changes: 130 additions & 9 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,56 @@ jobs:
run: |
pip install --upgrade platformio
pip install gcovr==7.2
sudo apt-get install build-essential
sudo apt-get install build-essential bc jq

- name: Run unit tests (native)
run: pio test -e native -f test_ota_simple -f test_wifi_simple -f test_utils_simple -f test_constants_simple

- name: Compile project
run: pio run
run: pio run -e ttgo-lora32-v1-release

- name: Check flash size limit
run: |
# Get build output and extract flash usage
pio run -e ttgo-lora32-v1-release 2>&1 | tee build_output.log

# Extract flash usage from build output
FLASH_USED=$(grep -oP 'Flash:.*used \K\d+' build_output.log | tail -n 1)

if [ -z "$FLASH_USED" ]; then
echo "⚠️ Warning: Could not extract flash usage from build output"
echo "Looking for alternative patterns..."
# Try alternative patterns
FLASH_USED=$(grep -oP 'used \K\d+' build_output.log | tail -n 1)
fi

if [ -z "$FLASH_USED" ]; then
echo "❌ ERROR: Could not determine flash usage from build output"
echo "Build output (last 20 lines):"
tail -n 20 build_output.log
exit 1
fi

echo "Flash used: $FLASH_USED bytes"

# Check if flash usage exceeds 1,300,000 bytes
if [ "$FLASH_USED" -gt 1300000 ]; then
echo "❌ ERROR: Flash usage ($FLASH_USED bytes) exceeds limit of 1,300,000 bytes"
echo "Flash usage: $FLASH_USED / 1,300,000 bytes ($(echo "scale=2; $FLASH_USED * 100 / 1300000" | bc)%)"
exit 1
else
echo "✅ Flash usage OK: $FLASH_USED / 1,300,000 bytes ($(echo "scale=2; $FLASH_USED * 100 / 1300000" | bc)%)"
fi

- name: Store map files as artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts-branch-${{ github.sha }}
path: |
.pio/build/ttgo-lora32-v1-release/firmware.map
.pio/build/ttgo-lora32-v1-release/firmware.elf
retention-days: 30
if: always()

- name: Generate Compilation DB
run: pio run -t compiledb
Expand Down Expand Up @@ -104,13 +147,56 @@ jobs:
run: |
pip install --upgrade platformio
pip install gcovr==7.2
sudo apt-get install build-essential
sudo apt-get install build-essential bc jq

- name: Run unit tests (native)
run: pio test -e native -f test_ota_simple -f test_wifi_simple -f test_utils_simple -f test_constants_simple

- name: Compile project
run: pio run
run: pio run -e ttgo-lora32-v1-release

- name: Check flash size limit
run: |
# Get build output and extract flash usage
pio run -e ttgo-lora32-v1-release 2>&1 | tee build_output.log

# Extract flash usage from build output
FLASH_USED=$(grep -oP 'Flash:.*used \K\d+' build_output.log | tail -n 1)

if [ -z "$FLASH_USED" ]; then
echo "⚠️ Warning: Could not extract flash usage from build output"
echo "Looking for alternative patterns..."
# Try alternative patterns
FLASH_USED=$(grep -oP 'used \K\d+' build_output.log | tail -n 1)
fi

if [ -z "$FLASH_USED" ]; then
echo "❌ ERROR: Could not determine flash usage from build output"
echo "Build output (last 20 lines):"
tail -n 20 build_output.log
exit 1
fi

echo "Flash used: $FLASH_USED bytes"

# Check if flash usage exceeds 1,300,000 bytes
if [ "$FLASH_USED" -gt 1300000 ]; then
echo "❌ ERROR: Flash usage ($FLASH_USED bytes) exceeds limit of 1,300,000 bytes"
echo "Flash usage: $FLASH_USED / 1,300,000 bytes ($(echo "scale=2; $FLASH_USED * 100 / 1300000" | bc)%)"
exit 1
else
echo "✅ Flash usage OK: $FLASH_USED / 1,300,000 bytes ($(echo "scale=2; $FLASH_USED * 100 / 1300000" | bc)%)"
fi

- name: Store map files as artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts-main-${{ github.sha }}
path: |
.pio/build/ttgo-lora32-v1-release/firmware.map
.pio/build/ttgo-lora32-v1-release/firmware.elf
retention-days: 30
if: always()

- name: Generate Compilation DB
run: pio run -t compiledb
Expand Down Expand Up @@ -195,20 +281,54 @@ jobs:
- name: Install dependencies
run: |
pip install --upgrade platformio
sudo apt-get install build-essential
sudo apt-get install build-essential bc jq

- name: Run unit tests (native)
run: pio test -e native -f test_ota_simple -f test_wifi_simple -f test_utils_simple -f test_constants_simple

- name: Compile with updated firmware version
run: pio run
run: pio run -e ttgo-lora32-v1-release

- name: Check flash size limit
run: |
# Get build output and extract flash usage
pio run -e ttgo-lora32-v1-release 2>&1 | tee build_output.log

# Extract flash usage from build output
FLASH_USED=$(grep -oP 'Flash:.*used \K\d+' build_output.log | tail -n 1)

if [ -z "$FLASH_USED" ]; then
echo "⚠️ Warning: Could not extract flash usage from build output"
echo "Looking for alternative patterns..."
# Try alternative patterns
FLASH_USED=$(grep -oP 'used \K\d+' build_output.log | tail -n 1)
fi

if [ -z "$FLASH_USED" ]; then
echo "❌ ERROR: Could not determine flash usage from build output"
echo "Build output (last 20 lines):"
tail -n 20 build_output.log
exit 1
fi

echo "Flash used: $FLASH_USED bytes"

# Check if flash usage exceeds 1,300,000 bytes
if [ "$FLASH_USED" -gt 1300000 ]; then
echo "❌ ERROR: Flash usage ($FLASH_USED bytes) exceeds limit of 1,300,000 bytes"
echo "Flash usage: $FLASH_USED / 1,300,000 bytes ($(echo "scale=2; $FLASH_USED * 100 / 1300000" | bc)%)"
exit 1
else
echo "✅ Flash usage OK: $FLASH_USED / 1,300,000 bytes ($(echo "scale=2; $FLASH_USED * 100 / 1300000" | bc)%)"
fi

- name: Create release artifacts
run: |
mkdir -p artifacts
cp .pio/build/ttgo-lora32-v1/firmware.bin artifacts/firmware-${{ steps.validate-tag.outputs.tag_name }}.bin
cp .pio/build/ttgo-lora32-v1/firmware.elf artifacts/firmware-${{ steps.validate-tag.outputs.tag_name }}.elf
cp .pio/build/ttgo-lora32-v1/partitions.bin artifacts/partitions-${{ steps.validate-tag.outputs.tag_name }}.bin
cp .pio/build/ttgo-lora32-v1-release/firmware.bin artifacts/firmware-${{ steps.validate-tag.outputs.tag_name }}.bin
cp .pio/build/ttgo-lora32-v1-release/firmware.elf artifacts/firmware-${{ steps.validate-tag.outputs.tag_name }}.elf
cp .pio/build/ttgo-lora32-v1-release/firmware.map artifacts/firmware-${{ steps.validate-tag.outputs.tag_name }}.map
cp .pio/build/ttgo-lora32-v1-release/partitions.bin artifacts/partitions-${{ steps.validate-tag.outputs.tag_name }}.bin

# Create a manifest file with build info
cat > artifacts/build-info-${{ steps.validate-tag.outputs.tag_name }}.json << EOF
Expand Down Expand Up @@ -248,6 +368,7 @@ jobs:
### Artifacts
- `firmware-${{ steps.validate-tag.outputs.tag_name }}.bin` - Binary firmware file
- `firmware-${{ steps.validate-tag.outputs.tag_name }}.elf` - ELF debug file
- `firmware-${{ steps.validate-tag.outputs.tag_name }}.map` - Memory map file (for debugging memory regressions)
- `partitions-${{ steps.validate-tag.outputs.tag_name }}.bin` - Partition table
- `build-info-${{ steps.validate-tag.outputs.tag_name }}.json` - Build metadata

Expand Down
168 changes: 168 additions & 0 deletions .github/workflows/size-baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Size Baseline Capture

on:
push:
branches:
- size-baseline

env:
PLATFORMIO_CACHE_DIR: ~/.platformio/.cache

jobs:
capture-size-baseline:
name: Capture Size Baseline Artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Cache PlatformIO
uses: actions/cache@v3
with:
path: |
~/.cache/pip
${{ env.PLATFORMIO_CACHE_DIR }}
key: ${{ runner.os }}-pio-${{ hashFiles('platformio.ini') }}
restore-keys: |
${{ runner.os }}-pio-

- name: Install dependencies
run: |
pip install --upgrade platformio
sudo apt-get install build-essential

- name: Build release and capture artifacts
run: |
# Clean build with verbose output - use release environment for size baseline
pio run -e ttgo-lora32-v1-release -v > ci-build-release.log 2>&1 || RELEASE_BUILD_FAILED=1

# Create baseline artifacts directory
mkdir -p ci-baseline-artifacts

# Copy build log first (always available)
cp ci-build-release.log ci-baseline-artifacts/

# Copy generated files if they exist
if [ -f ".pio/build/ttgo-lora32-v1-release/firmware.elf" ]; then
cp .pio/build/ttgo-lora32-v1-release/firmware.elf ci-baseline-artifacts/release-firmware.elf
else
echo "WARNING: release firmware.elf not found" >> ci-baseline-artifacts/build-warnings.txt
fi

if [ -f ".pio/build/ttgo-lora32-v1-release/firmware.map" ]; then
cp .pio/build/ttgo-lora32-v1-release/firmware.map ci-baseline-artifacts/release-firmware.map
else
echo "WARNING: release firmware.map not found" >> ci-baseline-artifacts/build-warnings.txt
fi

# Extract memory usage information
echo "Size Baseline - CI Build" > ci-baseline-artifacts/ci-memory-usage.txt
echo "========================" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "Build Environment: ubuntu-latest (GitHub Actions)" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "Build Date: $(date -u +%Y-%m-%dT%H:%M:%SZ)" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "Git Branch: ${{ github.ref_name }}" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "Git Commit: ${{ github.sha }}" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "" >> ci-baseline-artifacts/ci-memory-usage.txt

# Extract RAM and Flash usage from build log
echo "RELEASE BUILD (ttgo-lora32-v1-release):" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "========================================" >> ci-baseline-artifacts/ci-memory-usage.txt
if grep -q "RAM:\|Flash:" ci-build-release.log; then
grep -A 2 -B 2 "RAM:\|Flash:" ci-build-release.log >> ci-baseline-artifacts/ci-memory-usage.txt
else
echo "WARNING: No memory usage information found in release build log" >> ci-baseline-artifacts/ci-memory-usage.txt
fi

# Record release build status
if [ "$RELEASE_BUILD_FAILED" = "1" ]; then
echo "RELEASE BUILD STATUS: FAILED" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "Release build failed - artifacts may be incomplete" >> ci-baseline-artifacts/build-warnings.txt
else
echo "RELEASE BUILD STATUS: SUCCESS" >> ci-baseline-artifacts/ci-memory-usage.txt
fi

echo "" >> ci-baseline-artifacts/ci-memory-usage.txt

- name: Build debug and capture artifacts
run: |
# Build debug environment for comparison
pio run -e ttgo-lora32-v1-debug -v > ci-build-debug.log 2>&1 || DEBUG_BUILD_FAILED=1

# Copy debug build log
cp ci-build-debug.log ci-baseline-artifacts/

# Copy debug generated files if they exist
if [ -f ".pio/build/ttgo-lora32-v1-debug/firmware.elf" ]; then
cp .pio/build/ttgo-lora32-v1-debug/firmware.elf ci-baseline-artifacts/debug-firmware.elf
else
echo "WARNING: debug firmware.elf not found" >> ci-baseline-artifacts/build-warnings.txt
fi

if [ -f ".pio/build/ttgo-lora32-v1-debug/firmware.map" ]; then
cp .pio/build/ttgo-lora32-v1-debug/firmware.map ci-baseline-artifacts/debug-firmware.map
else
echo "WARNING: debug firmware.map not found" >> ci-baseline-artifacts/build-warnings.txt
fi

# Add debug build info to memory usage report
echo "DEBUG BUILD (ttgo-lora32-v1-debug):" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "====================================" >> ci-baseline-artifacts/ci-memory-usage.txt
if grep -q "RAM:\|Flash:" ci-build-debug.log; then
grep -A 2 -B 2 "RAM:\|Flash:" ci-build-debug.log >> ci-baseline-artifacts/ci-memory-usage.txt
else
echo "WARNING: No memory usage information found in debug build log" >> ci-baseline-artifacts/ci-memory-usage.txt
fi

# Record debug build status
if [ "$DEBUG_BUILD_FAILED" = "1" ]; then
echo "DEBUG BUILD STATUS: FAILED" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "Debug build failed - artifacts may be incomplete" >> ci-baseline-artifacts/build-warnings.txt
else
echo "DEBUG BUILD STATUS: SUCCESS" >> ci-baseline-artifacts/ci-memory-usage.txt
fi

echo "" >> ci-baseline-artifacts/ci-memory-usage.txt
echo "ARTIFACT FILES:" >> ci-baseline-artifacts/ci-memory-usage.txt
ls -la ci-baseline-artifacts/ >> ci-baseline-artifacts/ci-memory-usage.txt

- name: Upload CI baseline artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: ci-size-baseline-${{ github.sha }}
path: ci-baseline-artifacts/
retention-days: 90

- name: Display memory usage summary
run: |
echo "=== CI BUILD MEMORY USAGE SUMMARY ==="
echo ""
echo "--- RELEASE BUILD ---"
if [ -f "ci-build-release.log" ]; then
grep -A 10 -B 5 "RAM:\|Flash:" ci-build-release.log || echo "Memory usage information not found in release build log"
else
echo "Release build log not found"
fi
echo ""
echo "--- DEBUG BUILD ---"
if [ -f "ci-build-debug.log" ]; then
grep -A 10 -B 5 "RAM:\|Flash:" ci-build-debug.log || echo "Memory usage information not found in debug build log"
else
echo "Debug build log not found"
fi
echo ""
echo "=== ARTIFACT FILES ==="
ls -la ci-baseline-artifacts/
echo ""
echo "=== WARNINGS (if any) ==="
if [ -f "ci-baseline-artifacts/build-warnings.txt" ]; then
cat ci-baseline-artifacts/build-warnings.txt
else
echo "No warnings found"
fi
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ program:
uploadfs:
platformio -f -c vim run --target uploadfs

# Build the optimized release firmware
.PHONY: release
release:
platformio -f -c vim run -e ttgo-lora32-v1-release

# Build and immediately upload the release firmware
.PHONY: upload-release
upload-release: release
platformio -f -c vim run -e ttgo-lora32-v1-release --target upload

.PHONY: test
test:
platformio test -e native
Expand Down
Loading