create-release.sh•7.2 kB
#!/bin/bash
# Release creation script for Radius MCP Server
# Creates Git tags and GitHub releases
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default values
VERSION=""
BRANCH="main"
DRY_RUN=false
PUSH_TAG=true
CREATE_RELEASE=true
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to show usage
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -v, --version VERSION Version to release (e.g., 1.0.0)"
echo " -b, --branch BRANCH Branch to tag [default: main]"
echo " -d, --dry-run Show what would be done without doing it"
echo " --no-push Don't push the tag to remote"
echo " --no-release Don't create GitHub release"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 -v 1.0.0 # Create release v1.0.0"
echo " $0 -v 1.0.0 -d # Dry run for v1.0.0"
echo " $0 -v 1.0.0 --no-push # Create tag locally only"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-v|--version)
VERSION="$2"
shift 2
;;
-b|--branch)
BRANCH="$2"
shift 2
;;
-d|--dry-run)
DRY_RUN=true
shift
;;
--no-push)
PUSH_TAG=false
shift
;;
--no-release)
CREATE_RELEASE=false
shift
;;
-h|--help)
show_usage
exit 0
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Validate version
if [[ -z "$VERSION" ]]; then
print_error "Version is required. Use -v or --version"
show_usage
exit 1
fi
# Validate version format (semantic versioning)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then
print_error "Invalid version format: $VERSION"
print_error "Use semantic versioning: MAJOR.MINOR.PATCH (e.g., 1.0.0)"
exit 1
fi
# Check if we're in a Git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
print_error "Not in a Git repository"
exit 1
fi
# Check if branch exists
if ! git show-ref --verify --quiet "refs/heads/$BRANCH"; then
print_error "Branch '$BRANCH' does not exist"
exit 1
fi
# Check if tag already exists
TAG_NAME="v$VERSION"
if git tag -l | grep -q "^$TAG_NAME$"; then
print_error "Tag '$TAG_NAME' already exists"
exit 1
fi
# Check if working directory is clean
if ! git diff-index --quiet HEAD --; then
print_error "Working directory is not clean. Commit or stash changes first."
exit 1
fi
# Check if we're on the correct branch
CURRENT_BRANCH=$(git branch --show-current)
if [[ "$CURRENT_BRANCH" != "$BRANCH" ]]; then
print_warning "You're not on branch '$BRANCH'. Current: $CURRENT_BRANCH"
if [[ "$DRY_RUN" != "true" ]]; then
print_error "Switch to branch '$BRANCH' first or use --dry-run"
exit 1
fi
fi
print_status "Creating release: $TAG_NAME"
print_status "Branch: $BRANCH"
print_status "Dry run: $DRY_RUN"
print_status "Push tag: $PUSH_TAG"
print_status "Create release: $CREATE_RELEASE"
# Update package.json version
if [[ "$DRY_RUN" == "true" ]]; then
print_status "Would update package.json version to $VERSION"
else
print_status "Updating package.json version to $VERSION"
npm version "$VERSION" --no-git-tag-version
fi
# Create changelog entry
CHANGELOG_ENTRY="## [$VERSION] - $(date +%Y-%m-%d)
### Added
- Employee management functionality
- XLSX import capabilities
- Advanced text parsing
- Data quality validation
- Error handling and retry logic
- Performance monitoring
- Comprehensive test suite
- CI/CD pipeline
### Changed
- Updated to latest dependencies
- Improved error messages
- Enhanced logging
### Fixed
- Various bug fixes and improvements
"
if [[ "$DRY_RUN" == "true" ]]; then
print_status "Would create changelog entry:"
echo "$CHANGELOG_ENTRY"
else
print_status "Creating changelog entry"
if [[ -f "CHANGELOG.md" ]]; then
# Prepend to existing changelog
echo -e "$CHANGELOG_ENTRY\n$(cat CHANGELOG.md)" > CHANGELOG.md
else
# Create new changelog
echo "$CHANGELOG_ENTRY" > CHANGELOG.md
fi
fi
# Commit changes
if [[ "$DRY_RUN" == "true" ]]; then
print_status "Would commit version changes"
else
print_status "Committing version changes"
git add package.json package-lock.json CHANGELOG.md
git commit -m "chore: bump version to $VERSION"
fi
# Create tag
if [[ "$DRY_RUN" == "true" ]]; then
print_status "Would create tag: $TAG_NAME"
else
print_status "Creating tag: $TAG_NAME"
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
fi
# Push changes
if [[ "$PUSH_TAG" == "true" ]]; then
if [[ "$DRY_RUN" == "true" ]]; then
print_status "Would push branch and tag to remote"
else
print_status "Pushing branch and tag to remote"
git push origin "$BRANCH"
git push origin "$TAG_NAME"
fi
else
print_warning "Skipping push to remote (--no-push specified)"
fi
# Create GitHub release
if [[ "$CREATE_RELEASE" == "true" ]]; then
if command -v gh &> /dev/null; then
if [[ "$DRY_RUN" == "true" ]]; then
print_status "Would create GitHub release: $TAG_NAME"
else
print_status "Creating GitHub release: $TAG_NAME"
gh release create "$TAG_NAME" \
--title "Release $TAG_NAME" \
--notes "$CHANGELOG_ENTRY" \
--target "$BRANCH"
fi
else
print_warning "GitHub CLI (gh) not found. Install it to create GitHub releases automatically."
print_status "You can create the release manually at: https://github.com/$(git remote get-url origin | sed 's/.*github.com[:/]\([^/]*\/[^/]*\)\.git.*/\1/')/releases/new"
fi
else
print_warning "Skipping GitHub release creation (--no-release specified)"
fi
# Summary
echo ""
print_status "=== Release Summary ==="
print_status "Version: $VERSION"
print_status "Tag: $TAG_NAME"
print_status "Branch: $BRANCH"
if [[ "$DRY_RUN" == "true" ]]; then
print_warning "This was a dry run. No changes were made."
print_status "Run without --dry-run to create the actual release."
else
print_success "Release $TAG_NAME created successfully!"
if [[ "$PUSH_TAG" == "true" ]]; then
print_success "Tag pushed to remote repository"
fi
if [[ "$CREATE_RELEASE" == "true" ]]; then
print_success "GitHub release created"
fi
print_status "Next steps:"
print_status "1. Verify the release in your repository"
print_status "2. Update deployment configurations if needed"
print_status "3. Notify team members about the new release"
fi