TechSummary 2025-08-04
· 閱讀時間約 22 分鐘
使用 GitHub Models 在 Actions 中自動化您的專案 🚀
Source: https://github.blog/ai-and-ml/generative-ai/automate-your-project-with-github-models-in-actions/
- GitHub Models 將 AI 整合到 GitHub Actions 工作流程中,實現專案內的自動化分類、摘要等功能。
- 權限設置: 使用 GitHub Models 前需在
permissions
區塊中加入models: read
,並建議遵循最小權限原則,以降低提示詞注入攻擊 (prompt injection) 風險。permissions:
contents: read
issues: write
models: read - 範例一:在 Bug 報告中請求更多資訊
- 透過
actions/ai-inference@v1
動作分析 Issue 內容,判斷錯誤報告是否包含足夠的重現資訊(例如:重現步驟、預期行為、實際行為、環境細節)。 - 若資訊不足,AI 會自動回覆提示作者補齊。此機制利用 AI 模型的回傳值(
pass
或詳細說明)建立工作流程中的條件邏輯。
- name: Analyze Issue For Reproduction
if: contains(join(github.event.issue.labels.*.name, ','), 'bug')
id: analyze-issue
uses: actions/ai-inference@v1
with:
model: mistral-ai/ministral-3b
system-prompt: |
Given a bug report title and text for an application, return 'pass' if there is enough information to reliably reproduce the issue, meaning the report clearly describes the steps to reproduce the problem, specifies the expected and actual behavior, and includes environment details such as browser and operating system; if any of these elements are missing or unclear, return a brief description of what is missing in a friendly response to the author instead of 'pass'. Consider the following title and body:
prompt: |
Title: ${{ steps.issue.outputs.title }}
Body: ${{ steps.issue.outputs.body }} - 透過
- 範例二:從合併的 Pull Request 建立發布說明
- 透過
gh CLI
搭配gh-models
擴充功能,在 Pull Request 合併時自動摘要其標題、內容、評論及審閱,並將摘要內容追加到指定的發布說明 Issue 中。
cat pr.json | gh models run xai/grok-3-mini \
"Given the following pull request information, generate a single, clear, and concise one-line changelog entry that summarizes the main change (feature, fix, or bug) introduced by this PR. Use neutral, user-facing language and avoid technical jargon or internal references. Only write the line, with no additional introduction or explanation text." > summary.md - 透過
- 範例三:摘要並優先處理 Issue
- 設定定期排程工作流程 (例如每週一早上 9 點),使用
gh CLI
抓取過去一週新開啟的 Issue,並將其傳遞給 AI 模型進行摘要、歸納主題及優先級排序,最終創建一個新的 Issue 來呈現週報摘要。 - 此範例使用獨立的
.prompt.yml
提示文件,提供更複雜的提示邏輯。
- 設定定期排程工作流程 (例如每週一早上 9 點),使用