diff --git a/.gitea/workflows/foxmesh-ci.yml b/.gitea/workflows/foxmesh-ci.yml index 6b8a757..d2afc8d 100644 --- a/.gitea/workflows/foxmesh-ci.yml +++ b/.gitea/workflows/foxmesh-ci.yml @@ -1,4 +1,4 @@ -name: Automated CI Build of FoxMesh +name: Build of FoxMesh on: push: @@ -19,113 +19,121 @@ jobs: contents: write # We want also create official Releases steps: - - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" - - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - # 1. Checkout the target branch - - name: Checkout Target branch - uses: actions/checkout@v7 - with: - ref: ${{ github.event.inputs.target_branch || github.ref }} + - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" + - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - # 2. Extract Git and Date Metadata for the dynamic artifact filename - - name: Generate Dynamic Artifact Metadata - id: meta - run: | - # Get current date in YYYYMMDD format - echo "CURRENT_DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV + # 1. Checkout the target branch + - name: Checkout Target branch + uses: actions/checkout@v7 + with: + ref: ${{ github.event.inputs.target_branch || github.ref }} - # Get short 7-character git commit hash - echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + # 2. Extract Git and Date Metadata for the dynamic artifact filename + - name: Generate Dynamic Artifact Metadata + id: meta + run: | + # Get current date in YYYYMMDD format + echo "CURRENT_DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV - # Extract and sanitize branch name (replace slashes and special characters with dashes) - RAW_BRANCH=${{ github.event.inputs.target_branch || github.ref_name }} - CLEAN_BRANCH=$(echo "$RAW_BRANCH" | sed 's/[^a-zA-Z0-9.\-]/_§/g' | sed 's|§|-|g' | sed 's|_||g') - echo "GIT_BRANCH=$CLEAN_BRANCH" >> $GITHUB_ENV + # Get short 7-character git commit hash + echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - # 3. Set up Python environment - - name: Set up Python 3.x - uses: actions/setup-python@v7 - with: - python-version: '3.x' + # Extract and sanitize branch name (replace slashes and special characters with dashes) + RAW_BRANCH=${{ github.event.inputs.target_branch || github.ref_name }} + CLEAN_BRANCH=$(echo "$RAW_BRANCH" | sed 's/[^a-zA-Z0-9.\-]/_§/g' | sed 's|§|-|g' | sed 's|_||g') + echo "GIT_BRANCH=$CLEAN_BRANCH" >> $GITHUB_ENV - # 4. Cache global PlatformIO directories, uses a dynamic key based on platformio.ini - - name: Cache PlatformIO - uses: actions/cache@v6 - with: - path: | - ~/.cache/pio - ~/.platformio - .pio - key: ${{ runner.os }}-pio-${{ hashFiles('**/platformio.ini') }} - restore-keys: | - ${{ runner.os }}-pio- + #3 Python alread installed + - name: Show Python Version + run: python --version - # 5. Install PlatformIO Core and the required intelhex extension in a single, quiet command - - name: Install PlatformIO Core - run: python -m pip install --quiet --upgrade pip platformio intelhex + # 4. Cache global PlatformIO directories, uses a dynamic key based on platformio.ini + - name: Cache PlatformIO + uses: actions/cache@v6 + with: + path: | + .platformio + .pio + key: ${{ runner.os }}-pio-${{ hashFiles('**/platformio.ini') }} + restore-keys: | + ${{ runner.os }}-pio- - # 6. Install ESP32 Platform SDK - - name: Install ESP32 platform - run: pio pkg install --silent --global --platform espressif32 + - name: PlatformIO in venv installieren + run: | + python3 -m venv .venv + source .venv/bin/activate + python3 -m pip install --quiet --upgrade pip platformio intelhex + # Ab hier steht platformio in diesem Schritt zur Verfügung + pio --version + # Fügt den Pfad absolut dem GitHub/Gitea-Pfad hinzu: + echo "$PWD/.venv/bin" >> $GITHUB_PATH - # 7. Compile the Project - - name: Compile the Project - run: pio run + # 5. Install PlatformIO Core and the required intelhex extension in a single, quiet command +# - name: Install PlatformIO Core +# run: python -m pip install --quiet --upgrade pip platformio intelhex - # 8. Dynamically create the smart flashing scripts next to the T-Beam binary - # with optional bootloader detection and group check - # the table of flash addresses usually found at /partitions-4MB-safeboot.csv - - name: Create Desktop Flashing Scripts - run: | - # ---------------------------------------------------------------------- - # 0. Flash Address Configuration ← edit here to change the layout - # ---------------------------------------------------------------------- - FLASH_BOOTLOADER_ADDR="0x1000" - FLASH_PARTITIONS_ADDR="0x8000" - FLASH_OTADATA_ADDR="0xE000" - FLASH_SAFEBOOT_ADDR="0x10000" - FLASH_FIRMWARE_ADDR="0x10000" + # 6. Install ESP32 Platform SDK +# - name: Install ESP32 platform +# run: pio pkg install --silent --global --platform espressif32 - # ---------------------------------------------------------------------- - # 1. Universal Linux Shell Script - # ---------------------------------------------------------------------- - cat << 'EOF' > flash_esp32_board.sh - #!/usr/bin/env bash - GREEN='\033[0;32m' - RED='\033[0;31m' - YELLOW='\033[1;33m' - NC='\033[0m' + # 7. Compile the Project + - name: Compile the Project + run: pio run - echo -e "${YELLOW}=== FoxMesh Universal ESP32 Flashing Script ===${NC}" + # 8. Dynamically create the smart flashing scripts next to the T-Beam binary + # with optional bootloader detection and group check + # the table of flash addresses usually found at /partitions-4MB-safeboot.csv + - name: Create Desktop Flashing Scripts + run: | + # ---------------------------------------------------------------------- + # 0. Flash Address Configuration ← edit here to change the layout + # ---------------------------------------------------------------------- + FLASH_BOOTLOADER_ADDR="0x1000" + FLASH_PARTITIONS_ADDR="0x8000" + FLASH_OTADATA_ADDR="0xE000" + FLASH_SAFEBOOT_ADDR="0x10000" + FLASH_FIRMWARE_ADDR="0x10000" - if ! command -v esptool &> /dev/null; then + # ---------------------------------------------------------------------- + # 1. Universal Linux Shell Script + # ---------------------------------------------------------------------- + cat << 'EOF' > flash_esp32_board.sh + #!/usr/bin/env bash + GREEN='\033[0;32m' + RED='\033[0;31m' + YELLOW='\033[1;33m' + NC='\033[0m' + + echo -e "${YELLOW}=== FoxMesh Universal ESP32 Flashing Script ===${NC}" + + if ! command -v esptool &> /dev/null; then echo -e "${RED}Error: esptool is not installed.${NC}" echo "Please install it via your package manager or pip: 'pip install esptool'" echo "Option Linux Arch: 'sudo pacman -Sy && sudo pacman -S extra-testing/esptool'" exit 1 - fi + fi - FIRMWARE="firmware.bin" + FIRMWARE="firmware.bin" - # Firmware File - if [ ! -f "$FIRMWARE" ]; then + # Firmware File + if [ ! -f "$FIRMWARE" ]; then echo -e "${RED}Error: No matching firmware binary found in this folder!${NC}" exit 1 - fi + fi - echo -e "${GREEN}Selected Firmware:${NC} $FIRMWARE ($BOARD_NAME)" - PORT=$(ls /dev/ttyUSB* /dev/ttyACM* 2>/dev/null | head -n 1) - if [ -z "$PORT" ]; then + echo -e "${GREEN}Selected Firmware:${NC} $FIRMWARE ($BOARD_NAME)" + PORT=$(ls /dev/ttyUSB* /dev/ttyACM* 2>/dev/null | head -n 1) + if [ -z "$PORT" ]; then echo -e "${RED}Error: No connected ESP32 Board (ttyUSB/ttyACM) found!${NC}" exit 1 - fi - echo -e "${GREEN}Detected Board on port:${NC} $PORT" + fi + echo -e "${GREEN}Detected Board on port:${NC} $PORT" - # Dynamic Permission Check: Determine required group for the specific TTY device - REQUIRED_GROUP=$(stat -c '%G' "$PORT") - if [ "$REQUIRED_GROUP" != "root" ]; then + # Dynamic Permission Check: Determine required group for the specific TTY device + REQUIRED_GROUP=$(stat -c '%G' "$PORT") + if [ "$REQUIRED_GROUP" != "root" ]; then if ! groups "$USER" | grep -q "\b${REQUIRED_GROUP}\b"; then echo -e "${RED}Error: You do not have permissions to access $PORT.${NC}" echo -e "The device belongs to the group: ${YELLOW}$REQUIRED_GROUP${NC}" @@ -134,107 +142,107 @@ jobs: echo -e "After running the command, please log out and log back in for the changes to take effect." exit 1 fi - fi + fi - # Build flash arguments from the address table (only include files that exist) - FLASH_ARGS="" - if [ -f "bootloader.bin" ]; then - FLASH_ARGS="$FLASH_ARGS __BOOTLOADER_ADDR__ bootloader.bin" - fi - if [ -f "partitions.bin" ]; then - FLASH_ARGS="$FLASH_ARGS __PARTITIONS_ADDR__ partitions.bin" - fi - if [ -f "otadata.bin" ]; then - FLASH_ARGS="$FLASH_ARGS __OTADATA_ADDR__ otadata.bin" - fi - if [ -f "safeboot.bin" ]; then - FLASH_ARGS="$FLASH_ARGS __SAFEBOOT_ADDR__ safeboot.bin" - fi - FLASH_ARGS="$FLASH_ARGS __FIRMWARE_ADDR__ $FIRMWARE" + # Build flash arguments from the address table (only include files that exist) + FLASH_ARGS="" + if [ -f "bootloader.bin" ]; then + FLASH_ARGS="$FLASH_ARGS __BOOTLOADER_ADDR__ bootloader.bin" + fi + if [ -f "partitions.bin" ]; then + FLASH_ARGS="$FLASH_ARGS __PARTITIONS_ADDR__ partitions.bin" + fi + if [ -f "otadata.bin" ]; then + FLASH_ARGS="$FLASH_ARGS __OTADATA_ADDR__ otadata.bin" + fi + if [ -f "safeboot.bin" ]; then + FLASH_ARGS="$FLASH_ARGS __SAFEBOOT_ADDR__ safeboot.bin" + fi + FLASH_ARGS="$FLASH_ARGS __FIRMWARE_ADDR__ $FIRMWARE" - echo -e "${GREEN}Flashing:${NC}$FLASH_ARGS" - esptool --chip esp32 --port "$PORT" --baud 921600 write-flash -z $FLASH_ARGS + echo -e "${GREEN}Flashing:${NC}$FLASH_ARGS" + esptool --chip esp32 --port "$PORT" --baud 921600 write-flash -z $FLASH_ARGS - if [ $? -eq 0 ]; then + if [ $? -eq 0 ]; then echo -e "${GREEN}=== Success! $BOARD_NAME successfully updated ===${NC}" - else + else echo -e "${RED}=== Flash failed! ===${NC}" exit 1 - fi - EOF + fi + EOF - # Substitute address placeholders with configured hex values - sed -i \ + # Substitute address placeholders with configured hex values + sed -i \ -e "s|__BOOTLOADER_ADDR__|${FLASH_BOOTLOADER_ADDR}|g" \ -e "s|__PARTITIONS_ADDR__|${FLASH_PARTITIONS_ADDR}|g" \ -e "s|__OTADATA_ADDR__|${FLASH_OTADATA_ADDR}|g" \ -e "s|__SAFEBOOT_ADDR__|${FLASH_SAFEBOOT_ADDR}|g" \ -e "s|__FIRMWARE_ADDR__|${FLASH_FIRMWARE_ADDR}|g" \ flash_esp32_board.sh - chmod +x flash_esp32_board.sh + chmod +x flash_esp32_board.sh - # ---------------------------------------------------- - # 2. Universal Windows Batch Script - # ---------------------------------------------------- - cat << 'EOF' > flash_esp32_board.bat - @echo off - setlocal enabledelayedexpansion - echo =================================================== - echo === FoxMesh Universal ESP32 Windows Flashing ====== - echo =================================================== + # ---------------------------------------------------- + # 2. Universal Windows Batch Script + # ---------------------------------------------------- + cat << 'EOF' > flash_esp32_board.bat + @echo off + setlocal enabledelayedexpansion + echo =================================================== + echo === FoxMesh Universal ESP32 Windows Flashing ====== + echo =================================================== - set "FIRMWARE=firmware.bin" + set "FIRMWARE=firmware.bin" - if not exist "!FIRMWARE!" ( + if not exist "!FIRMWARE!" ( echo [ERROR] No matching firmware binary found in this folder! pause exit /b 1 - ) + ) - echo [INFO] Selected Firmware: %FIRMWARE% (%BOARD_NAME%) + echo [INFO] Selected Firmware: %FIRMWARE% (%BOARD_NAME%) - set "COMPORT=" - for /f "tokens=2 delims=()" %%A in ('wmic path Win32_PnPEntity get Name ^| findstr /i "COM" ^| findstr /i "Silicon CP210 CH340 CH9102 USB-to-UART"') do set "COMPORT=%%A" - if "%COMPORT%"=="" ( - for /f "tokens=2 delims=()" %%A in ('wmic path Win32_PnPEntity get Name ^| findstr /i "(COM"') do set "COMPORT=%%A" - ) - if "%COMPORT%"=="" ( - echo [ERROR] No ESP32 Board or USB-UART bridge detected! + set "COMPORT=" + for /f "tokens=2 delims=()" %%A in ('wmic path Win32_PnPEntity get Name ^| findstr /i "COM" ^| findstr /i "Silicon CP210 CH340 CH9102 USB-to-UART"') do set "COMPORT=%%A" + if "%COMPORT%"=="" ( + for /f "tokens=2 delims=()" %%A in ('wmic path Win32_PnPEntity get Name ^| findstr /i "(COM"') do set "COMPORT=%%A" + ) + if "%COMPORT%"=="" ( + echo [ERROR] No ESP32 Board or USB-UART bridge detected! + pause + exit /b 1 + ) + echo [INFO] Detected Board on port: %COMPORT% + + set "FLASH_ARGS=" + if exist "bootloader.bin" ( + set "FLASH_ARGS=!FLASH_ARGS! __BOOTLOADER_ADDR__ bootloader.bin" + ) + if exist "partitions.bin" ( + set "FLASH_ARGS=!FLASH_ARGS! __PARTITIONS_ADDR__ partitions.bin" + ) + if exist "otadata.bin" ( + set "FLASH_ARGS=!FLASH_ARGS! __OTADATA_ADDR__ otadata.bin" + ) + if exist "safeboot.bin" ( + set "FLASH_ARGS=!FLASH_ARGS! __SAFEBOOT_ADDR__ safeboot.bin" + ) + set "FLASH_ARGS=!FLASH_ARGS! __FIRMWARE_ADDR__ %FIRMWARE%" + + echo [INFO] Flashing: !FLASH_ARGS! + esptool --chip esp32 --port %COMPORT% --baud 921600 write-flash -z !FLASH_ARGS! + + if %ERRORLEVEL% EQU 0 ( + echo === SUCCESS! Flash operation successfully completed === + ) else ( + echo [ERROR] Flash failed! + pause + exit /b 1 + ) pause - exit /b 1 - ) - echo [INFO] Detected Board on port: %COMPORT% + EOF - set "FLASH_ARGS=" - if exist "bootloader.bin" ( - set "FLASH_ARGS=!FLASH_ARGS! __BOOTLOADER_ADDR__ bootloader.bin" - ) - if exist "partitions.bin" ( - set "FLASH_ARGS=!FLASH_ARGS! __PARTITIONS_ADDR__ partitions.bin" - ) - if exist "otadata.bin" ( - set "FLASH_ARGS=!FLASH_ARGS! __OTADATA_ADDR__ otadata.bin" - ) - if exist "safeboot.bin" ( - set "FLASH_ARGS=!FLASH_ARGS! __SAFEBOOT_ADDR__ safeboot.bin" - ) - set "FLASH_ARGS=!FLASH_ARGS! __FIRMWARE_ADDR__ %FIRMWARE%" - - echo [INFO] Flashing: !FLASH_ARGS! - esptool --chip esp32 --port %COMPORT% --baud 921600 write-flash -z !FLASH_ARGS! - - if %ERRORLEVEL% EQU 0 ( - echo === SUCCESS! Flash operation successfully completed === - ) else ( - echo [ERROR] Flash failed! - pause - exit /b 1 - ) - pause - EOF - - # Substitute address placeholders with configured hex values - sed -i \ + # Substitute address placeholders with configured hex values + sed -i \ -e "s|__BOOTLOADER_ADDR__|${FLASH_BOOTLOADER_ADDR}|g" \ -e "s|__PARTITIONS_ADDR__|${FLASH_PARTITIONS_ADDR}|g" \ -e "s|__OTADATA_ADDR__|${FLASH_OTADATA_ADDR}|g" \ @@ -242,27 +250,27 @@ jobs: -e "s|__FIRMWARE_ADDR__|${FLASH_FIRMWARE_ADDR}|g" \ flash_esp32_board.bat - # ----------------------------------------------------------------------------- - # 3. Gather binaries and scripts into target directory for structural packaging - # ----------------------------------------------------------------------------- - mkdir -p deploy_package - BUILD_OUTPUT=".pio/build/ttgo-lora32-v21" + # ----------------------------------------------------------------------------- + # 3. Gather binaries and scripts into target directory for structural packaging + # ----------------------------------------------------------------------------- + mkdir -p deploy_package + BUILD_OUTPUT=".pio/build/ttgo-lora32-v21" - # Copy binaries only if they exist - [ -f "$BUILD_OUTPUT/firmware.bin" ] && cp "$BUILD_OUTPUT/firmware.bin" ./deploy_package/ - [ -f "$BUILD_OUTPUT/bootloader.bin" ] && cp "$BUILD_OUTPUT/bootloader.bin" ./deploy_package/ - [ -f "$BUILD_OUTPUT/partitions.bin" ] && cp "$BUILD_OUTPUT/partitions.bin" ./deploy_package/ - [ -f "$BUILD_OUTPUT/otadata.bin" ] && cp "$BUILD_OUTPUT/otadata.bin" ./deploy_package/ - [ -f "$BUILD_OUTPUT/safeboot.bin" ] && cp "$BUILD_OUTPUT/safeboot.bin" ./deploy_package/ + # Copy binaries only if they exist + [ -f "$BUILD_OUTPUT/firmware.bin" ] && cp "$BUILD_OUTPUT/firmware.bin" ./deploy_package/ + [ -f "$BUILD_OUTPUT/bootloader.bin" ] && cp "$BUILD_OUTPUT/bootloader.bin" ./deploy_package/ + [ -f "$BUILD_OUTPUT/partitions.bin" ] && cp "$BUILD_OUTPUT/partitions.bin" ./deploy_package/ + [ -f "$BUILD_OUTPUT/otadata.bin" ] && cp "$BUILD_OUTPUT/otadata.bin" ./deploy_package/ + [ -f "$BUILD_OUTPUT/safeboot.bin" ] && cp "$BUILD_OUTPUT/safeboot.bin" ./deploy_package/ - # Move flash scripts into the deployment directory - mv flash_esp32_board.sh ./deploy_package/ - mv flash_esp32_board.bat ./deploy_package/ + # Move flash scripts into the deployment directory + mv flash_esp32_board.sh ./deploy_package/ + mv flash_esp32_board.bat ./deploy_package/ - # 9. Dynamic Artifact Upload: FoxMesh-branch-date-hash.zip - - name: Upload Compiled Firmware Package - uses: actions/upload-artifact@v7 - with: - name: FoxMesh-${{ env.GIT_BRANCH }}-${{ env.CURRENT_DATE }}-${{ env.GIT_HASH }} - path: deploy_package/ + # 9. Dynamic Artifact Upload: FoxMesh-branch-date-hash.zip + - name: Upload Compiled Firmware Package + uses: actions/upload-artifact@v7 + with: + name: FoxMesh-${{ env.GIT_BRANCH }}-${{ env.CURRENT_DATE }}-${{ env.GIT_HASH }} + path: deploy_package/ retention-days: 10 # Artifacts will be automatically deleted after 10 days