|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Script to version FirebaseAuthSwiftUI package |
| 4 | +# This script will: |
| 5 | +# 1. Check we're on main branch with clean working directory |
| 6 | +# 2. Get latest git tag |
| 7 | +# 3. Prompt for new version |
| 8 | +# 4. Update Version.swift |
| 9 | +# 5. Commit, tag, and push changes |
| 10 | +# |
| 11 | +# Usage: |
| 12 | +# ./release-swift.sh # Normal mode (actually commits and pushes) |
| 13 | +# ./release-swift.sh --dry-run # Dry run mode (simulates without pushing) |
| 14 | + |
| 15 | +set -euo pipefail |
| 16 | + |
| 17 | +# Check for dry-run flag |
| 18 | +DRY_RUN=false |
| 19 | +if [ "${1:-}" = "--dry-run" ]; then |
| 20 | + DRY_RUN=true |
| 21 | + echo -e "\033[1;33m⚠️ DRY RUN MODE - No changes will be pushed to remote ⚠️\033[0m" |
| 22 | + echo "" |
| 23 | +fi |
| 24 | + |
| 25 | +# Colors for output |
| 26 | +RED='\033[0;31m' |
| 27 | +GREEN='\033[0;32m' |
| 28 | +YELLOW='\033[1;33m' |
| 29 | +NC='\033[0m' # No Color |
| 30 | + |
| 31 | +VERSION_FILE="FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Version.swift" |
| 32 | + |
| 33 | +echo -e "${GREEN}=== FirebaseAuthSwiftUI Version Release Script ===${NC}" |
| 34 | +echo "" |
| 35 | + |
| 36 | +# Check if we're on main branch |
| 37 | +echo "Checking current branch..." |
| 38 | +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 39 | +if [ "$CURRENT_BRANCH" != "main" ]; then |
| 40 | + echo -e "${RED}Error: Not on main branch (currently on: $CURRENT_BRANCH)${NC}" |
| 41 | + echo "Please switch to main branch before running this script." |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | +echo -e "${GREEN}✓ On main branch${NC}" |
| 45 | +echo "" |
| 46 | + |
| 47 | +# Check if working directory is clean |
| 48 | +echo "Checking working directory status..." |
| 49 | +if ! git diff-index --quiet HEAD --; then |
| 50 | + echo -e "${RED}Error: Working directory is not clean${NC}" |
| 51 | + echo "Please commit or stash your changes before running this script." |
| 52 | + echo "" |
| 53 | + echo "Current status:" |
| 54 | + git status --short |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | +echo -e "${GREEN}✓ Working directory is clean${NC}" |
| 58 | +echo "" |
| 59 | + |
| 60 | +# Get the latest tag |
| 61 | +echo "Fetching latest tags from remote..." |
| 62 | +git fetch --tags --quiet |
| 63 | + |
| 64 | +LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 65 | +if [ -z "$LATEST_TAG" ]; then |
| 66 | + echo -e "${YELLOW}No existing tags found${NC}" |
| 67 | + LATEST_VERSION="none" |
| 68 | +else |
| 69 | + echo "Latest tag: $LATEST_TAG" |
| 70 | + # Remove 'v' prefix if present |
| 71 | + LATEST_VERSION="${LATEST_TAG#v}" |
| 72 | +fi |
| 73 | +echo "" |
| 74 | + |
| 75 | +# Prompt for new version |
| 76 | +echo -e "${YELLOW}Enter the new version number (e.g., 15.0.2):${NC}" |
| 77 | +read -r NEW_VERSION |
| 78 | + |
| 79 | +# Validate semantic versioning format |
| 80 | +if ! [[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 81 | + echo -e "${RED}Error: Invalid version format${NC}" |
| 82 | + echo "Version must follow semantic versioning (X.Y.Z where X, Y, Z are numbers)" |
| 83 | + exit 1 |
| 84 | +fi |
| 85 | +echo -e "${GREEN}✓ Valid semantic version format${NC}" |
| 86 | +echo "" |
| 87 | + |
| 88 | +# Add 'v' prefix and confirm |
| 89 | +NEW_TAG="v${NEW_VERSION}" |
| 90 | +echo -e "${YELLOW}Version will be tagged as: ${GREEN}${NEW_TAG}${NC}" |
| 91 | +echo "Previous version: ${LATEST_VERSION}" |
| 92 | +echo "" |
| 93 | +echo -e "${YELLOW}Confirm this version? (y/n):${NC}" |
| 94 | +read -r CONFIRM |
| 95 | + |
| 96 | +if [ "$CONFIRM" != "y" ] && [ "$CONFIRM" != "Y" ]; then |
| 97 | + echo -e "${RED}Version release cancelled${NC}" |
| 98 | + exit 0 |
| 99 | +fi |
| 100 | +echo "" |
| 101 | + |
| 102 | +# Check if tag already exists |
| 103 | +if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then |
| 104 | + echo -e "${RED}Error: Tag $NEW_TAG already exists${NC}" |
| 105 | + echo "Please choose a different version number." |
| 106 | + exit 1 |
| 107 | +fi |
| 108 | +echo -e "${GREEN}✓ Tag $NEW_TAG does not exist${NC}" |
| 109 | +echo "" |
| 110 | + |
| 111 | +# Update Version.swift file |
| 112 | +echo "Updating $VERSION_FILE..." |
| 113 | +if [ ! -f "$VERSION_FILE" ]; then |
| 114 | + echo -e "${RED}Error: $VERSION_FILE not found${NC}" |
| 115 | + exit 1 |
| 116 | +fi |
| 117 | + |
| 118 | +# Create backup |
| 119 | +cp "$VERSION_FILE" "${VERSION_FILE}.bak" |
| 120 | + |
| 121 | +# Update the version in the file |
| 122 | +sed -i.tmp "s/public static let version = \".*\"/public static let version = \"${NEW_VERSION}\"/" "$VERSION_FILE" |
| 123 | +rm "${VERSION_FILE}.tmp" |
| 124 | + |
| 125 | +# Show the changes |
| 126 | +echo "" |
| 127 | +echo -e "${YELLOW}Changes to be committed:${NC}" |
| 128 | +echo "---" |
| 129 | +git diff "$VERSION_FILE" |
| 130 | +echo "---" |
| 131 | +echo "" |
| 132 | + |
| 133 | +echo -e "${YELLOW}Proceed with commit, tag, and push? (y/n):${NC}" |
| 134 | +read -r FINAL_CONFIRM |
| 135 | + |
| 136 | +if [ "$FINAL_CONFIRM" != "y" ] && [ "$FINAL_CONFIRM" != "Y" ]; then |
| 137 | + echo -e "${YELLOW}Restoring backup and cancelling...${NC}" |
| 138 | + mv "${VERSION_FILE}.bak" "$VERSION_FILE" |
| 139 | + exit 0 |
| 140 | +fi |
| 141 | + |
| 142 | +# Remove backup |
| 143 | +rm "${VERSION_FILE}.bak" |
| 144 | + |
| 145 | +# Commit the changes |
| 146 | +echo "" |
| 147 | +echo "Committing changes..." |
| 148 | +git add "$VERSION_FILE" |
| 149 | +git commit -m "chore: update FirebaseAuthSwiftUI version" |
| 150 | +echo -e "${GREEN}✓ Changes committed${NC}" |
| 151 | +echo "" |
| 152 | + |
| 153 | +# Create annotated tag |
| 154 | +echo "Creating annotated tag $NEW_TAG..." |
| 155 | +git tag -a "$NEW_TAG" -m "Release $NEW_TAG" |
| 156 | +echo -e "${GREEN}✓ Tag created${NC}" |
| 157 | +echo "" |
| 158 | + |
| 159 | +if [ "$DRY_RUN" = true ]; then |
| 160 | + echo -e "${YELLOW}DRY RUN: Skipping push operations${NC}" |
| 161 | + echo "" |
| 162 | + echo "Would push:" |
| 163 | + echo " - Commit to origin/main" |
| 164 | + echo " - Tag $NEW_TAG to origin" |
| 165 | + echo "" |
| 166 | + echo -e "${YELLOW}Cleaning up (removing commit and tag)...${NC}" |
| 167 | + git tag -d "$NEW_TAG" |
| 168 | + git reset --soft HEAD~1 |
| 169 | + git restore --staged "$VERSION_FILE" |
| 170 | + echo -e "${GREEN}✓ Local changes cleaned up${NC}" |
| 171 | + echo "" |
| 172 | + echo -e "${GREEN}=== Dry Run Complete ===${NC}" |
| 173 | + echo "Version: $NEW_VERSION" |
| 174 | + echo "Tag: $NEW_TAG" |
| 175 | + echo "" |
| 176 | + echo "Everything looks good! Run without --dry-run to actually release." |
| 177 | +else |
| 178 | + # Push commit |
| 179 | + echo "Pushing commit to remote..." |
| 180 | + git push origin main |
| 181 | + echo -e "${GREEN}✓ Commit pushed${NC}" |
| 182 | + echo "" |
| 183 | + |
| 184 | + # Push tag |
| 185 | + echo "Pushing tag to remote..." |
| 186 | + git push origin "$NEW_TAG" |
| 187 | + echo -e "${GREEN}✓ Tag pushed${NC}" |
| 188 | + echo "" |
| 189 | + |
| 190 | + echo -e "${GREEN}=== Release Complete ===${NC}" |
| 191 | + echo "Version: $NEW_VERSION" |
| 192 | + echo "Tag: $NEW_TAG" |
| 193 | + echo "" |
| 194 | + echo "Next steps:" |
| 195 | + echo "1. Verify the tag on GitHub: https://github.com/firebase/FirebaseUI-iOS/releases" |
| 196 | + echo "2. Create release notes if needed" |
| 197 | +fi |
| 198 | + |
0 commit comments