hass.tibber_prices/scripts/setup/setup
Julian Pawlowski a90fef6f2d refactor(scripts): reorganize and standardize development scripts
Major restructuring of the scripts/ directory with consistent output
formatting, improved organization, and stricter error handling.

Breaking Changes:
- Updated development environment to Home Assistant 2025.7+
  - Removed Python 3.12 compatibility (HA 2025.7+ requires Python 3.13)
  - Updated all HA core requirements from 2025.7 requirement files
  - Added new dependencies: python-multipart, uv (for faster package management)
  - Updated GitHub Actions workflows to use Python 3.13

Changes:
- Created centralized output library (scripts/.lib/output.sh)
  - Unified color codes and Unicode symbols
  - Consistent formatting functions (log_header, log_success, log_error, etc.)
  - Support for embedded formatting codes (${BOLD}, ${GREEN}, etc.)

- Reorganized into logical subdirectories:
  - scripts/setup/ - Setup and maintenance scripts
    - bootstrap: Install/update dependencies (used in CI/CD)
    - setup: Full DevContainer setup (pyright, copilot, HACS)
    - reset: Reset config/ directory to fresh state (NEW)
    - sync-hacs: Sync HACS integrations
  - scripts/release/ - Release management scripts
    - prepare: Version bump and tagging
    - suggest-version: Semantic version suggestion
    - generate-notes: Release notes generation
    - check-if-released: Check release status
    - hassfest: Local integration validation

- Updated all scripts with:
  - set -euo pipefail for stricter error handling
  - Consistent SCRIPT_DIR pattern for reliable sourcing
  - Professional output with colors and emojis
  - Unified styling across all 17 scripts

- Removed redundant scripts:
  - scripts/update (was just wrapper around bootstrap)
  - scripts/json_schemas/ (moved to schemas/json/)

- Enhanced clean script:
  - Improved artifact cleanup
  - Better handling of accidental package installations
  - Hints for reset and deep clean options

- New reset script features:
  - Standard mode: Keep configuration.yaml
  - Full mode (--full): Reset configuration.yaml from git
  - Automatic re-setup after reset

- Updated documentation:
  - AGENTS.md: Updated script references and workflow guidance
  - docs/development/: Updated all references to new script structure

Impact: Development environment now requires Python 3.13 and Home Assistant
2025.7+. Developers get consistent, professional script output with better
error handling and logical organization. Single source of truth for styling
makes future updates trivial.
2025-11-26 13:11:52 +00:00

106 lines
3.8 KiB
Bash
Executable file

#!/bin/bash
# script/setup: Setup script used by DevContainers to prepare the project
#
# Installs optional development tools (pyright, GitHub Copilot CLI, git-cliff)
# and configures the environment. Called automatically by DevContainer postStartCommand.
#
# Usage:
# ./scripts/setup/setup
#
# Examples:
# ./scripts/setup/setup
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR/../.."
# shellcheck source=scripts/.lib/output.sh
source "$SCRIPT_DIR/../.lib/output.sh"
# Install optional pyright for type checking
if command -v npm >/dev/null 2>&1 && ! command -v pyright >/dev/null 2>&1; then
log_header "Installing pyright for type checking"
npm install -g pyright 2>/dev/null || {
log_warning "pyright installation failed (optional)"
log_info "You can install it manually: ${BOLD}npm install -g pyright${NC}"
}
fi
# Install optional release note backend: GitHub Copilot CLI (AI-powered)
if command -v npm >/dev/null 2>&1 && ! command -v copilot >/dev/null 2>&1; then
log_header "Installing GitHub Copilot CLI for AI-powered release notes"
npm install -g @github/copilot 2>/dev/null || {
log_warning "GitHub Copilot CLI installation failed (optional)"
log_info "You can install it manually: ${BOLD}npm install -g @github/copilot${NC}"
}
fi
# Install optional release note backend: git-cliff (template-based)
if command -v cargo >/dev/null 2>&1 && ! command -v git-cliff >/dev/null 2>&1; then
log_header "Installing git-cliff for template-based release notes"
cargo install git-cliff || {
log_warning "git-cliff installation failed (optional)"
}
fi
"$SCRIPT_DIR/bootstrap"
# Install HACS for testing with other custom components
echo ""
log_header "Installing HACS in dev environment"
log_info "This allows testing your integration alongside other HACS components"
# Ensure config directory is initialized by Home Assistant first
if [[ ! -f config/.HA_VERSION ]]; then
log_step "Initializing Home Assistant config directory"
hass --config "${PWD}/config" --script ensure_config >/dev/null 2>&1 || true
fi
# Create custom_components directory if it doesn't exist
mkdir -p config/custom_components
# Clean up existing HACS installation if present
if [[ -d config/custom_components/hacs ]]; then
log_step "Removing existing HACS installation"
rm -rf config/custom_components/hacs
fi
if [[ -L custom_components/hacs ]]; then
log_step "Removing existing HACS symlink"
rm -f custom_components/hacs
fi
# Download and extract HACS (stable release ZIP)
cd config/custom_components
log_step "Downloading HACS"
if wget -q https://github.com/hacs/integration/releases/latest/download/hacs.zip && \
unzip -q hacs.zip -d hacs && \
rm hacs.zip; then
cd ../..
# Install HACS Python dependencies
log_step "Installing HACS Python dependencies"
if uv pip install -q 'aiogithubapi>=22.10.1'; then
# Create symlink so HA finds HACS alongside tibber_prices
log_step "Creating symlink in custom_components/"
ln -sf "${PWD}/config/custom_components/hacs" custom_components/hacs
log_success "HACS installed successfully"
log_info "Location: ${BOLD}config/custom_components/hacs/${NC}"
log_info "Version: Stable release (no auto-updates)"
else
log_warning "Failed to install HACS Python dependencies"
log_info "You can install manually: ${BOLD}uv pip install 'aiogithubapi>=22.10.1'${NC}"
fi
else
log_warning "HACS installation failed"
log_info "You can install manually:"
log_step "${BOLD}cd config/custom_components${NC}"
log_step "${BOLD}wget https://github.com/hacs/integration/releases/latest/download/hacs.zip${NC}"
log_step "${BOLD}unzip hacs.zip -d hacs && rm hacs.zip${NC}"
cd ../..
fi
echo ""
log_success "Project setup complete"