Skip to content

Commit aefa766

Browse files
add Github Action
1 parent 4284195 commit aefa766

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish and Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
name: Publish and Create Release
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write # 确保有权创建 Release
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
cache: 'npm'
24+
25+
- name: Install Dependencies
26+
run: npm install
27+
28+
- name: Install vsce
29+
run: npm install -g @vscode/vsce
30+
31+
# 优化点:先打包出 vsix 文件,这样既能发布到商店,也能上传到 GitHub Release
32+
- name: Build VSIX
33+
run: vsce package -o ./extension.vsix
34+
35+
- name: Publish to Marketplace
36+
env:
37+
VSCE_PAT: ${{ secrets.VSCE_PAT }}
38+
run: |
39+
# 使用已经打包好的 vsix 文件进行发布,效率更高且保证内容一致
40+
if [[ ${{ github.ref_name }} == *-* ]]; then
41+
echo "检测到先行版本标签,正在发布预发布版..."
42+
vsce publish --pre-release -p $VSCE_PAT --packagePath ./extension.vsix
43+
else
44+
echo "检测到正式版本标签,正在发布正式版..."
45+
vsce publish -p $VSCE_PAT --packagePath ./extension.vsix
46+
fi
47+
48+
- name: Extract Release Notes
49+
id: extract_release_notes
50+
uses: anton-prakapovich/extract-release-notes-action@v1
51+
with:
52+
filename: CHANGELOG.md
53+
# 如果你的标签是 v1.0.0 但 CHANGELOG 里是 [1.0.0],去掉开头的 v
54+
version: ${{ github.ref_name }}
55+
56+
- name: Get Previous Tag
57+
id: pre_tag
58+
run: |
59+
# 增加容错,如果没有上一个 tag 则不输出
60+
prev_tag=$(git describe --abbrev=0 --tags ${{ github.ref_name }}^ 2>/dev/null || echo "")
61+
echo "prev=$prev_tag" >> $GITHUB_OUTPUT
62+
63+
- name: Create GitHub Release
64+
uses: softprops/action-gh-release@v2
65+
with:
66+
# 如果是预发布版,GitHub Release 也会标记为 Pre-release
67+
prerelease: ${{ contains(github.ref_name, '-') }}
68+
body: |
69+
${{ steps.extract_release_notes.outputs.contents }}
70+
71+
---
72+
${{ steps.pre_tag.outputs.prev != '' && format('**Full Changelog**: https://github.com/{0}/compare/{1}...{2}', github.repository, steps.pre_tag.outputs.prev, github.ref_name) || 'Initial Release' }}
73+
files: |
74+
./extension.vsix
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)