Skip to content

Commit 990236a

Browse files
author
sunzhongyi
committed
feat: opt publish flow
1 parent 18533ce commit 990236a

File tree

2 files changed

+81
-69
lines changed

2 files changed

+81
-69
lines changed

.github/workflows/publish.yml

Lines changed: 44 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
name: Publish to VS Code Marketplace
22

33
on:
4-
push:
5-
tags:
6-
- 'v*'
74
workflow_dispatch:
85
inputs:
96
version:
10-
description: 'Version to publish (e.g., 1.0.0, leave empty to use package.json version)'
11-
required: false
12-
default: ''
7+
description: 'Version to publish (e.g., 1.0.0)'
8+
required: true
9+
type: string
10+
release_type:
11+
description: 'Release type'
12+
required: true
13+
type: choice
14+
options:
15+
- 'release'
16+
- 'pre-release'
17+
default: 'release'
1318

1419
jobs:
1520
publish:
1621
runs-on: ubuntu-latest
17-
22+
1823
steps:
1924
- name: Checkout code
2025
uses: actions/checkout@v4
21-
with:
22-
fetch-depth: 0
23-
26+
2427
- name: Setup Node.js
2528
uses: actions/setup-node@v4
2629
with:
2730
node-version: '20.x'
2831
cache: 'npm'
29-
32+
3033
- name: Install dependencies
3134
run: npm ci
32-
33-
- name: Update version if specified
34-
if: github.event.inputs.version != ''
35+
36+
- name: Update version
3537
run: |
3638
echo "Updating version to ${{ github.event.inputs.version }}"
3739
npm version ${{ github.event.inputs.version }} --no-git-tag-version
@@ -41,73 +43,46 @@ jobs:
4143

4244
- name: Install VSCE
4345
run: npm install -g @vscode/vsce
44-
45-
- name: Verify package.json
46-
run: |
47-
echo "Checking package.json..."
48-
cat package.json | jq '.name, .version, .publisher'
49-
46+
5047
- name: Package extension
51-
run: vsce package
52-
53-
- name: List generated files
54-
run: ls -la *.vsix
55-
48+
run: |
49+
if [ "${{ github.event.inputs.release_type }}" = "pre-release" ]; then
50+
vsce package --pre-release
51+
else
52+
vsce package
53+
fi
54+
5655
- name: Publish to VS Code Marketplace
57-
run: vsce publish -p $VSCE_TOKEN
56+
run: |
57+
if [ "${{ github.event.inputs.release_type }}" = "pre-release" ]; then
58+
vsce publish --pre-release -p "$VSCE_TOKEN"
59+
else
60+
vsce publish -p "$VSCE_TOKEN"
61+
fi
5862
env:
5963
VSCE_TOKEN: ${{ secrets.VSCE_TOKEN }}
60-
61-
- name: Upload VSIX to GitHub Release
62-
if: startsWith(github.ref, 'refs/tags/')
64+
65+
- name: Create Git Tag (for releases only)
66+
if: github.event.inputs.release_type == 'release'
67+
run: |
68+
git config --local user.email "[email protected]"
69+
git config --local user.name "GitHub Action"
70+
git tag "v${{ github.event.inputs.version }}"
71+
git push origin "v${{ github.event.inputs.version }}"
72+
73+
- name: Create GitHub Release (for releases only)
74+
if: github.event.inputs.release_type == 'release'
6375
uses: softprops/action-gh-release@v1
6476
with:
77+
tag_name: "v${{ github.event.inputs.version }}"
6578
files: "*.vsix"
6679
generate_release_notes: true
6780
env:
6881
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69-
82+
7083
- name: Upload VSIX artifact
7184
uses: actions/upload-artifact@v4
7285
with:
73-
name: commit-assistant-release-${{ github.sha }}
86+
name: commit-assistant-${{ github.event.inputs.release_type }}-${{ github.event.inputs.version }}
7487
path: "*.vsix"
7588
retention-days: 90
76-
77-
pre-release:
78-
runs-on: ubuntu-latest
79-
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version == ''
80-
81-
steps:
82-
- name: Checkout code
83-
uses: actions/checkout@v4
84-
85-
- name: Setup Node.js
86-
uses: actions/setup-node@v4
87-
with:
88-
node-version: '20.x'
89-
cache: 'npm'
90-
91-
- name: Install dependencies
92-
run: npm ci
93-
94-
- name: Build project
95-
run: npm run build
96-
97-
- name: Install VSCE
98-
run: npm install -g @vscode/vsce
99-
100-
- name: Package pre-release
101-
run: vsce package --pre-release
102-
103-
- name: Publish pre-release to VS Code Marketplace
104-
run: vsce publish --pre-release -p $VSCE_TOKEN
105-
env:
106-
VSCE_TOKEN: ${{ secrets.VSCE_TOKEN }}
107-
108-
- name: Upload pre-release VSIX artifact
109-
uses: actions/upload-artifact@v4
110-
with:
111-
name: commit-assistant-prerelease-${{ github.sha }}
112-
path: "*.vsix"
113-
retention-days: 30

build&publish.note

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 开发新功能时
2+
git commit -m "feat: add new feature"
3+
git push
4+
5+
6+
7+
## 🎯 简化发布流程
8+
9+
10+
### ✅ **只有一种发布方式**:手动触发
11+
12+
1. **去 GitHub Actions 页面**
13+
2. **点击 "Run workflow"**
14+
3. **填写两个参数**:
15+
- **Version**: 输入版本号(如 `1.0.0`)
16+
- **Release type**: 选择 `release` 或 `pre-release`
17+
4. **点击绿色的 "Run workflow" 按钮**
18+
19+
### 🔄 **自动化处理**:
20+
21+
- ✅ 自动更新 `package.json` 中的版本号
22+
- ✅ 自动构建项目
23+
- ✅ 自动打包扩展
24+
- ✅ 自动发布到 VS Code Marketplace
25+
- ✅ 如果是正式版本,自动创建 Git tag 和 GitHub Release
26+
- ✅ 自动上传 .vsix 文件作为 artifact
27+
28+
### 📋 **使用示例**:
29+
30+
**发布正式版本 1.0.0**:
31+
- Version: `1.0.0`
32+
- Release type: `release`
33+
34+
**发布预发布版本 1.1.0-beta.1**:
35+
- Version: `1.1.0-beta.1`
36+
- Release type: `pre-release`
37+

0 commit comments

Comments
 (0)