#!/bin/bash
# 快速回滚脚本

ENV=$1
VERSION=$2

if [ -z "$ENV" ] || [ -z "$VERSION" ]; then
    echo "用法: ./rollback.sh <环境> <版本号>"
    echo "环境选项: staging/prod"
    exit 1
fi

case $ENV in
    canary)
        git checkout main
        git reset --hard "v${VERSION}-canary"
        git push canary main --force
        ;;
    dev)
        git checkout main
        git reset --hard "v${VERSION}-dev"
        git push dev main --force
        ;;
    beta)
        git checkout main
        git reset --hard "v${VERSION}-beta"
        git push beta main --force
        ;;
    *)
        echo "无效的环境选项: canary/dev/beta"
        exit 1
        ;;
esac

echo "✅ 回滚完成: ${ENV} -> v${VERSION}"
