Storybook ๋ฐฐํฌํ•˜๊ธฐ(Chromatic, Git Action) ๐Ÿ‘ป

Junยท2024๋…„ 12์›” 4์ผ
0

Storybook

๋ชฉ๋ก ๋ณด๊ธฐ
1/1

์ด๋ฒˆ ํ˜‘์—… ํ”„๋กœ์ ํŠธ์—์„œ Storybook์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ, ๋ฉ˜ํ† ๋‹˜๊ป˜์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๋„˜์–ด์„œ Chromatic์œผ๋กœ ๋ฐฐํฌํ•˜๋ฉด ํ˜‘์—… ๊ฐ„์˜ ํšจ์œจ์„ฑ์„ ํ–ฅ์ƒํ•  ์ˆ˜ ์žˆ๊ณ , ๋””์ž์ธ ์‹œ์Šคํ…œ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ถ€๋ถ„์—์„œ ์œ ์šฉํ•˜๋‹ค๊ณ  ํ•˜์…”์„œ ๋ฐฐํฌ๋ฅผ ๊ณ ๋ฏผํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  PR ์‹œ ์ž๋™์œผ๋กœ Chromatic๋„ ๋ฐฐํฌํ•˜๋„๋ก ์„ค์ •ํ•ด๋ณด์•˜๋‹ค. Git Action์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐํฌ ์ฃผ์†Œ๋ฅผ ๋ณด์—ฌ์ฃผ๋„๋ก ํ•˜์˜€๋‹ค.

Chromatic ์‚ฌ์šฉ

Chromatic ์ด๋ž€?

์Šคํ† ๋ฆฌ๋ถ ๊ด€๋ฆฌ์ž๊ฐ€ ๋งŒ๋“  ๋ฌด๋ฃŒ ๋ฐฐํฌ ์„œ๋น„์Šค์ด๋‹ค. ์Šคํ† ๋ฆฌ๋ถ์„ ํด๋ผ์šฐ๋“œ์— ์•ˆ์ „ํ•˜๊ฒŒ ๋ฐฐํฌํ•˜๊ณ  ํ˜ธ์ŠคํŒ…ํ•  ์ˆ˜ ์žˆ๋‹ค.

Chromatic์— ๊ฐ€์ž… ํ›„, ๋ฐฐํฌํ•  ํ”„๋กœ์ ํŠธ๋ฅผ ์„ ํƒํ•œ๋‹ค. ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์—์„œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์„ค์น˜๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. ํ˜„์žฌ pnpm์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ, pnpm์œผ๋กœ ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•˜์˜€๋‹ค.

pnpm install --save-dev chromatic

๊ทธ๋ฆฌ๊ณ , ๋‹ค์‹œ ํ„ฐ๋ฏธ๋„์—์„œ chromatic์— ๋ฐฐํฌํ•˜๋ฉด ๋œ๋‹ค.

npx chromatic --project-token=chpt_ ---


๊ต‰์žฅํžˆ ์‰ฝ๊ฒŒ ๋ฐฐํฌ๊ฐ€ ๋๋‚ฌ๋‹ค! ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์— ์žˆ๋Š” storybook์ด ์ •์ƒ์ ์œผ๋กœ ๋ณด์ด๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

Git Action์„ ํ†ตํ•œ ์ž๋™ ๋ฐฐํฌ

์œ„์˜ chpt_ --- ์˜ ํ† ํฐ์„ ๊นƒํ—ˆ๋ธŒ์— ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•ด๋‹น ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ Secrets and variables์˜ Actions์—์„œ ํ† ํฐ์„ ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ๋‹ค.

๋“ฑ๋ก ํ›„, .github/workflows ํด๋” ์•ˆ์— yml ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค. ๊ณต์‹ ๋ฌธ์„œ์—์„œ๋Š” chromatic.ymlํŒŒ์ผ๋กœ ์ƒ์„ฑํ•˜๋ผ๊ณ  ํ•˜์˜€์ง€๋งŒ, ์ด๋ฆ„์€ ํฌ๊ฒŒ ๋ฌธ์ œ๊ฐ€ ๋˜์ง€ ์•Š๊ธฐ์— ๋‚˜๋Š” storybook.yml์œผ๋กœ ์ƒ์„ฑํ•˜์˜€๋‹ค.

