⚙️ 우리 팀의 GitHub PR & 배포 자동화 세팅기
GitHub Actions는 GitHub에서 제공하는 자동화 도구(CI/CD)로, 특정 이벤트(Push, Pull Request, Merge 등)에 반응하여 정의된 작업을 수행할 수 있도록 지원함.이 작업의 흐름을 워크플로우(Workflow)라고 하며, .github/workflows/*.yml 파일에 정의됨.GitHub Actions를 사용하면 반복적이고 실수하기 쉬운 작업을 자동화하고, 개발 흐름의 일관성을 확보할 수 있음.
도입하게 된 이유 : 팀 규모와 PR 일관성의 반비례- 각자 다른 양식으로 PR을 작성해 리뷰 기준이 불분명- 제목/설명/태그 정보가 불충분해 기여 의도 파악이 어려움- 수시로 이루어지는 PR과 머지로 인해 버전 관리 누락- 빌드/배포를 수동으로 처리하느라 반복 작업에 리소스 낭비
pull_request_template.md 구성- PR 설명의 품질을 일정 수준 이상으로 유지- 리뷰 속도와 정확도 향상에 크게 기여
## 🔍 이슈 넘버
-
## 🔧 개요
변경한 작업의 목적이나 배경을 간단하게 작성해주세요.
---
## ✅ 작업 내용
- [ ] 기능 구현
- [ ] 버그 수정
- [ ] 리팩토링
- [ ] 문서 수정
## 🔍 주요 변경 사항
- 어떤 부분이 어떻게 바뀌었는지 핵심만 요약해주세요.
---
## 📸 스크린샷 (선택)
변경된 화면이나 동작이 있다면 캡처를 첨부해주세요.
## 📎 추가 라이브러리 설치 유무
- 작업 중 추가로 라이브러리를 설치한 경우 적어주세요.
## 📎 기타
리뷰어가 알아야 할 추가 정보나 요청 사항이 있다면 적어주세요.
PR & 릴리즈 자동화 워크플로우Flow (main 브랜치로 push 시)- 종속성 설치 및 빌드 수행- 빌드 결과 커밋- 서버에서 git pull 실행 (배포)- 이후 자동으로 가장 최근 태그 조회- 날짜 기반 버전 생성 (ex: 1.240508.01)- 새 태그 생성 및 push- GitHub Release 자동 생성
name: Release Workflow
# 실행 조건
on:
push:
branches:
- main
# 실행문
jobs:
build_and_tag:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout Source Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Cache node modules
uses: actions/cache@v3
with:
path: "**/node_modules"
key: {{runner.os}}-build-{{hashFiles('**/yarn-lock')}} # yarn 이라면 yarn.lock
restore-keys: |
{{runner.os}}-build-
- name: Install Dependencies
run: yarn install --frozen-lockfile # 해쉬된 yarn 파일을 읽어 변경점 있으면 자동으로 yarn 실행
- name: Build Project
run: yarn run build
- name: Commit build output
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "build and commit" || echo "No changes to commit"
git push origin main
- name: Get Latest Tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags --abbrev=0 || echo "0.000000.00")
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT
- name: Create New Tag
id: create_new_tag
run: |
year=$(date +'%y')
month=$(date +'%m')
day=$(date +%d)
minor="{year}{month}{day}"
IFS='.' read -r -a parts <<< "{{ steps.get_latest_tag.outputs.latest_tag }}"
major="{parts[0]}"
latest_minor="{parts[1]}"
latest_patch="{parts[2]}"
if [[ "{{ github.event.head_commit.message }}" == *"major update"* ]]; then
new_major=$((10#$major + 1))
new_patch="00"
else
if [ "$latest_minor" != "$minor" ]; then
new_patch="00"
else
new_patch=$(printf "%02d" $((10#$latest_patch + 1)))
fi
new_major=$major
fi
new_tag="$new_major.$minor.$new_patch"
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
git tag $new_tag
git push origin $new_tag
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: {{ secrets.GITHUB_TOKEN }}
with:
tag_name: {{ steps.create_new_tag.outputs.new_tag }}
release_name: {{ steps.create_new_tag.outputs.new_tag }}
body: Release version {{ steps.create_new_tag.outputs.new_tag }}
draft: false
prerelease: false
도입 효과- PR에 공통된 정보 구조를 갖추게 되어 명확해진 리뷰와 기록- 빌드 및 릴리즈 자동화로 수동 작업 부담이 사라지고 오류 감소- 커밋 메시지 기반의 버전 생성 규칙을 도입해 릴리즈 기록을 체계화- 팀 전체의 개발 생산성과 품질 유지 향상