generate-custom-instructions-from-codebase 是做什麼的?
遷移與程式碼演化指令產生器,專為 GitHub Copilot 設計。分析兩個專案版本(分支、提交或發行版)之間的差異,建立精確指令,讓 Copilot 在技術遷移、重大重構或框架版本升級時保持一致性。
功能
- 分析兩個 Git 參考(分支、標籤、提交 SHA)之間的差異
- 自動產生
.github/copilot-instructions.md檔案 - 支援對已存在的指令檔案進行增量更新
- 可透過 GitHub CLI 在本地執行,或做為 GitHub Actions 中的自動化步驟
- 使用
git diff與 LLM(預設使用 Anthropic Claude)分析變更模式
使用方法
使用 GitHub CLI(本地)
# 分析目前分支與 main 分支的差異
github/generate-custom-instructions-from-codebase --base main --head HEAD
# 指定特定的參考版本
github/generate-custom-instructions-from-codebase --base v1.0.0 --head v2.0.0
# 將產生的指令寫入自訂檔案路徑
github/generate-custom-instructions-from-codebase --base main --head feature-branch --output .github/copilot-instructions.md
使用 GitHub Actions
建立一個工作流程檔案 .github/workflows/generate-instructions.yml:
name: 產生 Copilot 指令
on:
pull_request:
types: [closed]
branches:
- main
jobs:
generate:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 產生遷移指令
uses: github/generate-custom-instructions-from-codebase@v1
with:
base: ${{ github.event.pull_request.base.sha }}
head: ${{ github.event.pull_request.head.sha }}
- name: 提交指令
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add .github/copilot-instructions.md
git commit -m "更新 Copilot 遷移指令"
git push
輸出
此技能會產生一個 .github/copilot-instructions.md 檔案,包含:
- 規則:Copilot 應遵循的明確程式碼模式與慣例
- 偏好:特定 API 使用方式、命名慣例或架構決策
- 範例:展示變更前與變更後程式碼的程式碼片段
- 背景脈絡:遷移或重構作業的描述
支援的平台
- GitHub Copilot(主要目標)
- GitHub CLI(本地執行)
- GitHub Actions(自動化 CI/CD)
- Cline / Roo Code(透過
.clinerules輸出格式)
環境變數
| 變數 | 描述 | 必要 |
|---|---|---|
GITHUB_TOKEN | 用於存取儲存庫的 GitHub 令牌 | 是 |
ANTHROPIC_API_KEY | 用於 Claude 分析的 API 金鑰 | 使用 Anthropic 時為必要 |
授權條款
MIT