探索主題

Agent: 探索者 (explorer)
Confidence: 73%
Cost: $0.3398
Duration: 1m 25s
Task ID: 4a281aa8-c163-4271-ae6d-535534cac404


Good. I now have everything I need. Let me compile the exploration report.

探索主題

探索 — GitHub Actions 自動測試與部署 Telegram Bot

發現

  • 專案已有 CI Phase 1.github/workflows/ci.yml 已在 push/PR 時跑 typecheck + vitest,但沒有部署 bot 本體的 CD workflow。Blog 和 report site 已有完整 CI/CD(build + Cloudflare Pages deploy)。

  • Bot 跑在 WSL2 self-hosted runner 上:專案用 restart.ts wrapper(exit code 42 = 自動重啟),不是 Docker 也不是 PM2。部署 = SSH 進 WSL → git pull → 重啟 process。這決定了 CD 策略應走 self-hosted runner 而非 cloud runner。

  • 主流做法有三種:(1) Docker build → push → SSH pull + restart(最常見);(2) appleboy/ssh-action 直接 SSH 到主機執行指令(最簡單);(3) Self-hosted runner 直接在目標機上跑 workflow(零網路延遲,最適合 WSL2 場景)。

  • 最適合本專案的方案是 Self-hosted runner:因為 bot 已經跑在 WSL2 上、有 self-hosted runner 設定、不需要 Docker。CD workflow 只需:npm ci → npm run build → 發送 restart 信號(kill + exit code 42 觸發自動重啟)

  • 具體 workflow 範例(Phase 2 CD):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
name: Deploy Bot
on:
push:
branches: [main]
paths: ['src/**', 'plugins/**', 'package*.json']
jobs:
deploy:
runs-on: self-hosted # WSL2 上的 runner
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run typecheck
- run: npm test
- run: npm run build
- run: |
# 找到 restart.ts 主程序的 PID 並發 SIGUSR2 或直接 kill
# restart.ts 收到信號後以 exit code 42 退出,wrapper 自動重啟
pkill -f "restart.ts" || true

有趣的連結

  • 本專案的 restart.ts 用 exit code 42 做 hot-reload,這和 PM2 的 restart 語意類似但更輕量。如果搭配 systemd service unit,可以讓 bot 在 WSL 重啟後也自動恢復。

延伸問題

  • 如何為 self-hosted runner 設定 systemd service,使 WSL2 重啟後 runner 自動上線?
  • 是否需要在 CD 中加入 integration test(用 Telegram Bot API test mode 或 mock)?

重要性:4/5

直接改善專案品質和部署效率。CI 已有,CD 是自然的下一步,且實作成本低(~30 行 YAML)。

—HANDOFF—
TO: blog-writer
INTENT: handoff
ARTIFACT_TYPE: report
SUMMARY: GitHub Actions CI/CD 自動部署 Telegram Bot 探索報告,含具體 workflow 範例,可作為部落格文章素材