Skip to main content
We publish frequent updates to our documentation, and translation of this page may still be in progress. For the most current information, please visit the English documentation.

워크플로에서 GitHub CLI 사용

GitHub Actions 워크플로에서 GitHub CLI으로 스크립팅할 수 있습니다.

GitHub CLI에 대한 자세한 내용은 "AUTOTITLE"을 참조하세요.

GitHub CLI는 모든 GitHub호스팅 실행기에 사전 설치됩니다. GitHub CLI를 사용하는 각 단계에서는 GITHUB_TOKEN 환경 변수를 필요한 범위가 있는 토큰으로 설정해야 합니다.

모든 GitHub CLI 명령을 실행할 수 있습니다. 예를 들어 이 워크플로는 gh issue comment 하위 명령을 사용하여 이슈가 열리면 주석을 추가합니다.

YAML
name: Comment when opened
on:
  issues:
    types:
      - opened
jobs:
  comment:
    runs-on: ubuntu-latest
    steps:
      - run: gh issue comment $ISSUE --body "Thank you for opening this issue!"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          ISSUE: ${{ github.event.issue.html_url }}

GitHub CLI를 통해 API 호출을 실행할 수도 있습니다. 예를 들어 이 워크플로는 먼저 gh api 하위 명령을 사용하여 GraphQL API를 쿼리하고 결과를 구문 분석합니다. 그런 다음 이후 단계에서 액세스할 수 있는 환경 변수에 결과를 저장합니다. 두 번째 단계에서는 gh issue create 하위 명령을 사용하여 첫 번째 단계의 정보를 포함하는 이슈를 만듭니다.

YAML
name: Report remaining open issues
on: 
  schedule: 
    # Daily at 8:20 UTC
    - cron: '20 8 * * *'
jobs:
  track_pr:
    runs-on: ubuntu-latest
    steps:
      - run: |
          numOpenIssues="$(gh api graphql -F owner=$OWNER -F name=$REPO -f query='
            query($name: String!, $owner: String!) {
              repository(owner: $owner, name: $name) {
                issues(states:OPEN){
                  totalCount
                }
              }
            }
          ' --jq '.data.repository.issues.totalCount')"

          echo 'NUM_OPEN_ISSUES='$numOpenIssues >> $GITHUB_ENV
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OWNER: ${{ github.repository_owner }}
          REPO: ${{ github.event.repository.name }}
      - run: |
          gh issue create --title "Issue report" --body "$NUM_OPEN_ISSUES issues remaining" --repo $GITHUB_REPOSITORY
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}