forked from woowacourse-teams/2024-haeng-dong
-
Notifications
You must be signed in to change notification settings - Fork 0
181 lines (146 loc) Β· 4.78 KB
/
frontend-pull-request.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: frontend-pull-request
on:
pull_request:
types: [opened, synchronize]
branches: [main, fe-dev]
paths:
- "client/**"
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./client
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.15.1"
- name: Install dependencies
run: npm install
- name: Run lint
run: npm run lint
- name: Run test
run: npm run test
- name: Cypress test
run: npm run dev &
env:
CI: true
- name: Wait for the server to start
run: sleep 3
- name: Run Cypress tests
run: npm run cypress-run
feature-deploy:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./client
# pull request base refκ° fe-devμΌ λλ§ feature-deploy μμ
μν
if: github.base_ref == 'fe-dev'
steps:
# 1. Git 리ν¬μ§ν 리 체ν¬μμ
- name: Checkout code
uses: actions/checkout@v4
# 2. Node js 20.15.1 λ²μ μΌλ‘ μ
ν
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.15.1"
# 3. feature λΈλμΉ μ΄λ¦ μΆμΆ (feature/#123 -> feature123)
- name: Extract and format branch name
run: |
echo "BRANCH_NAME=$(echo '${{ github.head_ref }}' | sed 's#[/#]##g')" >> $GITHUB_ENV
# 4. μμ‘΄μ±μ΄ μΊμμ μλμ§ νμΈ
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}-v1
restore-keys: |
${{ runner.os }}-npm-
# 5. μμ‘΄μ± μ€μΉ
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install
# 6. Dev νκ²½μΌλ‘ λΉλ
- name: Build dev environment
run: npm run build-dev-feature
env:
API_BASE_URL: ${{ secrets.API_BASE_URL }}
AMPLITUDE_KEY: ${{ secrets.AMPLITUDE_KEY }}
KAKAO_JAVASCRIPT_KEY: ${{ secrets.KAKAO_JAVASCRIPT_KEY }}
IMAGE_URL: ${{ secrets.IMAGE_URL }}
KAKAO_REDIRECT_URI: ${{ secrets.KAKAO_REDIRECT_URI }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
# 7. AWS μΈμ¦ μ€μ
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
# 8. S3μ μ
λ‘λ
- name: Deploy to S3
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
run: |
aws s3 sync ./dist s3://${{ secrets.S3_BUCKET_NAME }}/dev/${BRANCH_NAME}/ \
--delete
# 9. CloudFront μΊμ 무ν¨ν
- name: Invalidate CloudFront Cache
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ secrets.DEV_CLOUDFRONT_DISTRIBUTION_ID }} \
--paths "/${BRANCH_NAME}/*"
# 10. λ°°ν¬ μ£Όμ PRμ μ½λ©νΈ μμ±
- name: Comment on PR
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
uses: thollander/actions-comment-pull-request@v2
with:
message: "π **Deploy Link**: ${{ secrets.DEV_BASE_URL }}/${{ env.BRANCH_NAME }}"
chromatic:
name: Run Chromatic
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./client
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.15.1"
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}-v1
restore-keys: |
${{ runner.os }}-npm-
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install
- name: Run Chromatic
uses: chromaui/action@latest
id: publish_chromatic
with:
workingDir: client
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
- name: Comment on PR
uses: thollander/actions-comment-pull-request@v2
with:
message: "π **storybook**: ${{ steps.publish_chromatic.outputs.storybookUrl }}"