GitHub 모델을 사용하여 프로젝트를 자동화하십시오

GitHub 모델을 사용하여 프로젝트를 자동화하십시오

GitHub 모델은 AI를 GitHub Action Workflows에 가져 와서 프로젝트가 살고있는 곳을 자동화하고 요약하는 등을 지원합니다.

GitHub Action Workflows에서 GitHub 모델의 사용을 통합하고 자동화하는 세 가지 방법을 살펴 보겠습니다.

https://www.youtube.com/watch?v=m293_esos7i

그러나 먼저 : 올바른 권한을 추가하십시오

작업 워크 플로에서 GitHub 모델을 사용하기 전에 워크 플로우에 AI 모델에 대한 액세스 권한을 부여해야합니다. 올바른 권한이 없으면 AI 모델을 호출하려는 단계는 실패합니다.

GitHub 모델 사용에 대한 권한 제공은 권한 블록의 한 줄입니다.

permissions:
  contents: read
  issues: write
  models: read

이 권한은 워크 플로에 리포지토리 컨텐츠를 읽을 수있는 기능을 제공합니다. 문제 및 댓글을 읽고 만들거나 업데이트하는 것; 그리고 가장 중요한 것은이 튜토리얼의 경우 GitHub 모델에 액세스 할 수 있습니다.

예제 : 버그 보고서에 더 많은 정보를 요청하십시오

이 예는 AI 추론 동작 사용 방법과 AI를 사용하여 분기 로직을 만드는 방법을 보여줍니다. 당신은 전체를 찾을 수 있습니다 워크 플로 이 저장소에서.

개발자로서 우리의 작업에서 가장 시간이 많이 걸리고 정신적 인 부분 중 하나는 재생산하기에 너무 적은 정보가 포함 된 새로운 문제를 증진시키는 것입니다.

이러한 문제를 평가하고 응답하는 데 시간을 소비하는 대신 AI 추론 조치를 사용하면 주요 AI 모델을 호출하여 워크 플로의 일부로 텍스트를 분석하거나 생성 할 수 있습니다. 예를 들어 아래의 워크 플로우는 새 버그 보고서에 실행 가능성이 충분한 지 확인하고 그렇지 않은 경우 응답합니다.

워크 플로를 설정하려면 저장소에서 새 파일을 만듭니다. .github/workflows 디렉토리 호출 bug-reproduction-instructions.yml (디렉토리가 존재하지 않으면 디렉토리를 만듭니다). 새로운 문제가 열릴 때마다 트리거 된 다음 향후 단계를 위해 문제의 제목과 본문을 가져옵니다.

name: Bug Report Reproduction Check

on:
  issues:
    types: [opened]

permissions:
  contents: read
  issues: write
  models: read

jobs:
  reproduction-steps-check:
    runs-on: ubuntu-latest
    steps:
      - name: Fetch Issue
        id: issue
        uses: actions/github-script@v7
        with:
          script: |
            const issue = await github.rest.issues.get({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number
            })
            core.setOutput('title', issue.data.title)
            core.setOutput('body', issue.data.body)

워크 플로에 필요한 컨텍스트가 있으므로 새 단계를 만드십시오. 이 단계는 문제에 버그 레이블이 태그 된 경우에만 실행해야합니다. 이 단계는 AI 추론 조치를 사용하며 효과적인 재생 지침의 특성을 간략하게 설명하고 문제로부터 값을 제공하는 시스템 프롬프트로 구성됩니다.

- 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 }}

이 단계는 a를 반환합니다 pass 충분한 정보가 제공되는 경우 (순간 에이 작업을 수행하는 이유에 대한 자세한 내용), 누락 된 내용을 자세히 설명하는 응답을 반환하십시오.

GitHub 모델 카탈로그에서 사용 가능한 40 개 이상의 AI 모델을 사용할 수 있습니다. 모델 값을 각 모델의 페이지에서 식별자로 교체하십시오.

다음으로, 마지막 단계를 추가하면 반환 된 값이 그렇지 않은 경우에만 주석을 게시합니다. pass.

