-
Notifications
You must be signed in to change notification settings - Fork 42
138 lines (122 loc) · 4.25 KB
/
release.yml
File metadata and controls
138 lines (122 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Build and Release
# 触发条件
on:
# 手动触发
workflow_dispatch:
inputs:
version:
description: '版本号 (留空则使用 package.json 中的版本)'
required: false
type: string
prerelease:
description: '是否为预发布版本'
required: false
type: boolean
default: false
draft:
description: '是否创建草稿 Release'
required: false
type: boolean
default: false
# 当推送 tag 时自动触发
push:
tags:
- 'v*.*.*'
# 设置权限
permissions:
contents: write
packages: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
# 1. 检出代码
- name: 📥 Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# 2. 设置 Node.js 环境
- name: 🔧 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.19.3'
cache: 'npm'
# 3. 安装依赖
- name: 📦 Install dependencies
run: npm install
# 3.1 构建 Webview (VSCode 插件 UI)
- name: 🌐 Build Webview
run: npm run build:webview --workspace=packages/vscode-ui-plugin
# 4. 获取并同步版本号
- name: 📌 Get and Sync version
id: get_version
run: |
# 1. 确定版本号
if [ -n "${{ inputs.version }}" ]; then
VERSION="${{ inputs.version }}"
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
else
VERSION=$(node -p "require('./package.json').version")
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Final target version: $VERSION"
# 2. 同步版本号到所有 package.json (仅在 runner 环境中,不提交回仓库)
node -e "
const fs = require('fs');
const paths = [
'package.json',
'packages/cli/package.json',
'packages/cli/src/package.json',
'packages/core/package.json',
'packages/vscode-ide-companion/package.json'
];
paths.forEach(p => {
if (fs.existsSync(p)) {
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
const oldVersion = pkg.version;
pkg.version = '$VERSION';
fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
console.log('✅ Updated ' + p + ': ' + oldVersion + ' -> $VERSION');
}
});
"
# 5. 构建跨平台包(由于已经同步了版本号,这里使用 --no-version-bump)
- name: 🏗️ Build cross-platform package
run: npm run pack:prod:ci
env:
NODE_ENV: production
# 6. 查找构建产物
- name: 🔍 Find build artifacts
id: find_artifacts
run: |
VERSION="${{ steps.get_version.outputs.VERSION }}"
TGZ_FILE="deepv-code-${VERSION}.tgz"
if [ ! -f "$TGZ_FILE" ]; then
echo "❌ Expected artifact not found: $TGZ_FILE"
echo "📁 Available .tgz files:"
ls -lh deepv-code-*.tgz 2>/dev/null || echo " (none)"
exit 1
fi
echo "TGZ_FILE=$TGZ_FILE" >> $GITHUB_OUTPUT
echo "✅ Found artifact: $TGZ_FILE"
ls -lh $TGZ_FILE
# 7. 创建 GitHub Release (使用 tag message 作为 release notes)
- name: 🚀 Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get_version.outputs.VERSION }}
name: DeepV Code v${{ steps.get_version.outputs.VERSION }}
draft: ${{ inputs.draft || false }}
prerelease: ${{ inputs.prerelease || false }}
files: ${{ steps.find_artifacts.outputs.TGZ_FILE }}
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 8. 上传构建产物为 workflow artifact
- name: 📤 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: deepv-code-v${{ steps.get_version.outputs.VERSION }}
path: ${{ steps.find_artifacts.outputs.TGZ_FILE }}
retention-days: 90