Repository navigation
127 lines (113 loc) · 4.51 KB
/
Copy pathreusable-vscode-plugin.yml
File metadata and controls
127 lines (113 loc) · 4.51 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
# =============================================================================
# Reusable Workflow: VSCode Plugin 构建 / 预发布 / 正式发布
#
# 模式 (mode):
# "package" — 改版本号 + 构建 + 打包 .vsix + 上传 artifact(PR Preview)
# "pre-release" — 改版本号 + 构建 + 预发布到 Marketplace(Merge → dev)
# "release" — 构建 + 正式发布到 Marketplace(Push → main,changeset 版本号)
#
# 步骤:
# 1. 改名(cherry-markdown-core + cherry-markdown)— 解决 workspace 冲突
# 2. 改版本号(package / pre-release 模式加时间戳)
# 3. 安装依赖 + 构建核心库
# 4. 生产模式编译插件
# 5. 打包 / 预发布 / 正式发布
# =============================================================================
name: 'Reusable: VSCode Plugin'
on:
workflow_call:
inputs:
mode:
description: '"package" | "pre-release" | "release"'
required: true
type: string
pr_number:
description: '预发布时需要评论的 PR 编号'
required: false
type: number
default: 0
jobs:
vscode-plugin:
runs-on: ubuntu-latest
timeout-minutes: 30
continue-on-error: ${{ inputs.mode == 'package' }}
steps:
- uses: actions/checkout@v6
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'yarn'
# ── 1. 改名:解决 workspace 同名冲突 ──
- name: Prepare package names
run: bash .github/scripts/prepare-vscode-plugin.sh
# ── 2. 改版本号(package / pre-release 加时间戳)──
- name: Stamp preview version
if: inputs.mode != 'release'
run: |
cd packages/vscodePlugin
TIMESTAMP=$(t=$(date +%m%d%H%M | sed 's/^0*//'); [ -n "$t" ] && printf '%s' "$t" || date +%H%M%S)
tmp=$(mktemp) && jq --arg ts "$TIMESTAMP" '
.version |= (
split(".") as $s |
if ($s|length) < 3 then
error("package.json version must be in '\''x.y.z'\'' format")
else
if $s[2] == "0" then
($s[0:2] + [$ts]) | join(".")
else
($s[0:2] + [($s[2] + $ts)]) | join(".")
end
end
)
' package.json > "$tmp" && mv "$tmp" package.json
# ── 3. 安装依赖 + 构建核心库 ──
- name: Install and Build Dependencies
run: |
yarn --network-timeout 100000
yarn build
# ── 4. 生产模式编译插件 ──
- name: Build VSCode Plugin (production bundle)
run: yarn build:vscodePlugin
# ── 5a. package 模式:打包 + 上传 artifact ──
- name: Package VSCode Plugin
if: inputs.mode == 'package'
run: |
cd packages/vscodePlugin
npx @vscode/vsce package --no-dependencies --no-yarn
- name: Upload VSIX
if: inputs.mode == 'package'
uses: actions/upload-artifact@v4
with:
name: vscode-plugin-vsix
path: packages/vscodePlugin/*.vsix
retention-days: 5
if-no-files-found: warn
# ── 5b. pre-release 模式:预发布到 Marketplace ──
- name: Publish VSCode Plugin (pre-release)
if: inputs.mode == 'pre-release'
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
run: |
cd packages/vscodePlugin
npx @vscode/vsce publish -p $VSCE_PAT --no-dependencies --no-yarn --pre-release
- name: Comment on PR (pre-release)
if: inputs.mode == 'pre-release' && inputs.pr_number > 0
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: ${{ inputs.pr_number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `🔌 Preview Cherry Markdown Extensions [see: prerelease-extensions](https://code.visualstudio.com/api/working-with-extensions/publishing-extension?from_column=20423&from=20423#prerelease-extensions)`
});
# ── 5c. release 模式:正式发布到 Marketplace ──
- name: Publish VSCode Plugin (release)
if: inputs.mode == 'release'
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
run: |
cd packages/vscodePlugin
npx @vscode/vsce publish -p $VSCE_PAT --no-dependencies --no-yarn