TL;DR
1. ์คํ ๋ฆฌ๋ถ์ ๋์ ํ๊ฒ ๋ ๊ณ๊ธฐ
2. chromatic์ผ๋ก ์คํ ๋ฆฌ๋ถ ๋ฐฐํฌํ๊ธฐ
3. Github Actions๋ฅผ ์ด์ฉํด Pull Reqeust์์ ๋ฐ๋ก ์ปดํฌ๋ํธ ํ์ธํ๊ธฐ
์คํ ๋ฆฌ๋ถ์ ๋์ ํ๊ฒ ๋ ๊ณ๊ธฐ
ํ์ ์ ์งํํ๋ฉด์ ์ฌ๋ฌ ์ฌ๋์ด ์ปดํฌ๋ํธ๋ฅผ ๊ฐ๋ฐํ๊ฒ ๋์์ต๋๋ค.
์๋์ ๊ฐ์ ์ปดํฌ๋ํธ ์ฝ๋๋ค์ด PR๋ก ์ฌ๋ผ์ค๊ธฐ ์์ํ์ต๋๋ค.
PR์ ์ด์ฌํ ์์ฑํ๋๋ผ๋ ์ ์ฝ๋๋ฅผ ๋ณด๊ณ ์ฝ๊ฒ ๋จธ๋ฆฌ์ ์ปดํฌ๋ํธ๋ฅผ ๋ ์ฌ๋ฆฌ๊ธฐ๋ ์ด๋ ต์ต๋๋ค.
๊ฒ๋ค๊ฐ, PR์ ์ด์ฌํ ์์ฑํ๋ค๋ ๊ฒ์ ๊ฐ๋ฐ์๊ฐ ๋งค๋ฒ ๊ผผ๊ผผํ ์์ฑํด์ผํ๊ณ PR์ ์ฝ๋ ๊ฐ๋ฐ์๋ ๋ ์ ๊ฒฝ์จ์ ์ฝ์ด์ผํฉ๋๋ค. ๋ถํ์ํ๊ฒ ๋์ ์ํต ๋น์ฉ์ด ๋ฐ์ํ๊ณ ์์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋งค๋ฒ pull์ ๋ฐ์์ ๊ฐ๋ฐ ์๋ฒ๋ฅผ ์คํํ๊ณ ์ด๋ค UI์ธ์ง ํ์ธํ๊ณ ์ ๋๋ก ์๋ํ๋์ง ์์ ํ ์คํธ๋ฅผ ์งํํด์ผํ์ต๋๋ค.
์ด๋ฌํ ์ ๋ค์ ํด๊ฒฐํ๊ณ ์ ์คํ ๋ฆฌ๋ถ์ ๋์ ํ๊ธฐ๋ก ํ์์ต๋๋ค.
์คํ ๋ฆฌ๋ถ ๋์ ์ด์ ์ ๋ฌธ์ ์
1. ์ฝ๋๋ฅผ ๋ณด๊ณ ์ปดํฌ๋ํธ๋ฅผ ๋ ์ฌ๋ฆฌ๊ธฐ ์ด๋ ค์
2. PR์ ๊ผผ๊ผผํ๊ฒ ์์ฑํ๊ณ ์ฝ๋๋ฐ ์ฌ์ฉํ๋ ๋ถํ์ํ๊ฒ ๋์ ์ํต ๋น์ฉ
3. ์ปดํฌ๋ํธ์ UI์ ํ ์คํธ๋ฅผ ์ํด ์ง์ ์คํํด๋ด์ผํ๋ ๋ถํธํจ
chromatic์ผ๋ก ์คํ ๋ฆฌ๋ถ ๋ฐฐํฌํ๊ธฐ
chromatic?
์คํ ๋ฆฌ๋ถ ๊ด๋ฆฌ์๊ฐ ๋ง๋ ๋ฌด๋ฃ ๋ฐฐํฌ ์๋น์ค๋ก ์คํ ๋ฆฌ๋ถ์ ๊ฐ๋จํ๊ฒ ๋ฐฐํฌํ ์ ์์ต๋๋ค.
vercel, netflify๋ก๋ ์คํ ๋ฆฌ๋ถ์ ๋ฐฐํฌํ ์ ์์ง๋ง chromatic์ ์ปดํฌ๋ํธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ, ๋น๋ ๊ณผ์ ๋ฑ์ ์คํ ๋ฆฌ๋ถ์ ์ต์ ํํด์ ๋ณด์ฌ์ฃผ๊ธฐ ๋๋ฌธ์ chromatic์ ๋ฐฐํฌํ์์ต๋๋ค.
1. chromatic ๊ฐ์ ํ๊ธฐ
Github๋ก ์ฐ๋ํด์ chromatic์ ๊ฐ๋จํ๊ฒ ๊ฐ์ ํ ์ ์์ต๋๋ค.
Automatically review, test, and document Storybook
We make tools for frontend developers that automate the Storybook workflow. Chromatic helps you gather UI feedback, test across browsers, and generate usage docs, all in one shared cloud workspace.
www.chromatic.com
Choose Github Repo
๋ฒํผ์ ๋๋ฅด๋ฉด ๊นํ๋ธ ๋ ํฌ์งํ ๋ฆฌ์ ๋๊ธฐํํ ์ ์์ต๋๋ค.
2. ์ค์นํ๊ธฐ
๊นํ๋ธ ๋ ํฌ์งํ ๋ฆฌ์ ๋๊ธฐํ๊ฐ ๋๋๋ฉด ์๋์ ๊ฐ์ ํ๋ฉด์ด ๋ณด์ฌ์ง๋๋ค.
1. chromatic์ ์ค์นํด์ค๋๋ค.
npm install --save-dev chromatic
2. ์คํ ๋ฆฌ๋ถ์ chromatic์ ๋ฐฐํฌํฉ๋๋ค.
npx chromatic --project-token <your-project-token>
๊ฐ๋จํ๊ฒ ์คํ ๋ฆฌ๋ถ์ ๋ฐฐํฌํ ์ ์์ต๋๋ค.
์ด๋ฅผ ํตํด ์คํ ๋ฆฌ๋ถ ๋์ ์ด์ ์ ๋ฌธ์ ์ ์ค 1๋ฒ๊ณผ 2๋ฒ์ ๋ฌธ์ ์ ์ ํด๊ฒฐํ ์ ์๊ฒ ๋์์ต๋๋ค.
์คํ ๋ฆฌ๋ถ ๋์ ์ด์ ์ ๋ฌธ์ ์
1. ์ฝ๋๋ฅผ ๋ณด๊ณ ์ปดํฌ๋ํธ๋ฅผ ๋ ์ฌ๋ฆฌ๊ธฐ ์ด๋ ค์
2. PR์ ๊ผผ๊ผผํ๊ฒ ์์ฑํ๊ณ ์ฝ๋๋ฐ ์ฌ์ฉํ๋ ๋ถํ์ํ๊ฒ ๋์ ์ํต ๋น์ฉ
3. ์ปดํฌ๋ํธ์ UI์ ํ ์คํธ๋ฅผ ์ํด ์ง์ ์คํํด๋ด์ผํ๋ ๋ถํธํจ
Pull Request์์ ์ปดํฌ๋ํธ UI๋ฅผ ํ์ธํ ์ ์์๊น?
ํ์ง๋ง ์์ง ์คํ ๋ฆฌ๋ถ ๋์ ์ด์ ์ ๋ฌธ์ ์ ์ค ๋ง์ง๋ง ๋ฌธ์ ์ ์ธ ์ปดํฌ๋ํธ์ UI์ ํ ์คํธ๋ฅผ ์ํด ์ง์ ์คํํด๋ด์ผํ๋ ๋ถํธํจ์ ๋ํด์๋ ํด๊ฒฐํ์ง ๋ชปํ์ต๋๋ค.
์คํ ๋ฆฌ๋ถ์ ๋์ ํ์ง๋ง ์ฌ์ ํ ์๋์ ๊ฐ์ ๋ถํธํจ์ด ๋ฐ์ํ๊ณ ์์์ต๋๋ค.
์ฝ๋๋ฅผ pull
๋ฐ๊ณ → ์คํ ๋ฆฌ๋ถ์ ๋ก์ปฌ์์ ์คํํ๊ณ → ์ปดํฌ๋ํธ๊ฐ ์ ๋๋ก ์๋ํ๋์ง ํ์ธ
์ด์ฉ์ง ์คํ ๋ฆฌ๋ถ์ ์ฅ์ ์ ๊ทน๋ํํ์ง ๋ชปํ๋ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ์ต๋๋ค
Github Action ์ถ๊ฐํ๊ธฐ
PR๋ก ์ฌ๋ผ์จ ์ปดํฌ๋ํธ ๋ณ๊ฒฝ์ฌํญ์ ๋ฐฐํฌ๋ ํ๊ฒฝ์์ ํ์ธํ ์ ์๋๋ก Github Action์ ์ถ๊ฐํด๋ณด๊ฒ ์ต๋๋ค.
ํฌ๋ก๋งํฑ ๋ช ๋ น์ด๋ฅผ ์์ฑํ๋ฉด ์๋์ ๊ฐ์ ๋ด์ฉ์ด ํฐ๋ฏธ๋์ ๋ํ๋ฉ๋๋ค.
Github Action์ผ๋ก CI๋ฅผ ์ฌ์ฉํ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ package.json์์ chromatic ๋ช ๋ น์ด๋ ์ ๊ฑฐํด์ฃผ์์ต๋๋ค.
1. Chromatic ํ ํฐ ์ค์ ํ๊ธฐ
๋ ํฌ์งํ ๋ฆฌ์ Settings > Secrets > New repository secret์ ํฌ๋ก๋งํฑ ํ ํฐ์ ๋ฃ์ด์ค๋๋ค.
yml ํ์ผ์ ๋ฃ์ด์ค ์ด๋ฆ์ผ๋ก ์์ฑํด์ฃผ์๋ฉด ๋ฉ๋๋ค.
2. .github/workflows/storybook.yml
์์ฑ
- develop ๋ธ๋์น์ PR์ด ์ฌ๋ผ๊ฐ๋ฉด ์คํ ๋ฆฌ๋ถ์ด ๋ฐฐํฌ๋๋๋ก ์ค์ ํ์์ต๋๋ค.
name: Storybook Deployment
run-name: ${{ github.actor }}์ ์คํ ๋ฆฌ๋ถ ๋ฐฐํฌ
on:
pull_request:
branches:
- develop
jobs:
storybook:
runs-on: ubuntu-20.04
outputs:
status: ${{ job.status }}
steps:
- name: checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: cache dependencies
id: cache
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-storybook
- name: depedency install
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci
- name: publish to chromatic
id: chromatic
uses: chromaui/action@v1
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
์ถ๊ฐ๋ก PR ์ฝ๋ฉํธ๋ก ๋ฐ๋ก ์คํ ๋ฆฌ๋ถ ๋ฐฐํฌ ๋งํฌ๋ฅผ ํ์ธํ ์ ์๋๋ก ์ก์ ์ ์ถ๊ฐํด์ฃผ์์ต๋๋ค.
...
jobs:
storybook:
runs-on: ubuntu-20.04
outputs:
status: ${{ job.status }}
steps:
...
- name: comment PR
uses: thollander/actions-comment-pull-request@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: "๐storybook: ${{ steps.chromatic.outputs.storybookUrl }}"
์ ์ก์ ์ ์คํํ๋ฉด develop ๋ธ๋์น์ PR์ด ์ฌ๋ผ๊ฐ๋ฉด ๊นํ๋ธ ๋ด์ด ์ฝ๋ฉํธ๋ฅผ ๋จ๊ฒจ์ค๋๋ค
์ฐธ๊ณ ๋ก ์ฝ๋ฉํธ๋ฅผ ๋จ๊ธฐ๊ธฐ ์ํด์๋ Workflow permissions๋ฅผ Read and write๋ก ์ค์ ํด์ฃผ์ด์ผ ์ ์์ ์ผ๋ก ์ก์ ์ด ์๋ํฉ๋๋ค
์ฐธ๊ณ
https://storybook.js.org/tutorials/intro-to-storybook/react/ko/deploy/
Storybook Tutorials
Learn how to develop UIs with components and design systems. Our in-depth frontend guides are created by Storybook maintainers and peer-reviewed by the open source community.
storybook.js.org
https://www.chromatic.com/docs/github-actions
Introduction • Chromatic docs
Chromatic is a cloud based toolchain built around Storybook to help teams develop robust UI components faster, together.
www.chromatic.com