sshtunnel/bin/scripts/release.sh

88 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
source bin/helpers/func.sh
printfe "%s\n" "green" "SSH Tunnel Manager Release Script"
printfe "%s\n" "normal" "==============================="
# Check if git is installed
if ! command -v git &> /dev/null; then
printfe "%s\n" "red" "Error: git is not installed"
exit 1
fi
# Check if we're in a git repository
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
printfe "%s\n" "red" "Error: Not in a git repository"
exit 1
fi
# Fetch all tags first to ensure we have the latest
printfe "%s\n" "cyan" "Fetching all tags..."
log_and_run git fetch --tags
# Get the latest version tag, excluding 'latest' tag, or default to v0.0.0 if no tags exist
VERSION_TAGS=$(git tag -l 'v*.*.*' | grep -v 'latest' | sort -V)
if [ -z "$VERSION_TAGS" ]; then
printfe "%s\n" "yellow" "No version tags found. Starting with v0.0.0."
LATEST_TAG="v0.0.0"
else
# Get the latest version tag
LATEST_TAG=$(echo "$VERSION_TAGS" | tail -n 1)
printfe "%s" "cyan" "Found latest version tag: "
printfe "%s\n" "yellow" "$LATEST_TAG" false
fi
# Parse the version number
if [[ $LATEST_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
else
printfe "%s\n" "red" "Error: Could not parse latest tag: $LATEST_TAG"
exit 1
fi
# Calculate the next patch version
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION="v$MAJOR.$MINOR.$NEXT_PATCH"
# Display current version and suggested next version
printfe "%s" "cyan" "Current version: "
printfe "%s\n" "yellow" "$LATEST_TAG" false
printfe "%s" "cyan" "Suggested next version: "
printfe "%s\n" "yellow" "$NEXT_VERSION" false
# Ask for confirmation or custom version
read -p "Accept suggested version? (y/n) " ACCEPT
if [[ $ACCEPT != "y" && $ACCEPT != "Y" ]]; then
read -p "Enter custom version (format vX.Y.Z): " CUSTOM_VERSION
if [[ $CUSTOM_VERSION =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
NEXT_VERSION=$CUSTOM_VERSION
else
printfe "%s\n" "red" "Error: Invalid version format. Must be vX.Y.Z where X, Y, Z are numbers."
exit 1
fi
fi
printfe "%s" "cyan" "Creating and pushing tag: "
printfe "%s\n" "yellow" "$NEXT_VERSION" false
# Make sure we have the latest changes
# We've already fetched tags at the beginning
# Create the new tag
printfe "%s\n" "cyan" "Creating new tag..."
log_and_run git tag "$NEXT_VERSION"
# Push the new tag
printfe "%s\n" "cyan" "Pushing new tag..."
log_and_run git push origin "$NEXT_VERSION"
# Update the latest tag
printfe "%s\n" "cyan" "Updating 'latest' tag..."
log_and_run git tag -f latest "$NEXT_VERSION"
log_and_run git push -f origin latest
printfe "%s\n" "green" "Successfully tagged and pushed version $NEXT_VERSION"
printfe "%s\n" "cyan" "Also updated 'latest' tag to point to $NEXT_VERSION"