- name: Comment On Issue
  if: contains(join(github.event.issue.labels.*.name, ','), 'bug') && steps.analyze-issue.outputs.response != 'pass'
  uses: actions/github-script@v7
  env:
    AI_RESPONSE: steps.analyze-issue.outputs.response
    with:
      script: |
        await github.rest.issues.createComment({
          owner: context.repo.owner,
          repo: context.repo.repo,
          issue_number: context.issue.number,
          body: process.env.AI_RESPONSE
        })

특정 기준이 충족되면 AI 모델에 고정 문자열을 반환하도록 촉구함으로써 (이 경우에는 충분한 재생산 정보가있는 좋은 버그 보고서가 제출되었습니다) 워크 플로우에 AI 구동 조건부 논리를 만들 수 있습니다.

Github에 대한 문제 "Firefox에서 작동하지 않습니다" 설명이없고 버그 레이블이 있습니다. GitHub -Actions Bot은 더 많은 정보, 특히 재생산 단계, 예상 및 실제 행동, 브라우저 및 운영 체제 세부 사항을 요청합니다.

예 2 : 병합 된 풀 요청에서 릴리스 노트 생성

이 예제는 GH Cli를 다음과 함께 사용하는 방법을 보여줍니다. GH- 모델 확대. 당신은 전체를 찾을 수 있습니다 워크 플로 이 저장소에서.

새로운 버전의 프로젝트로 철저한 릴리스 노트를 생성하는 데 시간이 걸리고 변경 사항을 수집하는 것과 사용자에게 설명하는 간결한 방법을 찾는 것 사이에 시간이 걸릴 수 있습니다.

그러나 당기 요청이 병합 될 때 실제로 GitHub 작업 워크 플로우 단계를 트리거하고 GitHub CLI를 사용하여 정보를 수집하고 호출 모델을 포함하여 조치를 취할 수 있습니다. 예를 들어 아래의 워크 플로는 병합 된 풀 요청을 요약하고 릴리스 노트 문제에 추가하여 각 풀 요청에 따라 시간과 에너지를 절약 할 수있는 방법을 보여줍니다.

이 워크 플로를 설정하려면 release이 레이블로 불리는 하나의 문제를 만듭니다 Publish next release changelog. 그런 다음 저장소에 새 파일을 만듭니다 .github/workflows 디렉토리 호출 release-notes.yml. 새 풀 요청이 닫힐 때마다 트리거되며 병합 된 상태가 사실 인 경우에만 단일 작업이 실행됩니다.

name: Add to Changelog

on:
  pull_request:
    types:
      - closed

permissions:
  pull-requests: read
  issues: write
  contents: read
  models: read

jobs:
  add_to_changelog:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

설치 gh-models 새로운 단계를 갖춘 확장, 이제 GitHub 모델을 사용하는 권한이있는 워크 플로 토큰을 제공합니다.

- name: Install gh-models extension
  run: gh extension install 
  env:
    GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

나머지 단계는 한 단계로 발생합니다.

- name: Summarize pull request and append to release issue
  env:
    GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |-
    PR_NUMBER="${{ github.event.pull_request.number }}"

    # Fetch PR and save to a file
    gh pr view "$PR_NUMBER" --json title,body,comments,reviews > pr.json
    
    # Generate a summary using the model by reading from file
    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

    # Fetch release issue number
    RELEASE_ISSUE=$(gh issue list --label release --limit 1 --json number --jq '.[0].number')

    # Fetch current release issue body
    RELEASE_ISSUE_BODY=$(gh issue view "$RELEASE_ISSUE" --json body --jq '.body')

    # Append summary to release issue body
    FORMATTED_LINE="- $(cat summary.md) (#$PR_NUMBER)"
    NEW_BODY="${RELEASE_ISSUE_BODY}"$'\n'"$FORMATTED_LINE"

    # Update the release issue with the new body
    gh issue edit "$RELEASE_ISSUE" --body "$NEW_BODY"

풀 요청의 제목, 신체, 의견 및 리뷰는 다음을 사용하여 모델로 가져 와서 전달됩니다. gh models run 명령. 릴리스 문제는 요약 된 라인으로 가져 와서 업데이트됩니다.

