在 GitHub 智能体工作流中集成 SafeDep MCP

目录

概述

GitHub Agentic Workflow 是 GitHub 的全新功能。它本质上是 GitHub Actions,但用户用英文在 .md 文件中编写工作流,而不是在 .yml 中的 steps(步骤)。

下面是一个 GitHub Agentic Workflow 的简单示例:

md
--- # metadata, IO, AI settings --- # Daily Repo Status Create an upbeat daily status report for the repo as a GitHub issue. ## What to include - Recent repository activity (issues, PRs, discussions, releases, code changes) - Progress tracking, goal reminders and highlights - Project status and recommendations - Actionable next steps for maintainers ## Style - Be positive, encouraging, and helpful 🌟 - Use emojis moderately for engagement - Keep it concise - adjust length based on actual activity

它在 CI 中使用 AI 代理来执行此提示,并为其提供关于 repositoryissuespull requestsdiscussions 等的上下文信息。它可以像现有的 GitHub Actions 一样被触发,例如 on: pull_requeston: issues_createon: daily 等。

创建新的 Agentic Workflow

使用 Agentic Workflows 时,​**GitHub CLI 是必需的**。如果尚未安装,请立即安装。

按照 Agentic Workflows快速入门文档来创建您的第一个 agentic workflow。

bash
# install gh-aw extension gh extension install github/gh-aw

创建新的 agentic workflow:

bash
# at root of your project gh aw add-wizard githubnext/agentics/daily-repo-status

这将在 GitHub secrets 中设置 Agent Provider 和 API Keys。

从高层次来看,流程如下:

  • .github/workflows/new-agent-workflow.md 中创建一个 .md 文件
  • 编写您的 agentic workflow,然后编译它
    bash
    gh aw compile
    这将创建一个 .lock.yml 文件,它是由 gh aw CLI 从我们的 .md 文件生成的实际 GitHub Actions 文件。
  • 提交并推送!

使用 SafeDep MCP

Agentic Workflows 支持 MCP,它有助于集成任何 MCP 服务器,然后这些服务器可以被在 CI 中运行的代理使用。

我们将集成 SafeDep MCP 服务器,让它在每个 Pull Request 上运行,并检查任何引入或更新的依赖项的安全状况。

创建一个新的 .github/workflows/safedep-check-on-pr.md 文件。

bash
touch .github/workflows/safedep-check-on-pr.md

将此内容粘贴到该文件中:

md
--- on: pull_request permissions: contents: read pull-requests: read safe-outputs: add-comment: target: 'triggering' # Ensures the comment is posted on the PR that started the workflow mcp-servers: safedep: url: 'https://mcp.safedep.io/model-context-protocol/threats/v1/mcp' headers: Authorization: '${{ secrets.SAFEDEP_API_KEY }}' X-Tenant-ID: '${{ secrets.SAFEDEP_TENANT_ID }}' allowed: ['*'] --- # SafeDep Security Check Your task is to use SafeDep security checks to determine if the OSS packages introduced or updated in the Pull Request are safe to merge.

注意:​ 我们在这里使用了 secrets,您必须将 SAFEDEP_API_KEYSAFEDEP_TENANT_ID 添加到您的仓库 secrets 中。请参阅 SafeDep MCP 文档获取如何获取这些值的指南。运行以下命令编译 agentic workflow 文件:

bash
# from root of your project gh aw compile

这将创建一个新的 .yml GitHub Actions 文件。

提交并推送!

此 workflow 将在每个 pull request 上执行,并会在其上发布一条总结评论。

GH AW Demo on GitHub PR

结论

在 GitHub Agentic Workflow 中使用 SafeDep MCP 是将 AI SDLC 安全集成到您的 CI/CD 中的强大方式,我们只是触及了皮毛,我们还可以创建一个 workflow 来运行 dailyweekly,从而生成一份关于所有 OSS 包安全状况的汇总报告。可能性是无限的。

  • GitHub Agentic Workflow
  • SafeDep MCP
  • AI

SafeDep 博客的最新内容

关注以获取有关开源安全与工程的最新更新和见解