#!/bin/bash
# Script to create a git tag and update the version in main.goset -e
if[ -z "$1"];thenecho"Usage: $0 <version>"echo"Example: $0 v1.0.0"exit1fiTAG_NAME="$1"# Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)VERSION="${TAG_NAME#v}"# Path to main.goMAIN_GO="main.go"# Check if main.go existsif[ ! -f "$MAIN_GO"];thenecho"Error: $MAIN_GO not found"exit1fi# Check if we're in a git repoif ! git rev-parse --git-dir > /dev/null 2>&1;thenecho"Error: Not in a git repository"exit1fi# Check if tag already existsif git rev-parse "$TAG_NAME" > /dev/null 2>&1;thenecho"Error: Tag $TAG_NAME already exists"exit1fi# Update the version variable in main.gosed -i "s/^var version = \".*\"/var version = \"$VERSION\"/""$MAIN_GO"# Update the version variable in the frontend package.jsonjq ".version = \"$VERSION\"""internal/dashboard/frontend/package.json" > "internal/dashboard/frontend/package.json.tmp"mv "internal/dashboard/frontend/package.json.tmp""internal/dashboard/frontend/package.json"# Build the frontendcd internal/dashboard/frontend
pnpm build
cd ../../..
# Wait a little bit for git to catch upsleep 3# Stage the changegit add .
# Commit the version updategit commit -m "chore: update version to $VERSION"||{echo"Warning: No changes to commit (version may already be $VERSION)"}# Create the taggit tag -a "$TAG_NAME" -m "Release $TAG_NAME"git push && git push --tags
echo"Version updated to $VERSION and tag $TAG_NAME pushed successfully"