[이제와서 시작하는 Claude AI 마스터하기 #15] GitHub Actions와 CI/CD 자동화
PR 코멘트에
@claude만 태그하면 AI가 코드를 분석하고, 수정하고, 심지어 PR까지 생성합니다! GitHub Actions와 Claude Code를 연동하여 개발 워크플로우를 자동화해봅시다.완독 시간: 25분 ⭐⭐⭐⭐
🎯 이번에 배울 것
📚 사전 지식
- #07편: Claude Code 시작하기 - Claude Code 기본
- GitHub Actions 기초 이해
📖 GitHub Actions 연동이란?
@claude 멘션의 힘
GitHub PR이나 이슈에서 @claude를 태그하면 Claude가 자동으로:
flowchart LR
A[PR 코멘트<br>@claude 리뷰해줘] --> B[GitHub Actions]
B --> C[Claude Code 실행]
C --> D[코드 분석]
D --> E[PR에 결과 코멘트]
가능한 작업들:
- 코드 리뷰 및 개선점 제안
- 이슈 기반 기능 구현
- 버그 수정 및 PR 생성
- 테스트 작성
- 문서 업데이트
왜 GitHub Actions 연동인가?
| 장점 | 설명 |
|---|---|
| 즉시 PR 생성 | 설명만 하면 완성된 PR 제공 |
| 자동 코드 구현 | 이슈를 작동하는 코드로 변환 |
| 프로젝트 표준 준수 | CLAUDE.md 가이드라인 자동 적용 |
| 간단한 설정 | 몇 분 만에 설정 완료 |
| 보안 | 코드는 GitHub 러너에서만 실행 |
🚀 빠른 설정 가이드
방법 1: Claude Code CLI로 자동 설정 (권장)
가장 쉬운 방법입니다:
1
2
claude
> /install-github-app
이 명령이 자동으로:
- GitHub 앱 설치
- 필요한 시크릿 설정
- 워크플로우 파일 생성
방법 2: 수동 설정
Step 1: GitHub 앱 설치
https://github.com/apps/claude 에서 설치
필요한 권한:
- Contents: Read & Write
- Issues: Read & Write
- Pull requests: Read & Write
Step 2: API 키 추가
Repository → Settings → Secrets → Actions에서:
- Name:
ANTHROPIC_API_KEY - Value: Anthropic Console에서 발급
Step 3: 워크플로우 파일 생성
.github/workflows/claude.yml:
1
2
3
4
5
6
7
8
9
10
11
12
13
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
claude:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: $
Step 4: 테스트
PR이나 이슈에서 @claude 태그해보세요!
💬 @claude 명령어 사용하기
기본 사용법
PR이나 이슈 코멘트에서:
1
@claude 이 PR 리뷰해주고 개선점 알려줘
1
@claude 이 이슈에 맞는 기능 구현해줘
1
@claude user dashboard의 TypeError 버그 수정해줘
실전 예제
기능 구현 요청:
1
@claude 이슈 설명에 따라 기능 구현하고 PR 만들어줘
코드 리뷰:
1
@claude 보안 취약점 관점에서 이 PR 리뷰해줘
버그 수정:
1
@claude console에서 보이는 에러 수정해줘
질문하기:
1
@claude 이 엔드포인트에 사용자 인증은 어떻게 구현하면 좋을까?
📋 실전 워크플로우 예제
예제 1: 기본 @claude 응답
1
2
3
4
5
6
7
8
9
10
11
12
13
14
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
claude:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: $
# @claude 멘션에 자동 응답
예제 2: PR 오픈 시 자동 리뷰
1
2
3
4
5
6
7
8
9
10
11
12
13
name: Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: $
prompt: "/review"
claude_args: "--max-turns 5"
예제 3: 매일 보고서 생성
1
2
3
4
5
6
7
8
9
10
11
12
13
name: Daily Report
on:
schedule:
- cron: "0 9 * * *" # 매일 오전 9시
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: $
prompt: "어제의 커밋과 오픈된 이슈 요약해줘"
claude_args: "--model claude-opus-4-6"
예제 4: Skills 사용
1
2
3
4
5
6
7
8
9
10
11
12
name: Custom Review
on:
pull_request:
types: [opened]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: $
prompt: "/review" # SKILL.md에 정의된 skill 실행
⚙️ 액션 파라미터
주요 파라미터
| 파라미터 | 설명 | 필수 |
|---|---|---|
prompt | Claude에게 전달할 지시 | 아니오* |
claude_args | CLI 인자 전달 | 아니오 |
anthropic_api_key | API 키 | 예** |
github_token | GitHub 토큰 | 아니오 |
trigger_phrase | 트리거 문구 (기본: “@claude”) | 아니오 |
use_bedrock | AWS Bedrock 사용 | 아니오 |
use_vertex | Google Vertex AI 사용 | 아니오 |
*prompt 없으면 @claude 멘션에 응답 **Bedrock/Vertex 사용 시 불필요
claude_args 활용
1
claude_args: "--max-turns 5 --model claude-sonnet-4-5-20250929"
자주 쓰는 인자:
--max-turns: 최대 대화 턴 (기본: 10)--model: 모델 지정--allowed-tools: 허용할 도구--debug: 디버그 출력
☁️ 클라우드 프로바이더 연동
기업 환경에서 AWS Bedrock이나 Google Vertex AI를 사용한다면:
AWS Bedrock 설정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
name: Claude PR Action
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
on:
issue_comment:
types: [created]
jobs:
claude-pr:
if: contains(github.event.comment.body, '@claude')
runs-on: ubuntu-latest
env:
AWS_REGION: us-west-2
steps:
- uses: actions/checkout@v4
- name: Configure AWS Credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: $
aws-region: us-west-2
- uses: anthropics/claude-code-action@v1
with:
use_bedrock: "true"
claude_args: '--model us.anthropic.claude-sonnet-4-5-20250929-v1:0'
Google Vertex AI 설정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
name: Claude PR Action
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
on:
issue_comment:
types: [created]
jobs:
claude-pr:
if: contains(github.event.comment.body, '@claude')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: $
service_account: $
- uses: anthropics/claude-code-action@v1
with:
use_vertex: "true"
claude_args: '--model claude-sonnet-4-5@20250929'
env:
ANTHROPIC_VERTEX_PROJECT_ID: $
CLOUD_ML_REGION: us-east5
📐 CLAUDE.md로 행동 제어
프로젝트 루트에 CLAUDE.md를 생성하면 Claude가 자동으로 따릅니다:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 코드 스타일 가이드
## 커밋 메시지
- Conventional Commits 사용
- 한글로 작성
- 예: `feat: 로그인 기능 추가`
## 코드 리뷰
- 보안 취약점 우선 체크
- 성능 영향 평가
- 테스트 커버리지 확인
## PR 규칙
- 제목은 50자 이내
- 본문에 변경 이유 포함
💰 비용 고려사항
GitHub Actions 비용
- GitHub 호스팅 러너 사용 → Actions 분 소비
- GitHub 빌링 문서 참조
API 비용
- 프롬프트/응답 길이에 따라 토큰 사용
- 작업 복잡도와 코드베이스 크기에 따라 다름
- Claude 가격 페이지 참조
비용 최적화 팁
1
2
# max-turns 제한으로 과도한 반복 방지
claude_args: "--max-turns 5"
- 구체적인
@claude명령 사용 - 워크플로우 타임아웃 설정
- 동시 실행 제한
🔒 보안 고려사항
API 키 보호
1
2
3
4
5
# ❌ 절대 하면 안 됨
anthropic_api_key: "sk-ant-..."
# ✅ 항상 시크릿 사용
anthropic_api_key: $
권한 최소화
1
2
3
4
permissions:
contents: write # 파일 수정에 필요
pull-requests: write # PR 생성에 필요
issues: write # 이슈 응답에 필요
추가 보안 권장사항
- Claude 제안을 머지 전 검토
- 액션 권한을 필요한 것만 부여
- 민감한 정보가 포함된 저장소 주의
🏗️ CI/CD 파이프라인 아키텍처
GitHub Actions를 넘어, Claude Code로 전체 CI/CD 파이프라인을 설계할 수 있습니다.
파이프라인 전체 흐름
graph LR
A[Code Push] --> B[CI Trigger]
B --> C[Code Analysis]
C --> D[Build]
D --> E[Test]
E --> F[Security Scan]
F --> G{Pass?}
G -->|Yes| H[Deploy to Staging]
G -->|No| I[Notify Developer]
H --> J[E2E Tests]
J --> K{Pass?}
K -->|Yes| L[Deploy to Production]
K -->|No| M[Rollback]
L --> N[Monitor]
N --> O[Alert if Issues]
📊 고급 배포 전략
블루-그린 배포
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 블루-그린 배포 워크플로우
name: Blue-Green Deployment
on:
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
required: true
type: choice
options:
- staging
- production
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to Green environment
run: |
# 새 버전을 Green 환경에 배포
kubectl apply -f k8s/app-green.yaml -n $NAMESPACE
kubectl wait --for=condition=ready pod -l app=app-green --timeout=300s
- name: Run smoke tests
run: npm run test:smoke -- --url https://green.$DOMAIN
- name: Switch traffic to Green
run: |
kubectl patch service app -p '{"spec":{"selector":{"version":"green"}}}'
- name: Monitor new deployment
run: npm run monitor -- --duration 5m --threshold 0.1
카나리 배포
트래픽을 점진적으로 늘려가며 새 버전을 검증하는 전략입니다:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 카나리 배포 단계 구성
const canaryStages = [
{ name: "1% traffic", percentage: 1, duration: "5m",
metrics: { errorRate: { threshold: 0.1 }, latency: { p99: 1000 } } },
{ name: "10% traffic", percentage: 10, duration: "10m",
metrics: { errorRate: { threshold: 0.05 }, latency: { p99: 800 } } },
{ name: "50% traffic", percentage: 50, duration: "30m",
metrics: { errorRate: { threshold: 0.01 }, latency: { p99: 500 } } }
];
const rollback = {
automatic: true,
conditions: [
"error_rate > threshold",
"latency_p99 > threshold",
"health_check_failures > 5"
]
};
🔄 자동 롤백 시스템
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 자동 롤백 워크플로우
name: Auto Rollback
on:
workflow_run:
workflows: ["Deploy to Production"]
types: [completed]
jobs:
monitor-and-rollback:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Monitor application health
id: health-check
run: |
for i in {1..10}; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://example.com/health)
if [ $STATUS -ne 200 ]; then
echo "Health check failed: $STATUS"
echo "healthy=false" >> $GITHUB_OUTPUT
exit 0
fi
sleep 30
done
echo "healthy=true" >> $GITHUB_OUTPUT
- name: Rollback if needed
if: steps.health-check.outputs.healthy == 'false'
run: |
kubectl rollout undo deployment/app -n production
curl -X POST $ \
-H 'Content-type: application/json' \
-d '{"text":"🚨 Production deployment rolled back due to health check failures"}'
⚡ 성능 최적화
병렬 처리 최적화
1
2
3
4
5
6
7
8
9
10
11
12
# 매트릭스 전략으로 병렬 테스트
jobs:
test:
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
os: [ubuntu-latest, windows-latest, macos-latest]
test-chunk: [1, 2, 3, 4]
runs-on: $
steps:
- name: Run test chunk $
run: npm run test:chunk:$
캐싱 전략
1
2
3
4
5
6
7
8
9
10
11
# 효율적인 캐싱 설정
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.npm
~/.cache
node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
$-node-
🏢 GitLab CI/CD 파이프라인 (참고)
GitHub Actions 외에 GitLab CI/CD를 사용하는 경우의 예시입니다:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# .gitlab-ci.yml
stages:
- validate
- test
- build
- deploy
lint:
stage: validate
image: node:18-alpine
script:
- npm ci --cache .npm --prefer-offline
- npm run lint
- npm run format:check
test:unit:
stage: test
image: node:18-alpine
coverage: '/Lines\s*:\s*(\d+\.\d+)%/'
script:
- npm ci
- npm run test:unit -- --coverage
deploy:production:
stage: deploy
image: bitnami/kubectl:latest
script:
- kubectl set image deployment/app app=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -n production
- kubectl rollout status deployment/app -n production
when: manual
only:
- main
🔐 시크릿 관리 심화
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 시크릿 관리 시스템 예시
class SecretManager {
private vault: HashiCorp.Vault;
async getSecrets(environment: string): Promise<Secrets> {
const path = `secret/data/${environment}`;
const response = await this.vault.read(path);
return {
database: {
host: response.data.db_host,
password: response.data.db_password,
user: response.data.db_user
},
api: {
key: response.data.api_key,
secret: response.data.api_secret
}
};
}
async rotateSecrets(environment: string): Promise<void> {
const newSecrets = await this.generateNewSecrets();
await this.vault.write(`secret/data/${environment}`, newSecrets);
await this.updateApplications(environment, newSecrets);
}
}
📈 파이프라인 모니터링 지표
CI/CD 파이프라인의 건강을 측정하는 핵심 DORA 지표:
| 지표 | 설명 | 목표 |
|---|---|---|
| Deployment Frequency | 배포 빈도 | 하루 여러 번 |
| Lead Time | 커밋에서 배포까지 시간 | 1시간 이내 |
| MTTR | 장애 복구 시간 | 1시간 이내 |
| Change Failure Rate | 배포 실패율 | 15% 이하 |
🔧 문제 해결
Claude가 @claude에 응답 안 함
체크리스트:
- GitHub 앱이 설치되어 있는가?
- 워크플로우가 활성화되어 있는가?
- API 키가 시크릿에 설정되어 있는가?
- 코멘트에
@claude가 포함되어 있는가? (/claude아님)
CI가 Claude 커밋에서 실행 안 됨
- GitHub 앱 또는 커스텀 앱 사용 확인 (기본 Actions 사용자 아님)
- 워크플로우 트리거에 필요한 이벤트 포함 확인
인증 오류
- API 키 유효성 확인
- Bedrock/Vertex의 경우 자격 증명 설정 확인
- 시크릿 이름 확인
📝 오늘 배운 것 정리
✅ GitHub Actions 연동 = @claude 멘션으로 AI 자동화
✅ 빠른 설정: /install-github-app 또는 수동 워크플로우 생성
✅ 워크플로우 유형: 멘션 응답, 자동 리뷰, 스케줄 작업
✅ 파라미터: prompt, claude_args, trigger_phrase 등
✅ 클라우드 연동: AWS Bedrock, Google Vertex AI 지원
✅ CLAUDE.md: 프로젝트 규칙을 Claude에게 전달
✅ 세션 연동: gh pr create로 만든 PR이 세션에 자동 연결, --from-pr로 복원
✅ 배포 전략: 블루-그린, 카나리 배포 등 고급 배포 패턴 활용
✅ 모니터링: DORA 지표로 파이프라인 건강 측정
🔗 다음 편 미리보기
AI와 함께 일하는 팀 문화 만들기:
- 코드 리뷰 프로세스
- 보안 거버넌스
- 팀 설정 공유
- AI 시대의 개발자 역할
🔗 시리즈 전체 보기
| # | 제목 | 상태 |
|---|---|---|
| 01 | Claude AI란? 첫 대화 시작하기 | ✅ 완료 |
| 02 | 프롬프트 엔지니어링 기초 | ✅ 완료 |
| 03 | Claude의 다양한 모델과 선택 가이드 | ✅ 완료 |
| 04 | API 활용 첫걸음 | ✅ 완료 |
| 05 | 고급 프롬프트 테크닉 | ✅ 완료 |
| 06 | Claude Projects 활용하기 | ✅ 완료 |
| 07 | Claude Code 시작하기 | ✅ 완료 |
| 08 | Claude Code 작동 원리 | ✅ 완료 |
| 09 | 실전 워크플로우 | ✅ 완료 |
| 10 | CLAUDE.md 완전 정복 | ✅ 완료 |
| 11 | Skills: 나만의 명령어 만들기 | ✅ 완료 |
| 12 | Subagents로 AI 분업하기 | ✅ 완료 |
| 13 | MCP로 외부 도구 연결하기 | ✅ 완료 |
| 14 | IDE 통합 완벽 가이드 | ✅ 완료 |
| 15 | GitHub Actions와 CI/CD 자동화 | 📖 현재 글 |
🔗 참고 자료
🚀 @claude로 GitHub 워크플로우를 자동화하세요!
![[이제와서 시작하는 Claude AI 마스터하기 #15] GitHub Actions와 CI/CD 자동화](/assets/img/posts/claude/claude-master-15.png)