Skip to content

Commit 70e1f8d

Browse files
th-ddaction-assistant[bot]PtJade-Ceramicsaime428sourcery-ai[bot]
authored
ci: 升级构建流程和依赖 (#769)
Signed-off-by: 叹号大帝 <162813557+th-dd@users.noreply.github.com> Signed-off-by: action-assistant[bot] <152410706+action-assistant[bot]@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: action-assistant[bot] <152410706+action-assistant[bot]@users.noreply.github.com> Co-authored-by: PtJade Ceramic <185668489+PtJade-Ceramic@users.noreply.github.com> Co-authored-by: saime428 <51110572+saime428@users.noreply.github.com> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 59c9ee9 commit 70e1f8d

6 files changed

Lines changed: 844 additions & 330 deletions

File tree

.github/dependabot.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ updates:
99
directory: "/"
1010
schedule:
1111
interval: "weekly"
12-
open-pull-requests-limit: 3
12+
groups:
13+
github-actions:
14+
patterns:
15+
- "*"
16+
17+
- package-ecosystem: "npm"
18+
directory: "/vscode-extension"
19+
schedule:
20+
interval: "weekly"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Build Extension
2+
3+
on:
4+
# 定时触发:每5天自动运行一次
5+
schedule:
6+
- cron: '0 0 */5 * *'
7+
8+
# 代码推送触发:当 vscode-extension 目录有变更时自动构建
9+
push:
10+
paths:
11+
- 'vscode-extension/**'
12+
13+
# PR 触发:当 PR 涉及 vscode-extension 目录变更时构建
14+
pull_request:
15+
paths:
16+
- 'vscode-extension/**'
17+
18+
# 手动触发:允许在 Actions 页面手动点击运行
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: read
23+
pull-requests: write
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
outputs:
29+
expires_at: ${{ steps.calc-expiry.outputs.expires_at }}
30+
artifact_name: ${{ steps.package.outputs.artifact_name }}
31+
vsix_path: ${{ steps.package.outputs.vsix_path }}
32+
33+
steps:
34+
- name: 检出代码
35+
uses: actions/checkout@v7
36+
37+
- name: 设置 Node.js 环境
38+
uses: actions/setup-node@v7
39+
with:
40+
node-version: '24'
41+
cache: 'npm'
42+
cache-dependency-path: 'vscode-extension/package-lock.json'
43+
44+
- name: 进入插件目录并安装依赖
45+
run: |
46+
cd vscode-extension
47+
npm ci
48+
49+
- name: 打包 VSIX
50+
id: package
51+
run: |
52+
cd vscode-extension
53+
# 清理旧的 VSIX 文件,避免上传历史构件
54+
rm -f ./*.vsix
55+
# 使用 package.json 中的 name 和 version 生成确定性的文件名
56+
PKG_NAME=$(node -p "require('./package.json').name")
57+
PKG_VERSION=$(node -p "require('./package.json').version")
58+
VSIX_FILE="${PKG_NAME}-${PKG_VERSION}.vsix"
59+
# 以指定的文件名打包 VSIX,避免依赖 ls 和通配符
60+
npx @vscode/vsce package -o "$VSIX_FILE"
61+
echo "artifact_name=$VSIX_FILE" >> $GITHUB_OUTPUT
62+
echo "vsix_path=vscode-extension/$VSIX_FILE" >> $GITHUB_OUTPUT
63+
64+
- name: 计算过期时间
65+
id: calc-expiry
66+
run: |
67+
EXPIRY_DATE=$(date -u -d "+5 days" '+%Y-%m-%d %H:%M UTC')
68+
echo "expires_at=$EXPIRY_DATE" >> $GITHUB_OUTPUT
69+
70+
- name: 上传构件
71+
uses: actions/upload-artifact@v7
72+
with:
73+
name: github-chinese-extension
74+
path: ${{ steps.package.outputs.vsix_path }}
75+
retention-days: 5
76+
archive: false
77+
78+
- name: 生成运行摘要
79+
if: always()
80+
run: |
81+
cat >> $GITHUB_STEP_SUMMARY << 'EOF'
82+
## 📦 GitHub 中文化扩展构建报告
83+
84+
| 项目 | 详情 |
85+
| :--- | :--- |
86+
| **构建状态** | ${{ job.status == 'success' && '✅ 成功' || '❌ 失败' }} |
87+
| **触发方式** | ${{ github.event_name }} |
88+
| **产物名称** | `${{ steps.package.outputs.artifact_name }}` |
89+
| **预计过期时间** | **${{ steps.calc-expiry.outputs.expires_at }}** |
90+
EOF

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ Desktop.ini
1313
main(local).js
1414
# VS Code extension package
1515
*.vsix
16+
17+
# logs
18+
*.log

vscode-extension/README.md

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,89 @@ VS Code 必须带 `--enable-proposed-api maboloshi.github-chinese` 参数启动
2020
<details>
2121
<summary>带参数启动 VS Code 的方式</summary>
2222

23-
- 打开[运行对话框](https://learn.microsoft.com/windows/advanced-settings/modern-run),录入:
23+
- 打开[运行对话框](https://learn.microsoft.com/windows/advanced-settings/modern-run),输入:
24+
2425
```cmd
2526
"%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" --enable-proposed-api maboloshi.github-chinese
2627
```
28+
2729
- 或修改[“开始”菜单](https://www.microsoft.com/zh-cn/windows/tips/start-menu)的 VS Code 快捷方式,在 `目标` 字段末尾追加 [COMMAND_LINE_ARGUMENTS](https://learn.microsoft.com/openspecs/windows_protocols/ms-shllink/17b69472-0f34-4bcf-b290-eccdb8de224b)
30+
2831
```cmd
2932
--enable-proposed-api maboloshi.github-chinese
3033
```
34+
3135
然后从“开始”菜单启动
3236

3337
</details>
3438

39+
## 安装方式
40+
41+
### 方案一:从 GitHub Actions 下载(推荐)
42+
43+
> 该方案需要登录 GitHub 账号,若你没有账号,请使用 [方案二](#方案二从源码构建)
44+
45+
1. 打开本仓库的 [Actions](https://github.com/maboloshi/github-chinese/actions/workflows/build-vscode-extension.yml) 页面
46+
47+
2. 选择最近一次成功运行的 workflow
48+
49+
3. 滚动到页面底部,在 **Artifacts** 区域下载 `github-chinese-extension.vsix`
50+
51+
4. 在 VS Code 中按 `Ctrl+Shift+P` 打开命令面板
52+
53+
5. 输入 `Extensions: Install from VSIX...` 并选择刚才下载的 `.vsix` 文件
54+
55+
6. 安装完成后,在 VS Code 集成浏览器中刷新 GitHub 页面即可生效
56+
57+
### 方案二:从源码构建
58+
59+
#### 环境要求
60+
61+
- [Git](https://git-scm.cn/install) (可选,用于克隆仓库,若不打算安装 Git ,请自行将仓库下载至本地)
62+
63+
- [NodeJS](https://nodejs.org)
64+
65+
#### 构建步骤
66+
67+
在 PowerShell 中执行以下代码:
68+
69+
```shell
70+
git clone https://github.com/maboloshi/github-chinese.git # 克隆仓库
71+
72+
# 若你的网络环境无法访问 GitHub 克隆仓库,请自行寻找加速器等解决
73+
74+
cd github-chinese/vscode-extension # 进入插件目录
75+
76+
npm install # 安装依赖
77+
78+
# 若你的网络环境缓慢,请使用这行命令:
79+
80+
# npm install --registry=https://registry.npmmirror.com
81+
82+
npx @vscode/vsce package # 打包插件
83+
```
84+
85+
构建完成后,按方案一的第 4-5 步安装生成的 `.vsix` 文件。
86+
3587
> [!NOTE]
36-
> 本扩展尚未上架 [VS Code 市场](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_find-and-install-an-extension),需通过[源码构建](#从本仓库源码构建)或下载 VSIX 安装。
88+
> 本扩展尚未上架 [VS Code 市场](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_find-and-install-an-extension),需通过 [源码构建](#方案二从源码构建) 或从 [Actions](https://github.com/maboloshi/github-chinese/actions/workflows/build-vscode-extension) 下载 VSIX 安装。
3789
3890
## 命令
3991

4092
- `GitHub 中文化: 检查注入状态` — 查看 browser API 可用性、注入标签数与词库加载状态
4193
- `GitHub 中文化: 刷新集成浏览器注入` — 重新拉取词库/主脚本并重新注入所有已打开的集成浏览器标签
4294

43-
## 从本仓库源码构建
95+
## 常见问题
96+
97+
### 为什么打开 GitHub 页面没有汉化?
4498

45-
1. [克隆仓库](https://docs.github.com/zh/repositories/creating-and-managing-repositories/cloning-a-repository)
46-
1. [在 VS Code 中打开该文件夹](https://code.visualstudio.com/docs/editor/workspaces#_folder-projects)
47-
1. [打开终端](https://code.visualstudio.com/docs/terminal/getting-started#_run-your-first-command-in-the-terminal),执行:
48-
```powershell
49-
cd vscode-extension
50-
npm install
51-
npx @vscode/vsce package
52-
```
53-
1. [从 VSIX 安装](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace#_install-from-a-vsix)
99+
请检查以下几点:
54100

55-
> [!TIP]
56-
> 推荐从[发行版](https://github.com/maboloshi/github-chinese/releases)直接下载 `.vsix`(如有)。
101+
1. **确认已安装依赖扩展**:Integrated Browser Extensions 必须已安装并启用
102+
2. **确认启动参数正确**:VS Code 必须带 `--enable-proposed-api boylett.integrated-browser-extensions` 参数启动
103+
3. **确认扩展已启用**:在扩展面板中确认 `GitHub 中文化` 扩展已启用
104+
4. **刷新页面**:在 VS Code 的集成浏览器中按 `Ctrl+R``F5` 刷新页面
105+
5. **重启 VS Code**:尝试完全退出并重新启动 VS Code
57106

58107
## 调试
59108

0 commit comments

Comments
 (0)