hass.tibber_prices/scripts/setup/reset
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

109 lines
3.3 KiB
Bash
Executable file

#!/bin/bash
# script/reset: Reset development environment to fresh state
#
# Removes all HA-generated files in config/ directory (keeps configuration.yaml by default)
# and re-runs complete setup (dependencies, HACS, symlinks).
# Use --full to also reset configuration.yaml from git.
#
# Usage:
# ./scripts/setup/reset [--full]
#
# Examples:
# ./scripts/setup/reset # Keep configuration.yaml (your local settings)
# ./scripts/setup/reset --full # Also reset configuration.yaml from git
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR/../.."
# shellcheck source=scripts/.lib/output.sh
source "$SCRIPT_DIR/../.lib/output.sh"
FULL_RESET=false
if [[ ${1:-} == --full ]]; then
FULL_RESET=true
fi
log_header "Resetting development environment to fresh state"
# Check if config directory exists
if [[ ! -d config ]]; then
log_error "config/ directory does not exist"
exit 1
fi
# Confirm destructive action
echo ""
log_warning "This will DELETE files in config/ directory!"
if [[ $FULL_RESET == true ]]; then
log_step "Mode: ${BOLD}FULL RESET${NC} - All files including configuration.yaml"
log_step "Deleting: .storage/, custom_components/, logs, .HA_VERSION, configuration.yaml, etc."
log_step "Then restore: configuration.yaml from git"
else
log_step "Mode: ${BOLD}STANDARD RESET${NC} - Keep configuration.yaml"
log_step "Deleting: .storage/, custom_components/, logs, .HA_VERSION, etc."
log_step "Keeping: configuration.yaml (your local settings preserved)"
fi
log_step "Then re-run: Complete setup (bootstrap + HACS + symlinks)"
echo ""
read -p "Continue? [y/N] " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
log_info "Reset cancelled"
exit 0
fi
# Remove config directory contents
if [[ $FULL_RESET == true ]]; then
# Full reset: Remove everything
log_step "Removing all files in config/ directory"
rm -rf config/* config/.* 2>/dev/null || true
# Check if configuration.yaml exists in git
if git ls-files --error-unmatch config/configuration.yaml >/dev/null 2>&1; then
# Restore configuration.yaml from git
log_step "Restoring configuration.yaml from git repository"
git checkout HEAD -- config/configuration.yaml || {
log_error "Failed to restore configuration.yaml from git"
exit 1
}
else
log_warning "configuration.yaml is not tracked in git repository"
fi
else
# Standard reset: Keep configuration.yaml
log_step "Removing all files except configuration.yaml"
find config -mindepth 1 ! -name 'configuration.yaml' -delete 2>/dev/null || {
log_error "Failed to clean config/ directory"
exit 1
}
fi
log_success "Config directory cleaned"
# Re-run complete setup
echo ""
log_header "Running complete setup"
log_info "This will install dependencies, HACS, and create symlinks"
echo ""
"$SCRIPT_DIR/setup" || {
log_error "Setup failed"
exit 1
}
echo ""
log_success "Reset complete - development environment is now in fresh state"
echo ""
log_info "Next steps:"
log_step "Run ${BOLD}./scripts/develop${NC} to start Home Assistant"
log_step "Configure integrations via UI (including HACS if needed)"
if [[ $FULL_RESET == false ]]; then
echo ""
log_info "Tip: Use './scripts/setup/reset --full' to also reset configuration.yaml from git"
fi