|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# 手动创建 GitHub Release 脚本 |
| 4 | +# 当自动创建失败时使用 |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# 颜色输出 |
| 9 | +RED='\033[0;31m' |
| 10 | +GREEN='\033[0;32m' |
| 11 | +YELLOW='\033[1;33m' |
| 12 | +BLUE='\033[0;34m' |
| 13 | +NC='\033[0m' |
| 14 | + |
| 15 | +print_info() { |
| 16 | + echo -e "${BLUE}[INFO]${NC} $1" |
| 17 | +} |
| 18 | + |
| 19 | +print_success() { |
| 20 | + echo -e "${GREEN}[SUCCESS]${NC} $1" |
| 21 | +} |
| 22 | + |
| 23 | +print_warning() { |
| 24 | + echo -e "${YELLOW}[WARNING]${NC} $1" |
| 25 | +} |
| 26 | + |
| 27 | +print_error() { |
| 28 | + echo -e "${RED}[ERROR]${NC} $1" |
| 29 | +} |
| 30 | + |
| 31 | +# 检查是否在 Git 仓库中 |
| 32 | +if ! git rev-parse --git-dir > /dev/null 2>&1; then |
| 33 | + print_error "当前目录不是 Git 仓库" |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +# 获取当前标签 |
| 38 | +current_tag=$(git describe --tags --exact-match HEAD 2>/dev/null || echo "") |
| 39 | +if [[ -z "$current_tag" ]]; then |
| 40 | + print_error "当前 HEAD 没有对应的标签" |
| 41 | + print_info "请先创建标签: ./scripts/quick-tag.sh" |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | + |
| 45 | +print_info "当前标签: $current_tag" |
| 46 | + |
| 47 | +# 检查插件文件是否存在 |
| 48 | +plugin_file="build/distributions/plugin-distributions-${current_tag#v}.zip" |
| 49 | +if [[ ! -f "$plugin_file" ]]; then |
| 50 | + print_error "插件文件不存在: $plugin_file" |
| 51 | + print_info "请先构建插件: ./gradlew buildPlugin" |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +print_info "找到插件文件: $plugin_file" |
| 56 | + |
| 57 | +# 获取仓库信息 |
| 58 | +repo_url=$(git config --get remote.origin.url) |
| 59 | +if [[ "$repo_url" =~ github\.com[:/]([^/]+)/([^/]+) ]]; then |
| 60 | + owner="${BASH_REMATCH[1]}" |
| 61 | + repo="${BASH_REMATCH[2]%.git}" |
| 62 | +else |
| 63 | + print_error "无法解析 GitHub 仓库信息" |
| 64 | + exit 1 |
| 65 | +fi |
| 66 | + |
| 67 | +print_info "仓库: $owner/$repo" |
| 68 | + |
| 69 | +# 检查 GitHub CLI 是否安装 |
| 70 | +if ! command -v gh &> /dev/null; then |
| 71 | + print_error "GitHub CLI (gh) 未安装" |
| 72 | + print_info "请安装 GitHub CLI: https://cli.github.com/" |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +# 检查是否已登录 |
| 77 | +if ! gh auth status &> /dev/null; then |
| 78 | + print_error "GitHub CLI 未登录" |
| 79 | + print_info "请先登录: gh auth login" |
| 80 | + exit 1 |
| 81 | +fi |
| 82 | + |
| 83 | +# 检查 Release 是否已存在 |
| 84 | +if gh release view "$current_tag" &> /dev/null; then |
| 85 | + print_warning "Release $current_tag 已存在" |
| 86 | + read -p "是否重新创建? (y/N): " -n 1 -r |
| 87 | + echo |
| 88 | + if [[ $REPLY =~ ^[Yy]$ ]]; then |
| 89 | + print_info "删除现有 Release..." |
| 90 | + gh release delete "$current_tag" --yes |
| 91 | + else |
| 92 | + print_info "操作已取消" |
| 93 | + exit 0 |
| 94 | + fi |
| 95 | +fi |
| 96 | + |
| 97 | +# 创建 Release |
| 98 | +print_info "创建 GitHub Release: $current_tag" |
| 99 | + |
| 100 | +# 生成 Release 说明 |
| 101 | +release_notes="## ZY 语言插件 $current_tag |
| 102 | +
|
| 103 | +### 功能特性 |
| 104 | +- 支持 .zy 文件语法高亮 |
| 105 | +- 提供代码补全功能 |
| 106 | +- 支持代码跳转和导航 |
| 107 | +- 集成 IntelliJ IDEA 平台 |
| 108 | +
|
| 109 | +### 安装方法 |
| 110 | +1. 下载插件包 |
| 111 | +2. 在 IntelliJ IDEA 中安装插件 |
| 112 | +3. 重启 IDE 生效 |
| 113 | +
|
| 114 | +### 支持版本 |
| 115 | +- IntelliJ IDEA 2024.1 - 2025.2 |
| 116 | +- 跨平台支持 (Windows/macOS/Linux) |
| 117 | +
|
| 118 | +### 文件信息 |
| 119 | +- 插件包: plugin-distributions-${current_tag#v}.zip |
| 120 | +- 构建时间: $(date) |
| 121 | +- 构建分支: $(git branch --show-current)" |
| 122 | + |
| 123 | +# 创建 Release |
| 124 | +gh release create "$current_tag" \ |
| 125 | + --title "$current_tag" \ |
| 126 | + --notes "$release_notes" \ |
| 127 | + "$plugin_file" |
| 128 | + |
| 129 | +print_success "Release 创建成功!" |
| 130 | +print_info "查看 Release: https://github.com/$owner/$repo/releases/tag/$current_tag" |
0 commit comments