์ฝ”๋“œ์˜ ๊ฒฝ์šฐ ์งฑ์žผ์ด์˜ FE ๊ฐœ๋ฐœ ๊ณต๋ถ€ ์ €์žฅ์†Œ
๋ธ”๋กœ๊ทธ๋ฅผ ์ฐธ๊ณ ํ•˜์˜€๋‹ค. ํ•ด๋‹น ๋ธ”๋กœ๊ทธ์˜ ํ”„๋กœ์ ํŠธ๋Š” yarn์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด์„œ yml์ด yarn ๊ธฐ์ค€์œผ๋กœ ๋˜์–ด์žˆ๋Š”๋ฐ, ๋‚ด๊ฐ€ ์ง„ํ–‰ํ•˜๋Š” ํ”„๋กœ์ ํŠธ์˜ ๊ฒฝ์šฐ pnpm์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ Corepack์„ ํ™œ์„ฑํ™”ํ•˜๊ณ , pnpm ๋ช…๋ น์–ด๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์ง„ํ–‰ํ•˜์˜€๋‹ค.

name: Preview

on:
  pull_request:
    branches: ['main', 'develop']

permissions:
  contents: write
  pages: write
  deployments: write
  id-token: write
  issues: write
  pull-requests: write

jobs:
  storybook-preview:
    runs-on: ubuntu-20.04

    steps:
      - name: ์ €์žฅ์†Œ ์ฒดํฌ์•„์›ƒ
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Corepack ํ™œ์„ฑํ™”
        run: corepack enable

      - name: pnpm ์„ค์น˜
        run: corepack prepare pnpm@latest --activate

      - name: ์บ์‹œ ์ข…์†์„ฑ
        id: cache
        uses: actions/cache@v3
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}-storybook

      - name: ์ข…์†์„ฑ ์„ค์น˜
        if: steps.cache.outputs.cache-hit != 'true'
        run: pnpm install

      - name: Chromatic์— ๊ฒŒ์‹œ
        id: chromatic
        uses: chromaui/action@v1
        with:
          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
          token: ${{ secrets.GITHUB_TOKEN }}
          onlyChanged: true
          autoAcceptChanges: true

      - name: ํ˜„์žฌ ์‹œ๊ฐ„ ๊ฐ€์ ธ์˜ค๊ธฐ
        uses: josStorer/get-current-time@v2
        id: current-time
        with:
          format: 'YYYY๋…„ MM์›” DD์ผ HH์‹œ mm๋ถ„ ss์ดˆ'
          utcOffset: '+09:00'

    outputs:
      storybook_url: ${{ steps.chromatic.outputs.storybookUrl }}
      current_time: ${{ steps.current-time.outputs.formattedTime }}

  github-bot-storybook:
    runs-on: ubuntu-latest
    needs: [storybook-preview]

    steps:
      - name: PR ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ธฐ๊ธฐ
        uses: thollander/actions-comment-pull-request@v2
        with:
          comment_tag: ${{ github.event.number }}-storybook
          message: |
            ๐Ÿ’„ Storybook: ${{ needs.storybook-preview.outputs.storybook_url }}
            ๐Ÿ•– Update: ${{ needs.storybook-preview.outputs.current_time }}


PR ์‹œ ๋ฐฐํฌ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง€๋Š” ๋ชจ์Šต์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค!

์ฐธ๊ณ 

์งฑ์žผ์ด์˜ FE ๊ฐœ๋ฐœ ๊ณต๋ถ€ ์ €์žฅ์†Œ - [GitHub Action / Chromatic] ์Šคํ† ๋ฆฌ๋ถ PR ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋ฐฐํฌ (feat. yarn)

์Šคํ† ๋ฆฌ๋ถ(Storybook) ๋ฐฐํฌํ•˜๊ธฐ ๊ณต์‹๋ฌธ์„œ
Storybook Chromatic ์œผ๋กœ ๋ฐฐํฌํ•˜๊ธฐ

profile
์—ด์‹ฌํžˆ ์•„์ž์•„์ž

0๊ฐœ์˜ ๋Œ“๊ธ€