Skip to content

Commit 14b7a74

Browse files
committed
test: github actions
1 parent 2f0d994 commit 14b7a74

5 files changed

Lines changed: 540 additions & 0 deletions

File tree

.github/workflows/release-on-tag.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
packages: write
1114

1215
steps:
1316
- name: Checkout
@@ -51,5 +54,7 @@ jobs:
5154
prerelease: false
5255
files: |
5356
build/distributions/*.zip
57+
generate_release_notes: true
58+
make_latest: true
5459
env:
5560
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

scripts/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# 版本标签管理脚本
2+
3+
这个目录包含了用于管理 ZY 语言插件版本的自动化脚本。
4+
5+
## 脚本说明
6+
7+
### 1. `tag-version.sh` - 完整版本管理脚本
8+
9+
功能完整的版本标签管理脚本,支持多种版本递增类型。
10+
11+
#### 使用方法
12+
13+
```bash
14+
# 显示帮助信息
15+
./scripts/tag-version.sh --help
16+
17+
# 查看当前版本
18+
./scripts/tag-version.sh --current
19+
20+
# 创建补丁版本 (1.0.0 -> 1.0.1)
21+
./scripts/tag-version.sh --patch
22+
23+
# 创建次版本 (1.0.0 -> 1.1.0)
24+
./scripts/tag-version.sh --minor
25+
26+
# 创建主版本 (1.0.0 -> 2.0.0)
27+
./scripts/tag-version.sh --major
28+
```
29+
30+
#### 功能特性
31+
32+
- ✅ 自动检测当前版本
33+
- ✅ 支持三种版本递增类型
34+
- ✅ 分支验证(建议在 main 分支使用)
35+
- ✅ 工作目录状态检查
36+
- ✅ 交互式确认
37+
- ✅ 自动推送到远程仓库
38+
- ✅ 彩色输出和错误处理
39+
40+
### 2. `quick-tag.sh` - 快速标签脚本
41+
42+
简化的快速标签创建脚本,自动递增补丁版本。
43+
44+
#### 使用方法
45+
46+
```bash
47+
# 快速创建下一个补丁版本标签
48+
./scripts/quick-tag.sh
49+
```
50+
51+
#### 功能特性
52+
53+
- ✅ 自动递增补丁版本
54+
- ✅ 工作目录状态检查
55+
- ✅ 交互式确认
56+
- ✅ 自动推送到远程仓库
57+
- ✅ 友好的用户界面
58+
59+
## 版本号规则
60+
61+
遵循 [语义化版本](https://semver.org/lang/zh-CN/) 规范:
62+
63+
- **主版本号 (Major)**: 不兼容的 API 修改
64+
- **次版本号 (Minor)**: 向下兼容的功能性新增
65+
- **补丁版本号 (Patch)**: 向下兼容的问题修正
66+
67+
## 使用建议
68+
69+
### 日常开发
70+
71+
```bash
72+
# 修复 bug 或小改动
73+
./scripts/quick-tag.sh
74+
```
75+
76+
### 功能发布
77+
78+
```bash
79+
# 新功能发布
80+
./scripts/tag-version.sh --minor
81+
```
82+
83+
### 重大更新
84+
85+
```bash
86+
# 重大版本更新
87+
./scripts/tag-version.sh --major
88+
```
89+
90+
## 自动化流程
91+
92+
1. **创建标签** → 脚本自动创建 Git 标签
93+
2. **推送标签** → 自动推送到远程仓库
94+
3. **触发构建** → GitHub Actions 检测到新标签
95+
4. **自动发布** → 构建完成后自动创建 GitHub Release
96+
97+
## 注意事项
98+
99+
- 确保在 `main` 分支上创建标签
100+
- 确保工作目录干净(无未提交的更改)
101+
- 标签创建后会自动触发 GitHub Actions 构建
102+
- 建议在创建标签前先测试代码
103+
104+
## 故障排除
105+
106+
### 工作目录不干净
107+
108+
```bash
109+
# 提交所有更改
110+
git add .
111+
git commit -m "准备发布新版本"
112+
113+
# 或者暂存更改
114+
git stash
115+
```
116+
117+
### 标签已存在
118+
119+
```bash
120+
# 删除本地标签
121+
git tag -d v1.0.0
122+
123+
# 删除远程标签
124+
git push origin :refs/tags/v1.0.0
125+
```
126+
127+
### 权限问题
128+
129+
```bash
130+
# 确保脚本有执行权限
131+
chmod +x scripts/*.sh
132+
```

scripts/create-release.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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"

scripts/quick-tag.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# 快速标签脚本 - 自动递增补丁版本
4+
# 用法: ./scripts/quick-tag.sh
5+
6+
echo "🚀 ZY 语言插件快速标签创建"
7+
echo "================================"
8+
9+
# 检查是否有未提交的更改
10+
if ! git diff-index --quiet HEAD --; then
11+
echo "❌ 工作目录不干净,请先提交更改"
12+
git status --short
13+
exit 1
14+
fi
15+
16+
# 获取当前版本
17+
current_version=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
18+
current_version=${current_version#v}
19+
20+
echo "📋 当前版本: v$current_version"
21+
22+
# 解析版本号
23+
IFS='.' read -ra VERSION_PARTS <<< "$current_version"
24+
major=${VERSION_PARTS[0]:-0}
25+
minor=${VERSION_PARTS[1]:-0}
26+
patch=${VERSION_PARTS[2]:-0}
27+
28+
# 递增补丁版本
29+
patch=$((patch + 1))
30+
new_version="$major.$minor.$patch"
31+
32+
echo "🆕 新版本: v$new_version"
33+
34+
# 确认创建
35+
read -p "确认创建标签 v$new_version? (y/N): " -n 1 -r
36+
echo
37+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
38+
echo "❌ 操作已取消"
39+
exit 0
40+
fi
41+
42+
# 创建标签
43+
echo "🏷️ 创建标签 v$new_version..."
44+
git tag -a "v$new_version" -m "Release version $new_version"
45+
46+
# 推送标签
47+
echo "📤 推送标签到远程仓库..."
48+
git push origin "v$new_version"
49+
50+
echo "✅ 标签创建成功!"
51+
echo "🎉 GitHub Actions 将自动构建并发布插件"
52+
echo "🔗 查看发布: https://github.com/$(git config --get remote.origin.url | sed 's/.*github.com[:/]\([^.]*\).*/\1/')/releases"

0 commit comments

Comments
 (0)