-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (131 loc) · 4.33 KB
/
ci-cd.yml
File metadata and controls
138 lines (131 loc) · 4.33 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: CI/CD Workflow
on:
push:
branches:
- main
- develop
- "feat/**"
- "fix/**"
- "refactor/**"
- "style/**"
- "release/**"
pull_request:
branches:
- develop
permissions:
contents: read
pull-requests: write
jobs:
# 0️⃣ Lint
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run lint
run: pnpm lint
# 1️⃣ Build & Test
build:
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm run build
- name: Test
run: pnpm test || true
# Build/Test 실패 시 PR 코멘트 + 닫기
- name: Fail PR if build/test fails
if: ${{ failure() && github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = ${{ github.event.pull_request.number }};
const updated_title = `[CI FAIL] ${{ github.event.pull_request.title }}`;
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr,
body: '빌드 또는 테스트에 실패했습니다.',
event: 'REQUEST_CHANGES'
});
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr,
title: updated_title,
state: 'closed'
});
# 2️⃣ Preview 배포 (feat/*, fix/*, refactor/*, style/*, develop PR)
deploy-preview:
if: ${{ !startsWith(github.ref, 'refs/heads/main') }}
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Vercel CLI 설치
run: npm install -g vercel@latest
- name: Vercel Preview Deploy
id: deploy
run: |
DEPLOY_URL=$(vercel deploy --token=${{ secrets.VERCEL_TOKEN }} --yes)
echo "url=$DEPLOY_URL" >> $GITHUB_OUTPUT
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
- name: PR 코멘트에 Preview URL 작성
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const deployUrl = '${{ steps.deploy.outputs.url }}';
const comment = `🚀 **미리보기 배포 완료!**\n\n📝 **배포 URL:** ${deployUrl}\n✅ **브랜치:** \`${{ github.head_ref }}\`\n✅ **커밋:** \`${{ github.sha }}\``;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
# 3️⃣ Production 배포 (main push)
deploy-production:
if: github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Vercel CLI 설치
run: npm install -g vercel@latest
- name: Vercel Production Deploy
id: deploy-prod
run: |
DEPLOY_URL=$(vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }} --yes)
echo "url=$DEPLOY_URL" >> $GITHUB_OUTPUT
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
- name: 운영 배포 완료 알림
run: |
echo "🎉 운영 환경 배포 완료!"
echo "📝 배포 URL: ${{ steps.deploy-prod.outputs.url }}"