이 문서에서는 예제 워크플로를 사용하여 GitHub Actions의 주요 CI 기능 중 일부를 보여 줍니다. 이 워크플로가 트리거되면 GitHub Docs 사이트에 끊어진 링크가 있는지 여부를 확인하는 스크립트가 자동으로 실행됩니다. 끊어진 링크가 있으면 워크플로는 GitHub CLI에서 세부 정보를 사용하여 GitHub 이슈를 만듭니다.
다음 다이어그램에서는 워크플로의 단계와 작업 내에서 실행되는 방법에 대한 개략적인 보기를 보여 줍니다.
name:CheckallEnglishlinks# **What it does**: This script once a day checks all English links and reports in issues.# **Why we have it**: We want to know if any links break.# **Who does it impact**: Docs content.on:workflow_dispatch:schedule:-cron:'40 19 * * *'# once a day at 19:40 UTC / 11:40 PSTpermissions:contents:readissues:writejobs:check_all_english_links:name:Checkalllinksif:github.repository=='github/docs-internal'runs-on:ubuntu-latestenv:GITHUB_TOKEN:${{secrets.DOCUBOT_READORG_REPO_WORKFLOW_SCOPES}}FIRST_RESPONDER_PROJECT:DocscontentfirstresponderREPORT_AUTHOR:docubotREPORT_LABEL:brokenlinkreportREPORT_REPOSITORY:github/docs-contentsteps:-name:Checkoutrepo'sdefaultbranchuses:actions/checkout@v3-name:SetupNodeuses:actions/setup-node@v3with:node-version:16.13.xcache:npm-name:npmcirun:npmci-name:npmrunbuildrun:npmrunbuild-name:Runscriptrun:|
script/check-english-links.js > broken_links.md
# check-english-links.js returns 0 if no links are broken, and 1 if any links# are broken. When an Actions step's exit code is 1, the action run's job status# is failure and the run ends. The following steps create an issue for the# broken link report only if any links are broken, so `if: ${{ failure() }}`# ensures the steps run despite the previous step's failure of the job.-if:${{failure()}}name:Gettitleforissueid:checkrun:echo"title=$(head -1 broken_links.md)">>$GITHUB_OUTPUT-if:${{failure()}}name:Createissuefromfileid:broken-link-reportuses:peter-evans/create-issue-from-file@b4f9ee0a9d4abbfc6986601d9b1a4f8f8e74c77ewith:token:${{env.GITHUB_TOKEN}}title:${{steps.check.outputs.title}}content-filepath:./broken_links.mdrepository:${{env.REPORT_REPOSITORY}}labels:${{env.REPORT_LABEL}}-if:${{failure()}}name:Closeand/orcommentonoldissuesenv:NEW_REPORT_URL:'https://github.com/${{ env.REPORT_REPOSITORY }}/issues/${{ steps.broken-link-report.outputs.issue-number }}'run:|
gh alias set list-reports "issue list \
--repo ${{ env.REPORT_REPOSITORY }} \
--author ${{ env.REPORT_AUTHOR }} \
--label '${{ env.REPORT_LABEL }}'"
# Link to the previous report from the new report that triggered this# workflow run.previous_report_url=$(ghlist-reports\--stateall\--limit2\--jsonurl\--jq'.[].url'\|grep-v${{env.NEW_REPORT_URL}}|head-1)ghissuecomment${{env.NEW_REPORT_URL}}--body"⬅️ [Previous report]($previous_report_url)"# If an old report is open and assigned to someone, link to the newer# report without closing the old report.forissue_urlin$(ghlist-reports\--jsonassignees,url\--jq'.[] | select (.assignees != []) | .url');doif [ "$issue_url"!="${{ env.NEW_REPORT_URL }}" ];thenghissuecomment$issue_url--body"➡️ [Newer report](${{ env.NEW_REPORT_URL }})"fidone# Link to the newer report from any older report that is still open,# then close the older report and remove it from the first responder's# project board.forissue_urlin$(ghlist-reports\--search'no:assignee'\--jsonurl\--jq'.[].url');doif [ "$issue_url"!="${{ env.NEW_REPORT_URL }}" ];thenghissuecomment$issue_url--body"➡️ [Newer report](${{ env.NEW_REPORT_URL }})"ghissueclose$issue_urlghissueedit$issue_url--remove-project"${{ env.FIRST_RESPONDER_PROJECT }}"fidone
예제 이해
다음 표에서는 GitHub Actions 워크플로를 만들 때 이러한 각 기능을 사용하는 방법을 설명합니다.
코드
설명
YAML
name:CheckallEnglishlinks
GitHub 리포지토리의 “작업” 탭에 표시되는 워크플로 이름입니다.
YAML
on:workflow_dispatch:schedule:-cron:'40 20 * * *'# once a day at 20:40 UTC / 12:40 PST
workflow_dispatch 및 scheduled를 워크플로에 대한 트리거로 정의합니다.
workflow_dispatch를 사용하면 UI에서 이 워크플로를 수동으로 실행할 수 있습니다. 자세한 내용은 workflow_dispatch를 참조하세요.
schedule 이벤트를 사용하면 cron 구문을 사용하여 워크플로를 자동으로 트리거하는 정기적인 간격을 정의할 수 있습니다. 자세한 내용은 schedule를 참조하세요.
YAML
permissions:contents:readissues:write
GITHUB_TOKEN에 부여된 기본 사용 권한을 수정합니다. 워크플로의 요구 사항에 따라 달라집니다. 자세한 내용은 "작업에 권한 할당"을 참조하세요.
YAML
jobs:
워크플로 파일에서 실행되는 모든 작업을 함께 그룹화합니다.
YAML
check_all_english_links:name:Checkalllinks
jobs 키 내에 저장된 ID가 check_all_english_links이고 이름이 Check all links인 작업을 정의합니다.
YAML
if:github.repository=='github/docs-internal'
리포지토리 이름이 docs-internal이고 github 조직 내에 있는 경우에만 check_all_english_links 작업이 실행됩니다. 그렇지 않으면 작업이 건너뛴 것으로 표시됩니다.
YAML
runs-on:ubuntu-latest
Ubuntu Linux 실행기에서 실행되도록 작업을 구성합니다. 즉, GitHub에서 호스트된 새 가상 머신에서 작업이 실행됩니다. 다른 실행기를 사용하는 구문 예제는 "GitHub Actions에 대한 워크플로 구문"을 참조하세요.
uses 키워드는 작업에 actions/checkout으로 이름이 지정된 작업을 검색하도록 지시합니다. 이 작업은 리포지토리를 체크 아웃하고 실행기로 다운로드하여 코드에 대해 작업(예: 도구 테스트)을 실행할 수 있도록 합니다. 워크플로가 리포지토리의 코드에 대해 실행되거나 리포지토리에 정의된 작업을 사용할 때마다 체크 아웃 작업을 사용해야 합니다.