워크플로 파일 검사
GitHub Actions는 YAML 구문을 사용하여 워크플로를 정의합니다. 각 워크플로는 코드 리포지토리의 .github/workflows디렉터리에 별도의 YAML 파일로 저장됩니다. 다음 워크플로 예제는 코드가 리포지토리에 푸시될 때마다 트리거됩니다. 워크플로는 다음 단계를 수행합니다.
- 푸시된 코드를 확인합니다.
- Node.js설치합니다.
- Bash 자동화된 테스트 시스템(Bats) 테스트 프레임워크를 설치합니다.
- Bats 버전을 출력하는 명령을 실행합니다.
bats -v.
name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
check-bats-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install -g bats
- run: bats -v
워크플로 파일 이해
YAML 구문을 사용하여 워크플로 파일을 만드는 방법을 이해하기 위해 이 섹션에서는 이전 예제의 각 줄을 설명합니다.
# Optional - The name of the workflow as it will appear in the "Actions" tab of the GitHub repository. If this field is omitted, the name of the workflow file will be used instead.
name: learn-github-actions
# Optional - The name for workflow runs generated that appear in the list of workflow runs on your repository's "Actions" tab. This example uses an expression with the 'github' context to display the username of the actor that triggered the workflow run.
run-name: ${{ github.actor }} is learning GitHub Actions
# Specifies the trigger for this workflow. This example uses the 'push' event, so a workflow run is triggered every time someone pushes a change to the repository or merges a pull request.
on: [push]
# Groups together all the jobs that run in the 'learn-github-actions' workflow.
jobs:
# Defines a job named 'check-bats-version'. The child keys will define properties of the job.
check-bats-version:
# Configures the job to run on the latest version of an Ubuntu Linux runner. This means that the job will execute on a fresh virtual machine hosted by GitHub.
runs-on: ubuntu-latest
# Groups together all the steps that run in the 'check-bats-version' job. Each item nested under this section is a separate action or shell script.
steps:
# The 'uses' keyword specifies that this step will run 'v4' of the 'actions/checkout' action. This is an action that checks out your repository onto the runner, allowing you to run scripts or other actions against your code (such as build and test tools). You should use the checkout action any time your workflow will use the repository's code.
- uses: actions/checkout@v4
# This step uses the 'actions/setup-node@v4' action to install the specified version of the Node.js. (This example uses version 20.) This puts both the 'node' and 'npm' commands in your PATH.
- uses: actions/setup-node@v4
with:
node-version: '20'
# The 'run' keyword tells the job to execute a command on the runner. In this case, you are using 'npm' to install the 'bats' software testing package.
- run: npm install -g bats
# The 'bats' command with a parameter that outputs the software version.
- run: bats -v
워크플로 실행에 대한 활동 보기
워크플로가 트리거되면 워크플로를 실행하는 워크플로 실행이 만들어집니다. 워크플로 실행이 시작되면 실행 진행률의 시각화 그래프를 보고 GitHub에서 각 단계의 작업을 볼 수 있습니다. 다음 단계에 따라 활동을 확인합니다.
리포지토리의 기본 페이지로 이동합니다.
리포지토리 이름 아래 있는 액션을 선택합니다.
왼쪽 사이드바에서 보려는 워크플로를 선택합니다.
워크플로 실행 목록에서 실행 이름을 선택하여 워크플로 실행 요약을 확인합니다.
왼쪽 사이드바 또는 시각화 그래프에서 보려는 작업을 선택합니다.
자세한 결과를 보려면 단계를 선택합니다.
이제 워크플로 파일 구성 요소를 이해했으므로 개발자가 다양한 사용 사례에 맞게 파일을 사용자 지정하는 방법을 확인할 수 있습니다.