Skip to content

Commit e10afb2

Browse files
committed
feat: 支持多github token
1 parent 476fd63 commit e10afb2

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
如果你的 workflow_dispatch 输入名不是 `issue_number`,或者你在其他事件里调用这个 action,就显式传 `issue-number`
4545

4646
- `github-token`: 用于创建和更新 Issue 评论
47-
- `copilot-github-token`: Copilot CLI 使用的 Fine-grained token
47+
- `copilot-github-token`: Copilot CLI 使用的 Fine-grained token,支持传多个 token,每行一个,action 会随机选择一个使用
4848
- `bot-name`: 从 `issue_comment` 正文中剥离掉的 bot mention,比如 `@YourBot`
4949
- `initial-comment-body`: 开始分析时先发出的评论正文
5050
- `action-link-text`: 评论里展示的运行链接文字
@@ -98,4 +98,5 @@
9898
- `copilot-output` 会包含 Copilot 启动前的参数打印和 prompt 正文,不再只是 Copilot 进程本身的 stdout/stderr
9999
- 会上传 Copilot 原始输出和最终结论两个 artifacts
100100
- 最终评论会包含最终结论、完整分析过程折叠块,以及当前 Actions 运行链接
101+
- `copilot-github-token` 兼容单个 token,也兼容多个 token 按行填写;传多个时每次运行会随机选一个
101102

action.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ inputs:
1111
description: GitHub token used to create and update issue comments.
1212
required: true
1313
copilot-github-token:
14-
description: Fine-grained GitHub token with Copilot access for the Copilot CLI.
14+
description: Fine-grained GitHub token with Copilot access for the Copilot CLI. Supports multiple tokens, one per line, and randomly picks one.
1515
required: true
1616
bot-name:
1717
description: Bot mention to strip from issue_comment messages before appending extra requirements.
@@ -223,10 +223,33 @@ runs:
223223
shell: bash
224224
run: npm install -g "${{ inputs.copilot-package }}"
225225

226+
- name: Resolve Copilot token
227+
id: resolve_copilot_token
228+
shell: bash
229+
env:
230+
INPUT_COPILOT_GITHUB_TOKEN: ${{ inputs.copilot-github-token }}
231+
run: |
232+
python <<'PY'
233+
import os
234+
import secrets
235+
236+
raw_value = os.environ["INPUT_COPILOT_GITHUB_TOKEN"]
237+
tokens = [line.strip() for line in raw_value.splitlines() if line.strip()]
238+
239+
if not tokens:
240+
raise SystemExit("Input copilot-github-token is empty after trimming blank lines.")
241+
242+
selected_token = secrets.choice(tokens)
243+
244+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fh:
245+
fh.write(f"copilot_token={selected_token}\n")
246+
fh.write(f"copilot_token_count={len(tokens)}\n")
247+
PY
248+
226249
- name: Run Copilot analysis with streaming updates
227250
shell: bash
228251
env:
229-
COPILOT_GITHUB_TOKEN: ${{ inputs.copilot-github-token }}
252+
COPILOT_GITHUB_TOKEN: ${{ steps.resolve_copilot_token.outputs.copilot_token }}
230253
GITHUB_TOKEN: ${{ inputs.github-token }}
231254
GITHUB_SERVER_URL: ${{ github.server_url }}
232255
COMMENT_ID: ${{ steps.initial_comment.outputs.comment-id }}
@@ -256,6 +279,7 @@ runs:
256279
echo " comment-url: $COMMENT_URL"
257280
echo " model: $COPILOT_MODEL"
258281
echo " reasoning-effort: $COPILOT_REASONING_EFFORT"
282+
echo " copilot-token-count: ${{ steps.resolve_copilot_token.outputs.copilot_token_count }}"
259283
echo " stream-update-interval-seconds: $STREAM_UPDATE_INTERVAL"
260284
echo " analysis-prompt-file: $ANALYSIS_PROMPT_FILE"
261285
echo " output-file: $OUTPUT_FILE"

0 commit comments

Comments
 (0)