다음 릴리스 ChangeLog를 게시하는 풀 요청. 설명에는 2 개의 총알 목록 항목이 있습니다. 각 항목은 병합 된 풀 요청에 대한 링크가있는 8-12 단어의 변경 사항을 설명합니다.

예 3 : 문제 요약 및 우선 순위

이 예제는 ⁠와 함께 ⁠github cli를 사용하는 방법을 보여줍니다.GH- 모델 보다 복잡하고 예약 된 워크 플로를 자동화하기위한 확장 및 프롬프트 파일. 전체를 검토하십시오 워크 플로 파일 그리고 프롬프트 파일.

특히 프로젝트가 성장함에 따라 새로운 활동을 추적하는 것은 쉽습니다. 그럼에도 불구하고 실제로 반복되는 문제와 테마를 추적하려면 놀라운 시간이 필요합니다. 새로 열린 문제를 요약하고, 테마 화하고, 우선 순위를 정하기 위해 주간 문제를 열려면 일정에 따라 GitHub 작업을 트리거 할 수 있습니다.

워크 플로를 설정하려면 Repository의 .github/Workflows 디렉토리에서 Weekly-Issue-Summary.yml이라는 새 파일을 만듭니다. 매주 월요일 오전 9시에 트리거됩니다

name: Weekly Issue Summary

on:
  workflow_dispatch:
  schedule:
    - cron: '0 9 * * 1'

permissions:
  issues: write
  contents: read
  models: read

jobs:
  create_weekly_summary:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install gh-models extension
        run: gh extension install 
        env:
          GH_TOKEN: ${{ github.token }}

지난주부터 열린 문제를 해결하고 파일에 저장하기위한 새로운 단계를 만듭니다.

 - name: Get issues from the past week and summarize
  id: get_issues
    run: |-
      LAST_WEEK=$(date -d "7 days ago" +"%Y-%m-%d")
      gh search issues "created:>$LAST_WEEK" --state=open --json title,body,url --repo ${{ github.repository }} > issues.json

      # further code will go here
    env:
      GH_TOKEN: ${{ github.token }}

이번 주 가치의 문제를 a gh models run 부르다:

cat issues.json | gh models run --file prompts/issue-summary.prompt.yml > summary.md

이전 예제와 달리이 명령에서 별도의 프롬프트 파일을 사용합니다. 저장소에서 프롬프트 디렉토리를 만들고 그 안에 issue-summary.prompt.yml 파일:

name: Issue summarizer
description: Summarizes weekly issues
model: openai/gpt-4.1
messages:
  - role: system
    content: You are a helpful issue summarizer. When given issue content, respond in markdown format.
  - role: user
    content: "Please summarize the following issues into a few short bullet points. Include links if provided. If possible, pull out general themes and help the team prioritize based on impact. Issues begin here:\n {{input}}"

이 파일에는 필수 정보가 포함되어 있습니다 : 모델, 시스템 및 사용자 프롬프트, 선택적으로 응답을 조정하는 데 사용되는 매개 변수가 포함되어 있습니다. a를 사용하여 .prompt.yml 파일, GitHub 모델의 저장소 통합을 활용하여 Rich UI로 프롬프트를 반복 할 수도 있습니다.

워크 플로 파일로 돌아가서 바로 아래에서 gh models run 명령, 요약으로 문제를 만듭니다.

ISSUE_TITLE="Issue Summary - $(date -d '7 days ago' '+%B %d') to $(date '+%B %d')"
gh issue create --title "$ISSUE_TITLE" --label summary --body-file summary.md
제목의 문제

AI 추론 조치로 간단하게 시작하든 gh-models 인라인 프롬프트가 포함 된 CLI 또는 완전한 기능을 갖춘 프롬프트 중심 워크 플로우를 생성하는 GitHub 모델을 사용하면 AI로 프로세스를 쉽게 확장 할 수 있습니다.

올바른 권한을 추가하고 위의 예를 선택하고 다음 워크 플로에서 GitHub 모델을 사용해보십시오.

작성자가 작성했습니다

케빈 루이스

선임 개발자 옹호자

출처 참조

Post Comment

당신은 놓쳤을 수도 있습니다