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
143 changes: 58 additions & 85 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
jobs:
# Stage 1: Branch Development Pipeline
branch-pipeline:
name: Branch Pipeline (Unit Test + Compile + Coverage + SonarQube)
name: Branch Pipeline (Compile + SonarQube)
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main')
steps:
Expand All @@ -44,34 +44,30 @@ jobs:
- name: Install dependencies
run: |
pip install --upgrade platformio
pip install gcovr==7.2
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 -e ttgo-lora32-v1-release
- name: Compile project (release)
run: make release

- name: Compile project (minimal)
run: make minimal

- 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)
# Parse the ELF file that was already built to extract flash usage
ELF_FILE=".pio/build/ttgo-lora32-v1/firmware.elf"

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)
if [ ! -f "$ELF_FILE" ]; then
echo "❌ ERROR: ELF file not found at $ELF_FILE"
exit 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
# Extract flash usage from ELF file using size command
FLASH_USED=$(size "$ELF_FILE" | tail -n 1 | awk '{print $1 + $2}')

if [ -z "$FLASH_USED" ] || [ "$FLASH_USED" -eq 0 ]; then
echo "❌ ERROR: Could not determine flash usage from ELF file"
exit 1
fi

Expand All @@ -91,22 +87,16 @@ jobs:
with:
name: build-artifacts-branch-${{ github.sha }}
path: |
.pio/build/ttgo-lora32-v1-release/firmware.map
.pio/build/ttgo-lora32-v1-release/firmware.elf
.pio/build/ttgo-lora32-v1/firmware.map
.pio/build/ttgo-lora32-v1/firmware.elf
.pio/build/minimal/firmware.map
.pio/build/minimal/firmware.elf
retention-days: 30
if: always()

- name: Generate Compilation DB
run: pio run -t compiledb

- name: Generate coverage report
run: |
gcovr \
--root . \
--exclude '\.pio/libdeps/' \
--exclude 'tests/.*' \
--sonarqube \
--output coverage.xml

- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v5
Expand All @@ -115,11 +105,10 @@ jobs:
with:
args: >
--define sonar.cfamily.compile-commands="compile_commands.json"
--define sonar.coverageReportPaths="coverage.xml"

# Stage 2: Main Branch Pipeline
main-pipeline:
name: Main Pipeline (Unit Test + Compile + Coverage + SonarQube)
name: Main Pipeline (Compile + SonarQube)
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
Expand All @@ -146,34 +135,29 @@ jobs:
- name: Install dependencies
run: |
pip install --upgrade platformio
pip install gcovr==7.2
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 (release)
run: make release

- name: Compile project
run: pio run -e ttgo-lora32-v1-release
- name: Compile project (minimal)
run: make minimal

- 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)
# Parse the ELF file that was already built to extract flash usage
ELF_FILE=".pio/build/ttgo-lora32-v1/firmware.elf"

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)
if [ ! -f "$ELF_FILE" ]; then
echo "❌ ERROR: ELF file not found at $ELF_FILE"
exit 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
# Extract flash usage from ELF file using size command
FLASH_USED=$(size "$ELF_FILE" | tail -n 1 | awk '{print $1 + $2}')

if [ -z "$FLASH_USED" ] || [ "$FLASH_USED" -eq 0 ]; then
echo "❌ ERROR: Could not determine flash usage from ELF file"
exit 1
fi

Expand All @@ -193,31 +177,23 @@ jobs:
with:
name: build-artifacts-main-${{ github.sha }}
path: |
.pio/build/ttgo-lora32-v1-release/firmware.map
.pio/build/ttgo-lora32-v1-release/firmware.elf
.pio/build/ttgo-lora32-v1/firmware.map
.pio/build/ttgo-lora32-v1/firmware.elf
.pio/build/minimal/firmware.map
.pio/build/minimal/firmware.elf
retention-days: 30
if: always()

- name: Generate Compilation DB
run: pio run -t compiledb

- name: Generate coverage report
run: |
gcovr \
--root . \
--exclude '\.pio/libdeps/' \
--exclude 'tests/.*' \
--sonarqube \
--output coverage.xml

- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
--define sonar.cfamily.compile-commands="compile_commands.json"
--define sonar.coverageReportPaths="coverage.xml"

# Stage 3: Release Pipeline
release-pipeline:
Expand Down Expand Up @@ -283,31 +259,28 @@ jobs:
pip install --upgrade platformio
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 -e ttgo-lora32-v1-release
- name: Compile project (release)
run: make release

- name: Compile project (minimal)
run: make minimal

- 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
# Parse the ELF file that was already built to extract flash usage
ELF_FILE=".pio/build/ttgo-lora32-v1/firmware.elf"

# 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)
if [ ! -f "$ELF_FILE" ]; then
echo "❌ ERROR: ELF file not found at $ELF_FILE"
exit 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
# Extract flash usage from ELF file using size command
FLASH_USED=$(size "$ELF_FILE" | tail -n 1 | awk '{print $1 + $2}')

if [ -z "$FLASH_USED" ] || [ "$FLASH_USED" -eq 0 ]; then
echo "❌ ERROR: Could not determine flash usage from ELF file"
exit 1
fi

Expand All @@ -325,10 +298,10 @@ jobs:
- name: Create release artifacts
run: |
mkdir -p artifacts
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
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/firmware.map artifacts/firmware-${{ steps.validate-tag.outputs.tag_name }}.map
cp .pio/build/ttgo-lora32-v1/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
29 changes: 15 additions & 14 deletions .github/workflows/size-baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
PLATFORMIO_CACHE_DIR: ~/.platformio/.cache
PLATFORMIO_BUILD_FLAGS: -v

jobs:
capture-size-baseline:
Expand Down Expand Up @@ -38,8 +39,8 @@ jobs:

- 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
# Clean build with verbose output - use ttgo-lora32-v1 environment for size baseline
make release >&1 | tee ci-build-release.log 2>&1 || RELEASE_BUILD_FAILED=1

# Create baseline artifacts directory
mkdir -p ci-baseline-artifacts
Expand All @@ -48,14 +49,14 @@ jobs:
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
if [ -f ".pio/build/ttgo-lora32-v1/firmware.elf" ]; then
cp .pio/build/ttgo-lora32-v1/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
if [ -f ".pio/build/ttgo-lora32-v1/firmware.map" ]; then
cp .pio/build/ttgo-lora32-v1/firmware.map ci-baseline-artifacts/release-firmware.map
else
echo "WARNING: release firmware.map not found" >> ci-baseline-artifacts/build-warnings.txt
fi
Expand All @@ -71,7 +72,7 @@ jobs:
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 "TTGO-LORA32-V1 BUILD (ttgo-lora32-v1):" >> 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
Expand All @@ -91,27 +92,27 @@ jobs:

- 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
# Build minimal environment for comparison
make minimal >&1 | tee 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
if [ -f ".pio/build/minimal/firmware.elf" ]; then
cp .pio/build/minimal/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
if [ -f ".pio/build/minimal/firmware.map" ]; then
cp .pio/build/minimal/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 "MINIMAL BUILD (minimal):" >> 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
Expand Down
27 changes: 10 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CREATED BY VIM-PIO
all:
all: release
platformio -f -c vim run

upload:
Expand All @@ -15,22 +15,15 @@ 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

.PHONY: test-cli
test-cli:
cd cli && go test ./... -v
.PHONY: release minimal test
release: ## Build main release env
platformio run -e ttgo-lora32-v1
minimal:
platformio run -e minimal

# Test target that calls minimal build for CI readability
test: minimal ## Build minimal env (alias for CI)


.PHONY: build-cli
build-cli:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ This project uses a single optimized build configuration:

For detailed build information, see [docs/BUILD.md](docs/BUILD.md).

## Build Commands

- `make release`: Build the main release environment (ttgo-lora32-v1)
- `make minimal`: Build the minimal environment for comparison
- For verbose output, set environment variable: `PLATFORMIO_BUILD_FLAGS=-v`

Example: `PLATFORMIO_BUILD_FLAGS=-v make release`

# Node Provisioning

1. Build the firmware and upload it to the board.
Expand Down
Loading