Workflows
- 하나 이상의 Job과 그 내부 Step에 있는 기능들을 자동화하여 관리 가능
- Workflows를 실행 시키는 트리거는 Event 라고 부름
- Event로는 push, pull request, fork 등 Github 내 다양한 동작들이 지정될 수 있음
.github/workflows
에 저장돼 있는yaml
파일이 바로 Workflows를 정의하는 파일임
name: Update README # workflows의 이름
on: # Event 발생 시 실행 정보
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
Jobs
- Workflows에서 독립적으로 수행할 작업들을 Job이라고 부름
- 각 Job은 각각 다른 서버에서 독립적으로 실행되기 때문에, 기본적으로 병렬 처리 됨
- 하지만 필요 시, Job 사이 의존 관계를 설정할 수 있음
runs-on
옵션을 통해, 각 서버의 OS 환경을 지정할 수 있음
# Workflows에서 수행할 Job 지정
jobs:
job1: # 이름은 자유롭게 설정할 수 있음
runs-on: ubuntu-latest
steps:
# job1에 대한 세부 내용
job2:
runs-on: windows-latest
steps:
# job2에 대한 세부 내용
job3:
runs-on: macos-latest
steps:
# job3에 대한 세부 내용
Steps
- Job에서 순차적으로 실행할 작업들을 Step이라고 함
- 커맨드나 스크립트를 실행하는 작업의 경우
run
을, Actions을 처리할 때는use
를 사용해서 처리 함 - 이전 단계에서의 변수를
$GITHUB_OUTPUT
으로 전달 받아, 다음 step에 활용할 수 있음
- 전달할 변수의 형태는
변수 이름=변수의 값
형태가 돼야 함 ex)DO_UPDATE=True
- 아래 코드에선
if
문의 조건 제어로 활용 함
- 전달할 변수의 형태는
steps:
- name: Checkout Repo
uses: actions/checkout@v3 # actions
with:
fetch-depth: 3
...
# README 업데이트 여부 확인
- name: Run update_readme.py
id: condition
working-directory: auto-readme # 실행할 폴더 정보
run: |
python update_readme.py >> $GITHUB_OUTPUT
# 변수 전달 됐는지 확인
- name: Echo condition Var
run: echo ${{steps.condition.outputs.DO_UPDATE}}
# 업데이트가 됐다면 commit 진행
- name: Commit changes
if: ${{steps.condition.outputs.DO_UPDATE == 'True'}} # 실행 조건 제어
run: |
git config --global user.name 'woodywarhol9'
git config --global user.email 'woodywarhol9@gmail.com'
git add -A
git commit -am "auto-update README.md"
Actions
- Step에서 실행할 작업의 템플릿이라고 생각하면 됨
- 실제로 다양한 템플릿이 Github에서 공유되고 있음
- 예시로
checkout@v3
은 Git 저장소를 불러올 때, 필요한 다양한 작업들을 편리하게 도와주는 Actions 임
- 예시로
steps:
- name: Checkout Repo
uses: actions/checkout@v3 # actions
with:
fetch-depth: 3
참고
GitHub Actions 이해 - GitHub Docs
Overview GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deplo
docs.github.com
GitHub Actions의 소개와 핵심 개념
Engineering Blog by Dale Seo
www.daleseo.com
- 기본 개념과 예시를 확인할 수 있다.