{"meta":{"title":"워크플로에서 GitHub CLI 사용","intro":"GitHub CLI 워크플로에서 GitHub Actions으로 스크립팅할 수 있습니다.","product":"GitHub Actions","breadcrumbs":[{"href":"/ko/actions","title":"GitHub Actions"},{"href":"/ko/actions/how-tos","title":"사용법"},{"href":"/ko/actions/how-tos/write-workflows","title":"워크플로 작성"},{"href":"/ko/actions/how-tos/write-workflows/choose-what-workflows-do","title":"워크플로에서 수행하는 작업 선택"},{"href":"/ko/actions/how-tos/write-workflows/choose-what-workflows-do/use-github-cli","title":"GitHub CLI 사용"}],"documentType":"article"},"body":"# 워크플로에서 GitHub CLI 사용\n\nGitHub CLI 워크플로에서 GitHub Actions으로 스크립팅할 수 있습니다.\n\n> \\[!NOTE]\n> GitHub CLI에 대한 자세한 내용은 [GitHub CLI 정보](/ko/github-cli/github-cli/about-github-cli)을(를) 참조하세요.\n\nGitHub CLI는 모든 GitHub호스팅 실행기에 사전 설치됩니다. GitHub CLI를 사용하는 각 단계에서는 `GH_TOKEN` 환경 변수를 필요한 범위가 있는 토큰으로 설정해야 합니다.\n\n모든 GitHub CLI 명령을 실행할 수 있습니다. 예를 들어 이 워크플로는 `gh issue comment` 하위 명령을 사용하여 이슈가 열리면 주석을 추가합니다.\n\n```yaml copy\nname: Comment when opened\non:\n  issues:\n    types:\n      - opened\njobs:\n  comment:\n    runs-on: ubuntu-latest\n    steps:\n      - run: gh issue comment $ISSUE --body \"Thank you for opening this issue!\"\n        env:\n          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n          ISSUE: ${{ github.event.issue.html_url }}\n```\n\nGitHub CLI를 통해 API 호출을 실행할 수도 있습니다. 예를 들어 이 워크플로는 먼저 `gh api` 하위 명령을 사용하여 GraphQL API를 쿼리하고 결과를 구문 분석합니다. 그런 다음 이후 단계에서 액세스할 수 있는 환경 변수에 결과를 저장합니다. 두 번째 단계에서는 `gh issue create` 하위 명령을 사용하여 첫 번째 단계의 정보를 포함하는 이슈를 만듭니다.\n\n```yaml copy\nname: Report remaining open issues\non:\n  schedule:\n    # Daily at 8:20 UTC\n    - cron: '20 8 * * *'\njobs:\n  track_pr:\n    runs-on: ubuntu-latest\n    steps:\n      - run: |\n          numOpenIssues=\"$(gh api graphql -F owner=$OWNER -F name=$REPO -f query='\n            query($name: String!, $owner: String!) {\n              repository(owner: $owner, name: $name) {\n                issues(states:OPEN){\n                  totalCount\n                }\n              }\n            }\n          ' --jq '.data.repository.issues.totalCount')\"\n\n          echo 'NUM_OPEN_ISSUES='$numOpenIssues >> $GITHUB_ENV\n        env:\n          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n          OWNER: ${{ github.repository_owner }}\n          REPO: ${{ github.event.repository.name }}\n      - run: |\n          gh issue create --title \"Issue report\" --body \"$NUM_OPEN_ISSUES issues remaining\" --repo $GITHUB_REPOSITORY\n        env:\n          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n```"}