Skip to content

Commit 854a4a9

Browse files
authored
feat(MOC-52): Code Graph 自动生成器 + GitHub Pages Actions 部署 (#298)
* feat(MOC-52): code graph 自动生成器 + GitHub Pages Actions 部署 tools/code-graph/gen.py:从 `cargo metadata` 自动推导 workspace crate 节点 + 内部依赖边(ground truth + 每 crate .rs 文件数),渲染自包含交互式 index.html —— D3 force graph,深空仪表盘视觉(渐变 mesh 背景 + 发光球体节点 + 玻璃拟态 面板 + Syne / JetBrains Mono 字体)。点节点高亮邻居 + 看 path/version/files/deps, 支持 zoom/drag。 .github/workflows/code-graph.yml:push main(任意 Cargo.toml / 生成器 / workflow 本身)+ workflow_dispatch → 生成 → configure-pages(自动把 Pages Source 切到 GitHub Actions)→ deploy-pages。产物不提交任何分支:main 纯源码、无 bot commit、 无 force-push、gh-pages 分支随之作废。 替换 Codex 之前手工硬编码且 diff 标记损坏的 gh-pages 快照(289/395 行带 `+` 前缀 → `<script>` 从 `+const` 开始 = JS 语法错误,交互全失效)。生成器输出经 本地 + Playwright 浏览器实测(9 crates / 15 edges 准确、交互正常、self-contained)。 Refs #297 * feat(MOC-52): 并入下载量趋势图 — Pages 站点同时出 code graph + 下载图 download-stats 折叠进站点 workflow(用户定:不另开分支、不碰 main): - tools/download-stats/gen_chart.py:读回 Pages 上已发布的 downloads.json 历史 + 今日 release 总下载数 → upsert 今日点 → 写合并 json + 渲染自包含深色 SVG 折线图。 GitHub 不暴露下载历史,故每日快照累积;数据存 Pages 部署本身(每次 run 从 live URL 读回 append),无需额外分支、无需 commit main。 - code-graph.yml → name "Project Site":加每日 cron + download-stats step (curl 读回 downloads.json → gh api 求 release 总下载 → gen_chart.py → _site/{downloads.json,downloads.svg} 连同 index.html 一起 deploy)。 配合 #297 README 底部嵌入 downloads.svg + star-history 双图。 Refs #297 * fix(MOC-52): review 修复 — 单遍 token 替换 + 显式切 Pages 到 Actions - code-graph/gen.py:多遍 str.replace 改单遍 regex sub。否则若某 crate 描述/名/ 路径含 __TOKEN__ 字面量,会被后续 pass 覆盖污染 JSON(Devin review BUG) - code-graph.yml:deploy 前显式 `gh api PUT pages build_type=workflow`(idempotent)。 configure-pages 不会把已存在的 legacy(gh-pages 分支)Pages 切到 Actions,首次 deploy 否则无法替换旧的损坏快照(chatgpt-codex-connector P1) * fix(MOC-52): 下载数据 fetch 失败只在 404 重置,其他错误 abort 保历史 chatgpt-codex-connector P2:`curl ... || echo '[]'` 把任何 fetch 失败(网络超时 / 5xx / TLS)都当 404,会用单点序列覆盖部署 → 永久截断下载历史(历史只存在已部署的 downloads.json)。改为按 HTTP 状态码区分:200 用 body、404(首跑/未发布)才从 [] 起、其他状态 exit 1 不部署,保住上次的历史。 * fix(MOC-52): README 图表按反馈调整 + 下载 fetch 失败不截断历史 按用户反馈: - Code Graph 从「能做什么」功能列表移到顶部导航(简体中文 / English / Changelog / Code Graph),纯文字链接 —— 它是 README 展示入口而非项目功能 - 删掉下载图图注的「(每日自动刷新)」—— 刷新机制不该写进图注 - star + 下载图统一白底(star 去 theme=dark、下载 SVG 改浅色主题)—— 嵌入图与 点击跳转的 star-history 页(白底)一致,消除黑底/白底不一致的困惑 chatgpt-codex-connector P2:download-stats step 加 `set -eo pipefail` + 拆开 gh api 与 awk —— 否则 gh api 失败时 awk 仍输出 0,会发布今日=0 覆盖持久化历史。 * fix(MOC-52): 下载历史 prev.json 解析失败/非 list 时 fail,不静默重置 chatgpt-codex-connector P2:load_series 对 malformed 200 body(坏的旧部署 / 手动 误改 / 200 返 HTML 错误页)静默返 [] 会用单点序列覆盖唯一持久化历史。改为 raise (被 set -e fail job,保住历史);workflow 首跑写的合法 "[]" 仍正常解析为空序列。
1 parent 33d9940 commit 854a4a9

6 files changed

Lines changed: 680 additions & 8 deletions

File tree

.github/workflows/code-graph.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Project Site
2+
3+
# Builds the project's GitHub Pages site and publishes it via GitHub Actions
4+
# (no gh-pages branch, no commits to main):
5+
# - index.html interactive crate dependency graph, from `cargo metadata`
6+
# - downloads.json cumulative release-download time series (read back from the
7+
# live site each run and appended — GitHub exposes no history)
8+
# - downloads.svg rendered download-trend chart embedded in the README
9+
#
10+
# Runs when the dependency structure / generators change, daily (to add a download
11+
# data point), and on demand.
12+
on:
13+
push:
14+
branches: [main]
15+
paths:
16+
- 'Cargo.toml'
17+
- '**/Cargo.toml'
18+
- 'tools/code-graph/**'
19+
- 'tools/download-stats/**'
20+
- '.github/workflows/code-graph.yml'
21+
schedule:
22+
- cron: '17 3 * * *' # daily — refresh the download-count series
23+
workflow_dispatch:
24+
25+
permissions:
26+
contents: read
27+
pages: write
28+
id-token: write
29+
30+
# Never cancel an in-flight Pages deploy; let queued runs finish in order.
31+
concurrency:
32+
group: pages
33+
cancel-in-progress: false
34+
35+
jobs:
36+
build:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Install Rust (for cargo metadata)
41+
uses: dtolnay/rust-toolchain@stable
42+
- uses: actions/setup-python@v5
43+
with:
44+
python-version: '3.12'
45+
- name: Generate code graph
46+
run: python3 tools/code-graph/gen.py --out _site/index.html
47+
- name: Update download-count series + chart
48+
env:
49+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
run: |
51+
set -eo pipefail
52+
# read back the previously-published series. The history lives only in the
53+
# deployed JSON, so ONLY a confirmed 404 (first run / not yet published) may
54+
# start from []; any other failure (network, 5xx, TLS) aborts the job so a
55+
# transient blip can't permanently truncate the chart.
56+
status=$(curl -sS -o prev.json -w '%{http_code}' https://cmochance.github.io/codex-app-transfer/downloads.json || echo 000)
57+
if [ "$status" = 404 ]; then echo '[]' > prev.json;
58+
elif [ "$status" != 200 ]; then echo "::error::fetch downloads.json failed (HTTP $status); aborting to preserve history"; exit 1; fi
59+
# current cumulative downloads. Fetch first so a failed gh api (network/auth/
60+
# pagination) aborts the job via set -e instead of silently summing to 0 and
61+
# truncating the persisted history; then aggregate.
62+
counts=$(gh api "repos/${GITHUB_REPOSITORY}/releases" --paginate --jq '.[].assets[].download_count')
63+
total=$(printf '%s\n' "$counts" | awk '{s+=$1} END {print s+0}')
64+
python3 tools/download-stats/gen_chart.py --prev prev.json --add "$total" \
65+
--out-json _site/downloads.json --out-svg _site/downloads.svg
66+
# The repo's Pages was previously a branch deploy (gh-pages). configure-pages
67+
# alone does NOT switch an already-enabled site to Actions, so flip build_type
68+
# explicitly before deploying (idempotent) — otherwise the first deploy can't
69+
# replace the old gh-pages content. Makes the gh-pages branch obsolete.
70+
- name: Switch Pages source to GitHub Actions
71+
env:
72+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
run: |
74+
gh api --method PUT "repos/${GITHUB_REPOSITORY}/pages" -f build_type=workflow \
75+
|| gh api --method POST "repos/${GITHUB_REPOSITORY}/pages" -f build_type=workflow
76+
- uses: actions/configure-pages@v5
77+
- uses: actions/upload-pages-artifact@v3
78+
with:
79+
path: _site
80+
81+
deploy:
82+
needs: build
83+
runs-on: ubuntu-latest
84+
environment:
85+
name: github-pages
86+
url: ${{ steps.deployment.outputs.page_url }}
87+
steps:
88+
- name: Deploy to GitHub Pages
89+
id: deployment
90+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,7 @@ src-tauri/icons/ios/
9797

9898
# Codex Desktop theme 本地素材(用户私人壁纸 / 版权资源, 不入仓)
9999
img/codex-theme/
100+
101+
# Code graph: generated site output + local preview/test artifacts
102+
_site/
103+
.playwright-mcp/

README.en.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<p align="center">
1313
<a href="README.md">简体中文</a> |
1414
<a href="README.en.md">English</a> |
15-
<a href="CHANGELOG.md">Changelog</a>
15+
<a href="CHANGELOG.md">Changelog</a> |
16+
<a href="https://cmochance.github.io/codex-app-transfer/">Code Graph</a>
1617
</p>
1718

1819
<p align="center">
@@ -75,7 +76,6 @@ A sixth theme (Carton) carries a floating mascot in the bottom-right that reacts
7576
- **Codex Desktop Theme (optional, off by default)**: Theme page ships 5 built-in anime themes (`carton` with a floating mascot + `changli` / `azurlane` / `nailin` / `zani` background-only), injects CSS token overrides + background image into Codex Desktop via CDP. Toggle is independent from Plugin Unlock; page reload re-applies automatically
7677
- Cross-platform single-instance lock (double-click brings the existing window forward) + cross-process file lock prevents multi-instance config-write lost-updates
7778
- Windows / macOS / Linux system tray
78-
- **Code Graph**: [View code dependency graph online](https://cmochance.github.io/codex-app-transfer/)
7979

8080
## Download
8181

@@ -302,10 +302,10 @@ MIT License. Full text at [LICENSE.txt](LICENSE.txt).
302302
<tr>
303303
<td width="50%" align="center">
304304
<a href="https://github.com/Cmochance/codex-app-transfer/releases"><img src="https://cmochance.github.io/codex-app-transfer/downloads.svg" alt="Download trend" width="100%"></a>
305-
<br/><sub>Download trend (refreshed daily)</sub>
305+
<br/><sub>Download trend</sub>
306306
</td>
307307
<td width="50%" align="center">
308-
<a href="https://star-history.com/#Cmochance/codex-app-transfer&Date"><img src="https://api.star-history.com/svg?repos=Cmochance/codex-app-transfer&type=Date&theme=dark" alt="Star history" width="100%"></a>
308+
<a href="https://star-history.com/#Cmochance/codex-app-transfer&Date"><img src="https://api.star-history.com/svg?repos=Cmochance/codex-app-transfer&type=Date" alt="Star history" width="100%"></a>
309309
<br/><sub>Star history</sub>
310310
</td>
311311
</tr>

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<p align="center">
1313
<a href="README.md">简体中文</a> |
1414
<a href="README.en.md">English</a> |
15-
<a href="CHANGELOG.md">Changelog</a>
15+
<a href="CHANGELOG.md">Changelog</a> |
16+
<a href="https://cmochance.github.io/codex-app-transfer/">Code Graph</a>
1617
</p>
1718

1819
<p align="center">
@@ -75,7 +76,6 @@ Codex App Transfer 是一个面向 **OpenAI Codex APP** 的轻量桌面配置 +
7576
- **Codex Desktop 主题(可选,默认关)**:Theme 页内置 5 套动漫主题(`carton` 含浮动看板娘 + `changli` / `azurlane` / `nailin` / `zani` 单背景),通过 CDP 向 Codex Desktop 注入 CSS token 覆盖 + 背景图。开关跟 Plugin Unlock 独立,page reload 自动重应用
7677
- 跨平台单实例锁定(双击启动自动唤起已有窗口)+ 跨进程 file lock 防多实例同时写 config 丢更新
7778
- Windows / macOS / Linux 系统托盘
78-
- **Code Graph**: [在线查看代码依赖图](https://cmochance.github.io/codex-app-transfer/)
7979

8080
## 下载
8181

@@ -301,10 +301,10 @@ MIT License。完整文本见 [LICENSE.txt](LICENSE.txt)。
301301
<tr>
302302
<td width="50%" align="center">
303303
<a href="https://github.com/Cmochance/codex-app-transfer/releases"><img src="https://cmochance.github.io/codex-app-transfer/downloads.svg" alt="下载量趋势" width="100%"></a>
304-
<br/><sub>下载量趋势(每日自动刷新)</sub>
304+
<br/><sub>下载量趋势</sub>
305305
</td>
306306
<td width="50%" align="center">
307-
<a href="https://star-history.com/#Cmochance/codex-app-transfer&Date"><img src="https://api.star-history.com/svg?repos=Cmochance/codex-app-transfer&type=Date&theme=dark" alt="Star 趋势" width="100%"></a>
307+
<a href="https://star-history.com/#Cmochance/codex-app-transfer&Date"><img src="https://api.star-history.com/svg?repos=Cmochance/codex-app-transfer&type=Date" alt="Star 趋势" width="100%"></a>
308308
<br/><sub>Star 趋势</sub>
309309
</td>
310310
</tr>

0 commit comments

Comments
 (0)