#!/bin/bash # SneakyScan Release Script # Handles version bumping, branch merging, tagging, and pushing set -e CONFIG_FILE="app/web/config.py" DEVELOP_BRANCH="nightly" STAGING_BRANCH="beta" MAIN_BRANCH="master" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}=== SneakyScan Release Script ===${NC}\n" # Ensure we're in the repo root if [ ! -f "$CONFIG_FILE" ]; then echo -e "${RED}Error: Must run from repository root${NC}" exit 1 fi # Check for uncommitted changes if [ -n "$(git status --porcelain)" ]; then echo -e "${RED}Error: You have uncommitted changes. Please commit or stash them first.${NC}" exit 1 fi # Prompt for version read -p "Enter version (e.g., 1.0.0): " VERSION # Validate version format (semver) if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then echo -e "${RED}Error: Invalid version format. Use semver (e.g., 1.0.0 or 1.0.0-beta)${NC}" exit 1 fi TAG_NAME="v$VERSION" # Check if tag already exists if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then echo -e "${RED}Error: Tag $TAG_NAME already exists${NC}" exit 1 fi echo -e "\n${YELLOW}Release version: $VERSION${NC}" echo -e "${YELLOW}Tag name: $TAG_NAME${NC}\n" read -p "Proceed with release? (y/n): " CONFIRM if [ "$CONFIRM" != "y" ]; then echo "Release cancelled." exit 0 fi # Fetch latest from remote echo -e "\n${GREEN}Fetching latest from remote...${NC}" git fetch origin # Update version in config.py echo -e "\n${GREEN}Updating version in $CONFIG_FILE...${NC}" sed -i "s/APP_VERSION = .*/APP_VERSION = '$VERSION'/" "$CONFIG_FILE" # Checkout develop and commit version change echo -e "\n${GREEN}Committing version change on $DEVELOP_BRANCH...${NC}" git checkout "$DEVELOP_BRANCH" git add "$CONFIG_FILE" git commit -m "Bump version to $VERSION" # Merge develop into staging echo -e "\n${GREEN}Merging $DEVELOP_BRANCH into $STAGING_BRANCH...${NC}" git checkout "$STAGING_BRANCH" git merge "$DEVELOP_BRANCH" -m "Merge $DEVELOP_BRANCH into $STAGING_BRANCH for release $VERSION" # Merge staging into main echo -e "\n${GREEN}Merging $STAGING_BRANCH into $MAIN_BRANCH...${NC}" git checkout "$MAIN_BRANCH" git merge "$STAGING_BRANCH" -m "Merge $STAGING_BRANCH into $MAIN_BRANCH for release $VERSION" # Create tag echo -e "\n${GREEN}Creating tag $TAG_NAME...${NC}" git tag -a "$TAG_NAME" -m "Release $VERSION" # Push everything echo -e "\n${GREEN}Pushing branches and tag to remote...${NC}" git push origin "$DEVELOP_BRANCH" git push origin "$STAGING_BRANCH" git push origin "$MAIN_BRANCH" git push origin "$TAG_NAME" # Return to develop branch git checkout "$DEVELOP_BRANCH" echo -e "\n${GREEN}=== Release $VERSION complete! ===${NC}" echo -e "Tag: $TAG_NAME" echo -e "All branches and tags have been pushed to origin."