hass.tibber_prices/scripts/prepare-release
Julian Pawlowski f60b5990ae test: add pytest framework and midnight-crossing tests
Set up pytest with Home Assistant support and created 6 tests for
midnight-crossing period logic (5 unit tests + 1 integration test).

Added pytest configuration, test dependencies, test runner script
(./scripts/test), and comprehensive tests for group_periods_by_day()
and midnight turnover consistency.

All tests pass in 0.12s.

Impact: Provides regression testing for midnight-crossing period bugs.
Tests validate periods remain visible across midnight turnover.
2025-11-21 23:47:01 +00:00

161 lines
5 KiB
Bash
Executable file

#!/bin/sh
# script/prepare-release: Prepare a new release by bumping version and creating tag
#
# This script:
# 1. Validates the version format (X.Y.Z)
# 2. Updates custom_components/tibber_prices/manifest.json
# 3. Commits the change with conventional commit format
# 4. Creates an annotated git tag
# 5. Shows you what will be pushed (you decide when to push)
#
# Usage:
# ./scripts/prepare-release [VERSION]
# ./scripts/prepare-release --suggest
# ./scripts/prepare-release 0.3.0
# ./scripts/prepare-release 1.0.0
set -eu
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m' # No Color
cd "$(dirname "$0")/.."
# Check if --suggest or no argument
if [ "${1:-}" = "--suggest" ] || [ -z "${1:-}" ]; then
./scripts/suggest-version
if [ -z "${1:-}" ]; then
echo ""
printf "${YELLOW}Provide version number as argument:${NC}\n"
echo " ./scripts/prepare-release X.Y.Z"
exit 0
fi
exit 0
fi
# Check if we have uncommitted changes
if ! git diff-index --quiet HEAD --; then
printf "${RED}❌ Error: You have uncommitted changes.${NC}\n"
echo "Please commit or stash them first."
exit 1
fi
# Parse version argument
VERSION="${1:-}"
if [ -z "$VERSION" ]; then
printf "${RED}❌ Error: No version specified.${NC}\n"
echo ""
echo "Usage: $0 VERSION"
echo ""
echo "Examples:"
echo " $0 0.3.0 # Bump to version 0.3.0"
echo " $0 1.0.0 # Bump to version 1.0.0"
exit 1
fi
# Strip 'v' prefix if present
VERSION="${VERSION#v}"
# Validate version format (X.Y.Z)
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
printf "${RED}❌ Error: Invalid version format: $VERSION${NC}\n"
echo "Expected format: X.Y.Z (e.g., 0.3.0, 1.0.0)"
exit 1
fi
TAG="v$VERSION"
MANIFEST="custom_components/tibber_prices/manifest.json"
# Check if manifest.json exists
if [ ! -f "$MANIFEST" ]; then
printf "${RED}❌ Error: Manifest file not found: $MANIFEST${NC}\n"
exit 1
fi
# Check if tag already exists (locally or remotely)
if git rev-parse "$TAG" >/dev/null 2>&1; then
printf "${RED}❌ Error: Tag $TAG already exists locally!${NC}\n"
echo "To remove it: git tag -d $TAG"
exit 1
fi
if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
printf "${RED}❌ Error: Tag $TAG already exists on remote!${NC}\n"
exit 1
fi
# Get current version
CURRENT_VERSION=$(jq -r '.version' "$MANIFEST")
printf "${BLUE}Current version: ${CURRENT_VERSION}${NC}\n"
printf "${BLUE}New version: ${VERSION}${NC}\n"
echo ""
# Update manifest.json
printf "${YELLOW}📝 Updating $MANIFEST...${NC}\n"
if ! command -v jq >/dev/null 2>&1; then
printf "${RED}❌ Error: jq is not installed${NC}\n"
echo "Please install jq: apt-get install jq (or brew install jq)"
exit 1
fi
# Create backup
cp "$MANIFEST" "$MANIFEST.backup"
# Update version with jq
if ! jq ".version = \"$VERSION\"" "$MANIFEST" > "$MANIFEST.tmp"; then
printf "${RED}❌ Error: Failed to update manifest.json${NC}\n"
mv "$MANIFEST.backup" "$MANIFEST"
exit 1
fi
mv "$MANIFEST.tmp" "$MANIFEST"
rm "$MANIFEST.backup"
printf "${GREEN}✓ Updated manifest.json${NC}\n"
# Stage and commit
printf "${YELLOW}📦 Creating commit...${NC}\n"
git add "$MANIFEST"
git commit -m "chore(release): bump version to $VERSION"
printf "${GREEN}✓ Created commit${NC}\n"
# Create annotated tag
printf "${YELLOW}🏷️ Creating tag $TAG...${NC}\n"
git tag -a "$TAG" -m "chore(release): version $VERSION"
printf "${GREEN}✓ Created tag $TAG${NC}\n"
# Show preview
echo ""
printf "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"
printf "${GREEN}✅ Release $VERSION prepared successfully!${NC}\n"
printf "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"
echo ""
printf "${BLUE}Review the changes:${NC}\n"
git log -1 --stat
echo ""
printf "${BLUE}Review the tag:${NC}\n"
git show "$TAG" --no-patch
echo ""
printf "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"
printf "${YELLOW}Next steps:${NC}\n"
echo ""
printf " ${GREEN}✓ To push and trigger release:${NC}\n"
printf " git push origin main $TAG\n"
echo ""
printf " ${RED}✗ To abort and undo:${NC}\n"
printf " git reset --hard HEAD~1 # Undo commit\n"
printf " git tag -d $TAG # Delete tag\n"
echo ""
printf "${BLUE}What happens after push:${NC}\n"
echo " 1. Both commit and tag are pushed to GitHub"
echo " 2. CI/CD detects the new tag"
echo " 3. Release notes are generated automatically"
echo " 4. GitHub release is created"
printf "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"