mirror of
https://github.com/1technophile/OpenMQTTGateway.git
synced 2026-03-11 01:38:33 +01:00
* Refactor GitHub Actions workflows for build, documentation, and linting - Consolidated build logic into reusable workflows (`task-build.yml` and `task-docs.yml`) to reduce duplication across multiple workflows. - Introduced `environments.json` to centralize the list of PlatformIO build environments, improving maintainability and clarity. - Updated `build.yml` and `build_and_docs_to_dev.yml` to utilize the new reusable workflows and environment definitions. - Enhanced `release.yml` to streamline the release process and integrate documentation generation. - Created reusable linting workflow (`task-lint.yml`) to standardize code formatting checks across the repository. - Simplified manual documentation workflow by leveraging the new reusable documentation workflow. - Improved artifact management and retention policies across workflows. - Updated dependencies and versions in workflows to ensure compatibility and performance. CI/CD pipeline agnostic of Workflow Engine and integrated on github actions - Implemented ci.sh for orchestrating the complete build pipeline. - Created ci_00_config.sh for centralized configuration of build scripts. - Created ci_build_firmware.sh for building firmware for specified PlatformIO environments. - Created ci_prepare_artifacts.sh for preparing firmware artifacts for upload or deployment. - Created ci_set_version.sh for updating version tags in firmware configuration files. - Created ci_build.sh to orchestrate the complete build pipeline. - Created ci_qa.sh for code linting and formatting checks using clang-format. - Created ci_site.sh for building and deploying VuePress documentation with version management. - Implemented checks for required tools and dependencies in the new scripts. - Improved internal scripts for better error handling and logging. UPDATE the web installer manifest generation and update documentation structure - Enhanced ci_list-env.sh to list environments from a JSON file. - Replaced common_wu.py and gen_wu.py scripts with new npm scripts for site generation and previewing on docsgen/gen_wu.js - Replaced generate_board_docs.py with docsgen/generated_board_docs.js - Added new npm scripts for integration of site generation on build phase. - Created preview_site.js to serve locally generated site over HTTPS with improved error handling. - Added new CI environments for CI builds in environments.json. - Deleted lint.yml as part of workflow cleanup. - Enhanced task-build.yml to include linting as a job and added support for specifying PlatformIO version. - Improved task-docs.yml to handle versioning more effectively and added clean option. Enhance documentation - ADD CLEAR Mark of development version of site - Updated README.md to include detailed workflow dependencies and relationships using mermaid diagrams. - Improved development.md with a quick checklist for contributors and clarified the code style guide. - Enhanced quick_start.md with tips for contributors and streamlined the workflow explanation. LINT FIX - Refined User_config.h for better formatting consistency. - Adjusted blufi.cpp and gatewayBT.cpp for improved code readability and consistency in formatting. - Updated gatewaySERIAL.cpp and mqttDiscovery.cpp to enhance logging error messages. - Improved sensorDS1820.cpp for better logging of device information. Add security scan workflows for vulnerability detection Add SBOM generation and upload to release workflow; update security scan summary handling Add shellcheck suppor + FIX shellcheck warning Enhance documentation for CI/CD scripts and workflows, adding details for security scanning and SBOM generation processes Fix formatting and alignment in BLE connection handling Reviewed the full web board presentation and the ESP32 web upload. The project uses a modern pattern where data is divided from the presentation layer. - Removed the `generate_board_docs` script. - Updated the `gen_wu` script in order to generate `boards-info.json`: the fail that containe all information about the configuration - Created and isolate the file `boards-info.js` to streamline the parsing of PlatformIO dependencies, modules, environments and improve the handling of library information. - Introduced vuepress component `BoardEnvironmentTable.vue` that render `boards-info.json` as UI card component - Introduced vuepress component `FlashEnvironmentSelector.vue` that render a selectred environment from `boards-info.json` and provide esp-web-upload feature on it - Introduced a new board page `board-selector.md` for improved firmware selection. - Updated `web-install.md` to enhance the firmware upload process, including a new board environment table. - Enhanced custom descriptions in `environments.ini` to include HTML links for better user guidance and board image link Add CC1101 initialization improvements and logging enhancements Add installation step for PlatformIO dependencies in documentation workflow Remove ci_set_version.sh script and associated versioning functionality * Fix comment provisined Fix PlatformIO version input reference in documentation workflow Remove outdated Squeezelite-ESP32 installer documentation
295 lines
7.7 KiB
Bash
Executable File
295 lines
7.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Builds firmware for specified PlatformIO environment
|
|
# Used by: CI/CD pipelines and local development
|
|
# Usage: ./build_firmware.sh <environment> [OPTIONS]
|
|
|
|
set -euo pipefail
|
|
|
|
# Constants
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
readonly SCRIPT_DIR
|
|
readonly PROJECT_ROOT
|
|
|
|
# Load shared configuration (colors, logging functions, paths)
|
|
if [[ -f "${SCRIPT_DIR}/ci_00_config.sh" ]]; then
|
|
source "${SCRIPT_DIR}/ci_00_config.sh"
|
|
else
|
|
echo "ERROR: ci_00_config.sh not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Set absolute path for BUILD_DIR
|
|
BUILD_DIR="${PROJECT_ROOT}/${BUILD_DIR}"
|
|
|
|
# Script-specific logging function
|
|
log_build() { echo -e "${BLUE}[BUILD]${NC} $*"; }
|
|
|
|
# Function to validate environment name
|
|
validate_environment() {
|
|
local env="$1"
|
|
|
|
if [[ -z "$env" ]]; then
|
|
log_error "Environment name is required"
|
|
return 1
|
|
fi
|
|
|
|
# Check if environment exists in platformio.ini or environments.ini
|
|
if ! grep -q "^\[env:${env}\]" "${PROJECT_ROOT}/platformio.ini" "${PROJECT_ROOT}/environments.ini" 2>/dev/null; then
|
|
log_warn "Environment '${env}' not found in configuration files"
|
|
log_warn "Proceeding anyway (PlatformIO will validate)"
|
|
fi
|
|
|
|
log_info "Building environment: $env"
|
|
}
|
|
|
|
|
|
|
|
# Function to check PlatformIO availability
|
|
check_platformio() {
|
|
if ! command -v platformio >/dev/null 2>&1; then
|
|
log_error "PlatformIO not found. Run setup_build_env.sh first"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Function to clean build artifacts
|
|
clean_build() {
|
|
local env="$1"
|
|
local env_dir="${BUILD_DIR}/${env}"
|
|
|
|
if [[ -d "$env_dir" ]]; then
|
|
log_info "Cleaning previous build artifacts for: $env"
|
|
rm -rf "$env_dir"
|
|
fi
|
|
}
|
|
|
|
# Function to run PlatformIO build
|
|
run_build() {
|
|
local env="$1"
|
|
local clean="${2:-false}"
|
|
local verbose="${3:-false}"
|
|
local enable_dev_ota="${4:-false}"
|
|
local version="${5:-edge}"
|
|
|
|
if [[ "$enable_dev_ota" == "true" ]]; then
|
|
log_info "Development OTA enabled"
|
|
export PLATFORMIO_BUILD_FLAGS='"-DDEVELOPMENTOTA=true"'
|
|
fi
|
|
|
|
if [[ -n "$version" ]]; then
|
|
log_info "Setting firmware version to: $version"
|
|
export PLATFORMIO_BUILD_FLAGS="${PLATFORMIO_BUILD_FLAGS} -DOMG_VERSION=\\\"${version}\\\""
|
|
fi
|
|
|
|
log_build "Starting build for environment: $env"
|
|
|
|
local build_cmd="platformio run -e $env"
|
|
|
|
if [[ "$clean" == "true" ]]; then
|
|
build_cmd="platformio run -e $env --target clean && $build_cmd"
|
|
fi
|
|
|
|
if [[ "$verbose" == "true" ]]; then
|
|
build_cmd="$build_cmd --verbose"
|
|
fi
|
|
|
|
# Execute build with timing
|
|
local start_time
|
|
start_time=$(date +%s)
|
|
|
|
log_info "PlatformIO Build Flags: $PLATFORMIO_BUILD_FLAGS"
|
|
log_info "Executing: $build_cmd"
|
|
|
|
if eval "$build_cmd"; then
|
|
local end_time
|
|
end_time=$(date +%s)
|
|
local duration=$((end_time - start_time))
|
|
|
|
log_build "Build completed successfully in ${duration}s"
|
|
return 0
|
|
else
|
|
log_error "Build failed for environment: $env"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Function to verify build artifacts
|
|
verify_artifacts() {
|
|
local env="$1"
|
|
local env_dir="${BUILD_DIR}/${env}"
|
|
|
|
log_info "Verifying build artifacts..."
|
|
|
|
local artifacts_found=0
|
|
local firmware="${env_dir}/firmware.bin"
|
|
local partitions="${env_dir}/partitions.bin"
|
|
local bootloader="${env_dir}/bootloader.bin"
|
|
|
|
if [[ -f "$firmware" ]]; then
|
|
local size
|
|
size=$(stat -f%z "$firmware" 2>/dev/null || stat -c%s "$firmware" 2>/dev/null)
|
|
log_info "✓ firmware.bin (${size} bytes)"
|
|
((artifacts_found++))
|
|
else
|
|
log_warn "✗ firmware.bin not found"
|
|
fi
|
|
|
|
if [[ -f "$partitions" ]]; then
|
|
log_info "✓ partitions.bin"
|
|
((artifacts_found++))
|
|
fi
|
|
|
|
if [[ -f "$bootloader" ]]; then
|
|
log_info "✓ bootloader.bin"
|
|
((artifacts_found++))
|
|
fi
|
|
|
|
if [[ $artifacts_found -eq 0 ]]; then
|
|
log_error "No build artifacts found"
|
|
return 1
|
|
fi
|
|
|
|
log_info "Found ${artifacts_found} artifact(s)"
|
|
}
|
|
|
|
# Function to show build summary
|
|
show_build_summary() {
|
|
local env="$1"
|
|
local env_dir="${BUILD_DIR}/${env}"
|
|
|
|
echo ""
|
|
echo "═══════════════════════════════════════"
|
|
echo " Build Summary: $env"
|
|
echo "═══════════════════════════════════════"
|
|
|
|
if [[ -d "$env_dir" ]]; then
|
|
find "$env_dir" -name "*.bin" -o -name "*.elf" | while read -r file; do
|
|
local size
|
|
size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null)
|
|
local size_kb=$((size / 1024))
|
|
echo " $(basename "$file"): ${size_kb} KB"
|
|
done
|
|
fi
|
|
|
|
echo "═══════════════════════════════════════"
|
|
}
|
|
|
|
# Show usage
|
|
usage() {
|
|
cat << EOF
|
|
Usage: $0 <environment> [OPTIONS]
|
|
|
|
Build firmware for a specific PlatformIO environment.
|
|
|
|
Arguments:
|
|
environment PlatformIO environment name (e.g., esp32dev-all-test)
|
|
|
|
Options:
|
|
--dev-ota Enable development OTA build flags
|
|
--clean Clean build artifacts before building
|
|
--verbose Enable verbose build output
|
|
--no-verify Skip artifact verification
|
|
--version <ver> Set firmware version (default: edge)
|
|
--help Show this help message
|
|
|
|
Examples:
|
|
$0 esp32dev-all-test
|
|
$0 esp32dev-bt --dev-ota
|
|
$0 theengs-bridge --clean --verbose
|
|
|
|
EOF
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
local environment=""
|
|
local enable_dev_ota=false
|
|
local clean_build_flag=false
|
|
local verbose=false
|
|
local verify=true
|
|
local version="edge"
|
|
|
|
# Parse arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--version)
|
|
version="$2"
|
|
shift 2
|
|
;;
|
|
--dev-ota)
|
|
enable_dev_ota=true
|
|
shift
|
|
;;
|
|
--clean)
|
|
clean_build_flag=true
|
|
shift
|
|
;;
|
|
--verbose)
|
|
verbose=true
|
|
shift
|
|
;;
|
|
--no-verify)
|
|
verify=false
|
|
shift
|
|
;;
|
|
--help|-h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
-*)
|
|
log_error "Unknown option: $1"
|
|
usage
|
|
exit 1
|
|
;;
|
|
*)
|
|
environment="$1"
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Validate inputs
|
|
if [[ -z "$environment" ]]; then
|
|
log_error "Environment name is required"
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
# Change to project root
|
|
cd "$PROJECT_ROOT"
|
|
|
|
# Check prerequisites
|
|
check_platformio || exit 1
|
|
|
|
# Validate environment
|
|
validate_environment "$environment" || exit 1
|
|
|
|
# Setup build environment
|
|
export PYTHONIOENCODING=utf-8
|
|
export PYTHONUTF8=1
|
|
|
|
# Clean if requested
|
|
if [[ "$clean_build_flag" == "true" ]]; then
|
|
clean_build "$environment"
|
|
fi
|
|
|
|
# Run build
|
|
run_build "$environment" "$clean_build_flag" "$verbose" "$enable_dev_ota" "$version" || exit 1
|
|
|
|
# Verify artifacts
|
|
if [[ "$verify" == "true" ]]; then
|
|
verify_artifacts "$environment" || exit 1
|
|
fi
|
|
|
|
# Show summary
|
|
show_build_summary "$environment"
|
|
|
|
log_info "Build process completed successfully"
|
|
}
|
|
|
|
# Run main if executed directly
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
main "$@"
|
|
fi
|