Skip to content

Commit fc22394

Browse files
committed
feat: ci preview action add (#183)
1 parent 99ab7ad commit fc22394

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

.github/workflows/ci-preview.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Preview CI
2+
env:
3+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
4+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
5+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
6+
NEXT_PUBLIC_API_BASE_URL: ${{ secrets.NEXT_PUBLIC_API_BASE_URL }}
7+
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
8+
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
9+
NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
10+
on:
11+
push:
12+
branches-ignore:
13+
- develop
14+
pull_request:
15+
branches-ignore:
16+
- develop
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js environment
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 18
29+
cache: "yarn"
30+
31+
- name: Get yarn cache directory path
32+
id: yarn-cache-dir-path
33+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
34+
35+
- uses: actions/cache@v3
36+
id: yarn-cache
37+
with:
38+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
39+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
40+
restore-keys: |
41+
${{ runner.os }}-yarn-
42+
43+
- name: Install dependencies
44+
run: yarn
45+
46+
- name: Build
47+
run: yarn build
48+
49+
deploy-vercel:
50+
runs-on: ubuntu-latest
51+
outputs:
52+
preview_url: ${{ steps.vercel_preview_url.outputs.preview_url }}
53+
currnent_time: ${{ steps.current-time.outputs.formattedTime }}
54+
needs: build
55+
steps:
56+
- name: Checkout
57+
uses: actions/checkout@v4
58+
59+
- name: Setup Node.js environment
60+
uses: actions/setup-node@v4
61+
with:
62+
node-version: 18
63+
cache: "yarn"
64+
65+
- name: Get yarn cache directory path
66+
id: yarn-cache-dir-path
67+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
68+
69+
- uses: actions/cache@v3
70+
id: yarn-cache
71+
with:
72+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
73+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
74+
restore-keys: |
75+
${{ runner.os }}-yarn-
76+
77+
- name: Install dependencies
78+
run: yarn
79+
80+
- name: Deploy to Vercel if needed
81+
run: |
82+
npm install --global vercel@latest
83+
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
84+
vercel build --token=${{ secrets.VERCEL_TOKEN }}
85+
vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
86+
- name: Get Vercel Preview
87+
uses: zentered/[email protected]
88+
id: vercel_preview_url
89+
- name: Get URL
90+
run: echo "https://${{ steps.vercel_preview_url.outputs.preview_url }}"
91+
- name: Get current time
92+
uses: josStorer/get-current-time@v2
93+
id: current-time
94+
with:
95+
format: "YYYY년 MM월 DD일 HH시 mm분"
96+
utcOffset: "+09:00"
97+
98+
github-deploy-comment:
99+
runs-on: ubuntu-latest
100+
needs: [deploy-vercel]
101+
steps:
102+
- name: Comment PR
103+
uses: thollander/actions-comment-pull-request@v3
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
106+
with:
107+
comment-tag: ${{ github.event.number }}-vercel
108+
message: |
109+
110+
🧷 vercel: ${{ needs.deploy-vercel.outputs.preview_url }}
111+
112+
⏰ Update: ${{ needs.deploy-vercel.outputs.currnent_time }}

0 commit comments

Comments
 (0)