Introduction
This guide shows you how to create a basic workflow that is triggered when code is pushed to your repository.
미리 구성된 워크플로를 시작하려면 actions/starter-workflows 리포지토리의 템플릿 목록을 탐색합니다. 자세한 내용은 "Using workflow templates" 항목을 참조하세요.
예제 워크로드 만들기
GitHub Actions는 YAML 구문을 사용하여 워크플로를 정의합니다. 각 워크플로는 코드 리포지토리의 .github/workflows
디렉터리에 별도의 YAML 파일로 저장됩니다.
리포지토리에서 코드가 푸시될 때마다 일련의 명령을 자동으로 트리거하는 예제 워크플로를 만들 수 있습니다. 이 워크플로에서 GitHub Actions는 푸시된 코드를 체크 아웃하고 bats 테스트 프레임워크를 설치하고, 기본 명령 bats -v
를 실행하여 bats 버전을 출력합니다.
-
리포지토리에서 워크플로 파일을 저장할
.github/workflows/
디렉터리를 만듭니다. -
.github/workflows/
디렉터리에서learn-github-actions.yml
이라는 새 파일을 만들고 다음 코드를 추가합니다.YAML 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
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
-
변경 내용을 커밋하고 GitHub 리포지토리에 푸시합니다.
이제 새 GitHub Actions 워크플로 파일이 리포지토리에 설치되고, 누군가가 리포지토리에 변경 내용을 푸시할 때마다 자동으로 실행됩니다. 워크플로의 실행 기록에 관한 세부 정보를 보려면 “워크플로 실행에 대한 작업 보기”를 참조하세요.
워크플로 파일 이해
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 from the workflow, which will 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. For more information, see "[AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#run-name)." 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. This is triggered by a push to every branch; for examples of syntax that runs only on pushes to specific branches, paths, or tags, see "[AUTOTITLE](/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore)." 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. For syntax examples using other runners, see "[AUTOTITLE](/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on)" 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 # Finally, you'll run the `bats` command with a parameter that outputs the software version. - run: bats -v
name: learn-github-actions
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.
run-name: ${{ github.actor }} is learning GitHub Actions
Optional - The name for workflow runs generated from the workflow, which will 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. For more information, see "GitHub Actions에 대한 워크플로 구문."
on: [push]
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. This is triggered by a push to every branch; for examples of syntax that runs only on pushes to specific branches, paths, or tags, see "GitHub Actions에 대한 워크플로 구문."
jobs:
Groups together all the jobs that run in the learn-github-actions
workflow.
check-bats-version:
Defines a job named check-bats-version
. The child keys will define properties of the job.
runs-on: ubuntu-latest
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. For syntax examples using other runners, see "GitHub Actions에 대한 워크플로 구문"
steps:
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.
- uses: actions/checkout@v4
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/setup-node@v4
with:
node-version: '20'
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
.
- run: npm install -g bats
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: bats -v
Finally, you'll run the bats
command with a parameter that outputs the software version.
# 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 from the workflow, which will 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. For more information, see "[AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#run-name)."
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. This is triggered by a push to every branch; for examples of syntax that runs only on pushes to specific branches, paths, or tags, see "[AUTOTITLE](/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore)."
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. For syntax examples using other runners, see "[AUTOTITLE](/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on)"
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
# Finally, you'll run the `bats` command with a parameter that outputs the software version.
- run: bats -v
워크플로 파일 시각화
아래 다이어그램에서, 방금 만든 워크플로 파일 및 GitHub Actions 구성 요소가 계층 구조로 구성된 방식을 확인할 수 있습니다. 각 단계는 단일 작업 또는 셸 스크립트를 실행합니다. 1단계와 2단계는 작업을 실행하는 반면, 3단계와 4단계는 셸 스크립트를 실행합니다. 워크플로에 대해 미리 빌드된 작업을 더 찾으려면 "Using pre-written building blocks in your workflow"을 참조하세요.
워크플로 실행에 대한 작업 보기
워크플로가 트리거되면 워크플로를 실행하는 워크플로 실행이 만들어집니다.__ 워크플로 실행이 시작된 후 GitHub에서 실행 진행률 시각화 그래프를 확인하고 각 단계의 작업을 볼 수 있습니다.
-
GitHub Enterprise Server 인스턴스에서 리포지토리의 기본 페이지로 이동합니다.
-
리포지토리 이름 아래에서 작업을 클릭합니다.
-
왼쪽 사이드바에서 확인할 워크플로를 클릭합니다.
-
워크플로 실행 목록에서 실행 이름을 클릭하여 워크플로 실행 요약을 확인합니다.
-
왼쪽 사이드바 또는 시각화 그래프에서 확인할 작업을 클릭합니다.
-
단계의 결과를 보려면 단계를 클릭합니다.