Skip to content

๐Ÿชต 1. Storybook PR Preview ๋ฐ ๋ฐฐํฌํ•˜๊ธฐ

choiseona edited this page Dec 5, 2024 · 1 revision

Storybook์ด๋ž€?

UI ์ปดํฌ๋„ŒํŠธ์™€ ํŽ˜์ด์ง€๋ฅผ ๋…๋ฆฝ์ ์œผ๋กœ ๋นŒ๋“œํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋ก ํŠธ์—”๋“œ ์ž‘์—… ํ™˜๊ฒฝ์ž…๋‹ˆ๋‹ค. ์ „์ฒด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ ๋„ ์ ‘๊ทผํ•˜๊ธฐ ์–ด๋ ค์šด ์ƒํƒœ๋‚˜ ์˜ˆ์™ธ์ ์ธ ์ผ€์ด์Šค๋ฅผ ๊ฐœ๋ฐœํ•˜๊ณ  ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค๋‹ˆ๋‹ค.

Storybook ๋„์ž… ์ด์œ 

์ด์ „ ํ”„๋กœ์ ํŠธ์—์„œ UI ์ž‘์—…์„ ๋‚˜๋ˆ ์„œ ์ง„ํ–‰ํ–ˆ์„ ๋•Œ ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ๋ฌธ์„œํ™”๋ฅผ ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜, ํ•˜๋”๋ผ๋„ ๋…ธ์…˜์— ๋ฌธ์„œํ™”๋ฅผ ํ•ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‹ค๋ณด๋‹ˆ ์ด๋ฏธ ๋งŒ๋“ค์–ด์ง„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ์Œ์—๋„ ํ™•์ธํ•˜์ง€ ๋ชปํ•˜๊ณ  ๋˜‘๊ฐ™์€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค๊ฒŒ ๋˜๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ•˜๊ฑฐ๋‚˜, ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด ๋ฌธ์„œ๋„ ์ˆ˜๋™์œผ๋กœ ๋ณ€๊ฒฝํ•ด์ค˜์•ผํ•˜๋Š” ๋น„ํšจ์œจ์ด ๋ฐœ์ƒํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์—์„œ ์–ด๋–ป๊ฒŒ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ณ  ๋ฌธ์„œํ™”ํ•  ๊ฒƒ์ธ์ง€ ๊ณ ๋ฏผํ•œ ๊ฒฐ๊ณผ storybook์„ ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๋ฐฐํฌ ๋ฐฉ๋ฒ•1. chromatic

๋ฐฐํฌ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด์•˜๋Š”๋ฐ chromatic์œผ๋กœ ๋ฐฐํฌํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ๊ฐ„๋‹จํ•ด๋ณด์˜€๊ณ  ๋ณดํŽธ์ ์ด์—ˆ์œผ๋‚˜ ๋„ค๋ถ€์บ  organization ๊ถŒํ•œ ๋ฌธ์ œ๋กœ ๋ฐฐํฌ ๋ถˆ๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

image

๋ฐฐํฌ ๋ฐฉ๋ฒ•2. GitHub Pages์— ๋ฐฐํฌ

chromatic์— ๋ฐฐํฌํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•ด GitHub Pages์— ์ง์ ‘ ๋ฐฐํฌํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  main์ด๋‚˜ develop ๋ธŒ๋žœ์น˜์— ๋Œ€ํ•œ ๋ฐฐํฌ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ vercel์ฒ˜๋Ÿผ PR์ด ์ƒ์„ฑ๋์„ ๋•Œ storybook preview๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์œผ๋ฉด ์ข‹๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ฆฌ๋ทฐ์–ด๋“ค์ด PR์„ ์ฐธ๊ณ ํ•  ๋•Œ ๋‹จ์ˆœํžˆ ์‚ฌ์ง„์ด๋‚˜ ์˜์ƒ์„ ์ฒจ๋ถ€ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•ด์„œ ํฐ ์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

main/develop Storybook ๋ฐฐํฌ ์ฝ”๋“œ ์ „๋ฌธ
    name: Deploy Storybook Production
    
    on:
      push:
        branches:
          - main
          - develop
        paths:
          - client/**
    
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
      cancel-in-progress: true
    
    defaults:
      run:
        working-directory: ./client
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
        permissions:
          contents: write
    
        steps:
          - name: Checkout
            uses: actions/checkout@v4
    
          - name: Setup pnpm
            uses: pnpm/action-setup@v3
            with:
              version: 9
              run_install: false
    
          - name: Setup Node
            uses: actions/setup-node@v4
            with:
              node-version: 20
              cache: "pnpm"
              cache-dependency-path: "./client/pnpm-lock.yaml"
    
          - name: Install dependencies
            run: pnpm install
    
          - name: Build storybook
            run: pnpm run build-storybook
    
          - name: Deploy
            uses: peaceiris/actions-gh-pages@v3
            with:
              github_token: ${{ secrets.GITHUB_TOKEN }}
              publish_dir: ./client/storybook-static
              destination_dir: ${{ github.ref == 'refs/heads/main' && 'storybook' || 'storybook-develop' }}
              keep_files: true
              commit_message: "docs: deploy storybook"
    
Storybook Preview ๋ฐฐํฌ ์ฝ”๋“œ ์ „๋ฌธ
    name: Deploy Storybook Preview
    
    on:
      pull_request:
        types:
          - opened
          - synchronize
          - reopened
          - closed
        branches:
          - main
          - develop
        paths:
          - client/**
    
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.number }}
      cancel-in-progress: true
    
    defaults:
      run:
        working-directory: ./client
    
    jobs:
      deploy-preview:
        if: github.event.action != 'closed'
        runs-on: ubuntu-latest
        permissions:
          contents: write
          pull-requests: write
        steps:
          - name: Checkout
            uses: actions/checkout@v4
    
          - name: Setup pnpm
            uses: pnpm/action-setup@v3
            with:
              version: 9
              run_install: false
    
          - name: Setup Node
            uses: actions/setup-node@v4
            with:
              node-version: 20
              cache: "pnpm"
              cache-dependency-path: "./client/pnpm-lock.yaml"
    
          - name: Install dependencies
            run: pnpm install
    
          - name: Build storybook
            run: pnpm run build-storybook
    
          - name: Deploy
            uses: peaceiris/actions-gh-pages@v3
            with:
              github_token: ${{ secrets.GITHUB_TOKEN }}
              publish_dir: ./client/storybook-static
              destination_dir: storybook/preview-${{ github.event.number }}
              keep_files: true
              commit_message: "docs: deploy storybook-preview"
    
          - name: Comment Preview URL
            uses: actions/github-script@v6
            with:
              script: |
                const previewUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/storybook/preview-${context.issue.number}`
                github.rest.issues.createComment({
                  issue_number: context.issue.number,
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  body: `๐Ÿ“š Storybook preview deployed to: [Visit Storybook Preview](${previewUrl})`
                })
    
      cleanup-preview:
        if: github.event.action == 'closed'
        runs-on: ubuntu-latest
    
        permissions:
          contents: write
          pull-requests: write
    
        defaults:
          run:
            working-directory: .
    
        steps:
          - name: Checkout
            uses: actions/checkout@v4
            with:
              ref: gh-pages
    
          - name: Delete preview directory
            run: |
              if [ -d "storybook/preview-${{ github.event.number }}" ]; then
                git config --global user.name 'github-actions[bot]'
                git config --global user.email 'github-actions[bot]@users.noreply.github.com'
                git rm -rf "storybook/preview-${{ github.event.number }}"
                git commit -m "docs: remove storybook preview for PR #${{ github.event.number }}"
                git push origin gh-pages
              fi
    
          - name: Comment Cleanup Notification
            uses: actions/github-script@v6
            with:
              script: |
                github.rest.issues.createComment({
                  issue_number: context.issue.number,
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  body: `๐Ÿงน Storybook preview for PR #${context.issue.number} has been removed.`
                })
    

main/develop storybook ๋ฐฐํฌ(storybook-ci-cd.yml)

main ๋ธŒ๋žœ์น˜, develop ๋ธŒ๋žœ์น˜์— push๋  ๋•Œ storybook์„ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.

  • main ๋ธŒ๋žœ์น˜ โ†’ ${GITHUB_PAGES_URL}/ storybook ๊ฒฝ๋กœ์— ๋ฐฐํฌ
  • develop ๋ธŒ๋žœ์น˜ โ†’ ${GITHUB_PAGES_URL}/ storybook-develop ๊ฒฝ๋กœ์— ๋ฐฐํฌ

trigger ์กฐ๊ฑด

on:
  push:
    branches:
      - main
      - develop
    paths:
      - client/**
  • main ๋˜๋Š” develop ๋ธŒ๋žœ์น˜์— push๊ฐ€ ์žˆ์„ ๋•Œ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • client ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์žˆ์„ ๋•Œ๋งŒ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์„ค์ •

defaults:
  run:
    working-directory: ./client
  • working-directory: ./client
    • ์Šคํ† ๋ฆฌ๋ถ์€ client ์ฝ”๋“œ์™€ ๋งŒ ๊ด€๋ จ์ด ์žˆ์œผ๋ฏ€๋กœ ๋ชจ๋“  ๋ช…๋ น์–ด๋Š” ./client ๋””๋ ‰ํ† ๋ฆฌ์—์„œ ์‹คํ–‰ํ•˜๋„๋ก ํ•จ

์ž‘์—… ๋‹จ๊ณ„

deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: write
  • deploy
    • deploy๋ผ๋Š” ์ด๋ฆ„์˜ ์ž‘์—…์„ ์ •์˜
  • runs-on: ubuntu-latest
    • Ubuntu ์ตœ์‹  ๋ฒ„์ „์˜ ๊ฐ€์ƒ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰
  • permissions
    • contents: write ๋ฐฐํฌ๋ฅผ ์œ„ํ•ด ์ €์žฅ์†Œ์— ์“ฐ๊ธฐ ๊ถŒํ•œ์„ ๋ถ€์—ฌ
  1. ์ฒดํฌ์•„์›ƒ
- name: Checkout
  uses: actions/checkout@v4
  • uses: actions/checkout@v4
    • actions/checkout@v4 ์•ก์…˜์„ ํ†ตํ•ด ์ €์žฅ์†Œ์˜ ์ฝ”๋“œ๋ฅผ workflow ์‹คํ–‰ ํ™˜๊ฒฝ(๊ฐ€์ƒ ํ™˜๊ฒฝ)์œผ๋กœ ๋ณต์‚ฌ
  1. PNPM ์„ค์ •
- name: Setup pnpm
  uses: pnpm/action-setup@v2
  with:
    version: 9           
    run_install: false    
  • uses: pnpm/action-setup@v2
    • pnpm/action-setup@v2 ์•ก์…˜์„ ํ†ตํ•ด pnpm์„ ์„ค์น˜
  • run_install: false
    • ์ž๋™ ์˜์กด์„ฑ ์„ค์น˜ ๋น„ํ™œ์„ฑํ™”
    • pnpm install ๋ช…๋ น์–ด๋ฅผ ๋ณ„๋„ ์Šคํ…์œผ๋กœ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•จ
    • ์˜์กด์„ฑ ์„ค์น˜ ๊ณผ์ •์˜ ์„ธ๋ฐ€ํ•œ ์ œ์–ด ๊ฐ€๋Šฅ(ํŒจํ‚ค์ง€ ์บ์‹œ ๋“ฑ)
  1. Node ์„ค์ •
- name: Setup Node            
  uses: actions/setup-node@v4   
  with:                        
    node-version: 20           
    cache: "pnpm"             
    cache-dependency-path: "./client/pnpm-lock.yaml" 
  • uses: actions/setup-node@v4
    • actions/setup-node@v4 ์•ก์…˜์„ ํ†ตํ•ด Node.js๋ฅผ ์„ค์น˜
  • cache: "pnpm"
    • pnpm ํŒจํ‚ค์ง€๋“ค์˜ ์บ์‹œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉ
  • cache-dependency-path: "./client/pnpm-lock.yaml"
    • โ€˜./client/pnpm-lock.yamlโ€™ ํŒŒ์ผ์„ ํ™•์ธํ•ด์„œ
      • ์บ์‹œ๊ฐ€ ์žˆ์œผ๋ฉด ์บ์‹œ๋œ ํŒจํ‚ค์ง€ ์˜์กด์„ฑ์„ ์‚ฌ์šฉ
      • ์บ์‹œ๊ฐ€ ์—†์œผ๋ฉด ์ƒˆ๋กœ์šด ์บ์‹œ๋ฅผ ์ƒ์„ฑ
  1. ์˜์กด์„ฑ ์„ค์น˜
- name: Install dependencies
  run: pnpm install
  • run: pnpm install
    • package.json์— ๋ช…์‹œ๋œ ๋ชจ๋“  ์˜์กด์„ฑ ํŒจํ‚ค์ง€๋“ค์„ ์„ค์น˜
  1. Storybook ๋นŒ๋“œ
- name: Build storybook
  run: pnpm run build-storybook
  • run: pnpm run build-storybook
    • Storybook์„ ์ •์  ํŒŒ์ผ๋กœ ๋นŒ๋“œ
    • client/storybook-static ๋””๋ ‰ํ† ๋ฆฌ์— ๋นŒ๋“œ ๊ฒฐ๊ณผ๋ฌผ์ด ์ƒ์„ฑ๋จ
  1. ๋ฐฐํฌ
- name: Deploy
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}  
    publish_dir: ./client/storybook-static 
    destination_dir: ${{ github.ref == 'refs/heads/main' && 'storybook' || 'storybook-develop' }}
    keep_files: true                           
    commit_message: "docs: deploy storybook"    
  • uses: peaceiris/actions-gh-pages@v3
    • ์ •์  ์›น์‚ฌ์ดํŠธ๋ฅผ Github Pages๋กœ ์ž๋™ ๋ฐฐํฌํ•˜๋Š” ์•ก์…˜
  • github_token: ${{ secrets.GITHUB_TOKEN }}
    • GitHub์—์„œ ์ž๋™์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ์ธ์ฆ ํ† ํฐ
    • ์ €์žฅ์†Œ์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์–ป๋Š”๋ฐ ์‚ฌ์šฉ
  • publish_dir: ./client/storybook-static
    • ์Šคํ† ๋ฆฌ๋ถ ๋นŒ๋“œ ๊ฒฐ๊ณผ๋ฌผ์ด ์ €์žฅ๋œ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ
    • ์ด ๋””๋ ‰ํ† ๋ฆฌ์˜ ๋‚ด์šฉ์ด GitHub Pages์— ๋ฐฐํฌ๋จ
  • destination_dir: ${{ github.ref == 'refs/heads/main' && 'storybook' || 'storybook-develop' }}
    • GitHub Pages์— ๋ฐฐํฌ๋  ๊ฒฝ๋กœ
    • main ๋ธŒ๋žœ์น˜๋ฉด /storybook ์— ๋ฐฐํฌ
    • develop ๋ธŒ๋žœ์น˜๋ฉด /storybook-develop ์— ๋ฐฐํฌ
  • keep_files: true
    • ๊ธฐ์กด์— ๋ฐฐํฌ๋œ ํŒŒ์ผ์„ ์œ ์ง€ํ•˜๊ณ  ์ƒˆ ํŒŒ์ผ๋งŒ ์—…๋ฐ์ดํŠธ
    • false๋ฉด ๊ธฐ์กด ํŒŒ์ผ์„ ๋ชจ๋‘ ์‚ญ์ œํ•˜๊ณ  ์ƒˆ๋กœ ๋ฐฐํฌ
  • commit_message: "docs: deploy storybookโ€
    • gh-pages ๋ธŒ๋žœ์น˜์— ์ƒ์„ฑ๋˜๋Š” ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€
    • GitHub Actions ๋ด‡์˜ ์ด๋ฆ„์œผ๋กœ ์ปค๋ฐ‹๋จ

๊ฐœ์„ 

  1. concurrency ์„ค์ •
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
  • ๊ฐ™์€ ๋ธŒ๋žœ์น˜์— ์—ฌ๋Ÿฌ ๋ฒˆ ๋น ๋ฅด๊ฒŒ pushํ•  ๋•Œ ๋ถˆํ•„์š”ํ•œ ์ค‘๋ณต ์‹คํ–‰์„ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.
  • ์ด์ „ ์‹คํ–‰์ค‘์ธ workflow๋ฅผ ์ž๋™์œผ๋กœ ์ทจ์†Œํ•˜๊ณ  ์ตœ์‹  push์— ๋Œ€ํ•ด์„œ๋งŒ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  1. ~~Storybook ๋นŒ๋“œ ์บ์‹ฑ~~
- name: Cache Storybook build
  uses: actions/cache@v3
  with:
    path: ./client/storybook-static
		key: storybook-build-${{ hashFiles('client/**/*.{js,jsx,ts,tsx,mdx,css}') }}
  • ์ถ”๊ฐ€ํ•ด๋ดค๋‹ค๊ฐ€ ์บ์‹œ ์ƒ์„ฑํ•˜๋Š” ๊ฑฐ์—๋งŒ 2๋ถ„์ด ๋„˜๊ฒŒ ๊ฑธ๋ ค์„œ ๋‹ค์‹œ ๋„๋ฃจ๋ฌตํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ํŒŒ์ผ ํ•˜๋‚˜๋งŒ ๋ณ€๊ฒฝํ•ด๋„ ์บ์‹œ ๋ฏธ์Šค์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฌด์˜๋ฏธํ•œ ์บ์‹ฑ์ด์–ด์„œ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

Preview ๋ฐฐํฌ(storybook-preview-ci-cd.yml)

main ๋ธŒ๋žœ์น˜๋‚˜ develop ๋ธŒ๋žœ์น˜์— PR์„ ์ƒ์„ฑ, ์ˆ˜์ •ํ•˜๋Š” ๊ฒฝ์šฐ preview๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

  • gh-pages ๋ธŒ๋žœ์น˜์˜ /storybook/preview-${PR} ํด๋” ์ƒ์„ฑ

pr์ด ๋‹ซํžˆ๋ฉด(merged ๋˜๋Š” closed) preview๋Š” ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.

  • gh-pages ๋ธŒ๋žœ์น˜์˜ /storybook/preview-${PR} ํด๋”๋ฅผ ์‚ญ์ œ

trigger ์„ค์ •

on:
  pull_request:
    types:            
      - opened        
      - synchronize  
      - reopened     
      - closed     
    branches:         
      - main
      - develop
    paths:          
      - client/**    
  • PR์ด ์ฒ˜์Œ ์ƒ์„ฑ๋์„ ๋•Œ, PR์— ์ƒˆ๋กœ์šด commit์ด push๋  ๋•Œ, ๋‹ซํ˜”๋˜ PR์ด ๋‹ค์‹œ ์—ด๋ฆด ๋•Œ, PR์ด merge ๋˜๊ฑฐ๋‚˜ ๋‹ซํž ๋•Œ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • main/develop ๋ธŒ๋žœ์น˜๋กœ ๊ฐ€๋Š” PR์— ๋Œ€ํ•ด์„œ๋งŒ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • client ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์žˆ์„ ๋•Œ๋งŒ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์„ค์ •

defaults:
  run:
    working-directory: ./client
  • working-directory: ./client
    • ์Šคํ† ๋ฆฌ๋ถ์€ client ์ฝ”๋“œ์™€๋งŒ ๊ด€๋ จ์ด ์žˆ์œผ๋ฏ€๋กœ ๋ชจ๋“  ๋ช…๋ น์–ด๋Š” ./client ๋””๋ ‰ํ† ๋ฆฌ์—์„œ ์‹คํ–‰ํ•˜๋„๋ก ํ•จ

์ž‘์—… ๋‹จ๊ณ„ - ์ž‘์—…1 (deploy-preview)

  deploy-preview:
    if: github.event.action != 'closed'
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
  • if: github.event.action != 'closed'
    • PR์ด ์ƒ์„ฑ๋์„ ๋•Œ, ์ƒˆ๋กœ์šด commit์ด push ๋์„ ๋•Œ, ๋‹ค์‹œ ์—ด๋ฆด๋•Œ๋งŒ ์‹คํ–‰.(PR์ด merge ๋˜๊ฑฐ๋‚˜ ๋‹ซํž ๋•Œ๋ฅผ ์ œ์™ธ)
  • runs-on: ubuntu-latest
    • Ubuntu ์ตœ์‹  ๋ฒ„์ „์˜ ๊ฐ€์ƒ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰
  • contents: write
    • gh-pages ๋ฐฐํฌ๋ฅผ ์œ„ํ•ด ์ €์žฅ์†Œ์— ์“ฐ๊ธฐ ๊ถŒํ•œ์„ ๋ถ€์—ฌ
  • pull-requests:write:
    • PR์— preview URL ์ฝ”๋ฉ˜ํŠธ์™€ ๋ฐฐํฌ ์ƒํƒœ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์“ฐ๊ธฐ ๊ถŒํ•œ์„ ๋ถ€์—ฌ

1~5**. 1.์ฒดํฌ์•„์›ƒ ~ 5.Storybook ๋นŒ๋“œ๊นŒ์ง€ ์œ„์™€ ๋™์ผํ•˜๋‹ค.**

  1. ๋ฐฐํฌ
- name: Deploy
 uses: peaceiris/actions-gh-pages@v3
 with:
   github_token: ${{ secrets.GITHUB_TOKEN }}
   publish_dir: ./client/storybook-static
   destination_dir: storybook/preview-${{ github.event.number }}
   keep_files: true
   commit_message: "docs: deploy storybook-preview
  • uses: peaceiris/actions-gh-pages@v3
    • ์ •์  ์›น์‚ฌ์ดํŠธ๋ฅผ Github Pages๋กœ ์ž๋™ ๋ฐฐํฌํ•˜๋Š” ์•ก์…˜
  • github_token: ${{ secrets.GITHUB_TOKEN }}
    • GitHub์—์„œ ์ž๋™์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ์ธ์ฆ ํ† ํฐ
    • ์ €์žฅ์†Œ์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์–ป๋Š”๋ฐ ์‚ฌ์šฉ
  • publish_dir: ./client/storybook-static
    • ์Šคํ† ๋ฆฌ๋ถ ๋นŒ๋“œ ๊ฒฐ๊ณผ๋ฌผ์ด ์ €์žฅ๋œ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ
    • ์ด ๋””๋ ‰ํ† ๋ฆฌ์˜ ๋‚ด์šฉ์ด GitHub Pages์— ๋ฐฐํฌ๋จ
  • destination_dir: storybook/preview-${{ github.event.number }}
    • GitHub Pages์— ๋ฐฐํฌ๋  ๊ฒฝ๋กœ
    • PR ๋ฒˆํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ PR๋ณ„ ๊ณ ์œ ํ•œ preview ๊ฒฝ๋กœ ์ƒ์„ฑ
    • ์˜ˆ: PR #123 โ†’ /storybook/preview-123
  • keep_files: true
    • ๊ธฐ์กด์— ๋ฐฐํฌ๋œ ํŒŒ์ผ์„ ์œ ์ง€ํ•˜๊ณ  ์ƒˆ ํŒŒ์ผ๋งŒ ์—…๋ฐ์ดํŠธ
    • false๋ฉด ๊ธฐ์กด ํŒŒ์ผ์„ ๋ชจ๋‘ ์‚ญ์ œํ•˜๊ณ  ์ƒˆ๋กœ ๋ฐฐํฌ
  • commit_message: "docs: deploy storybookโ€
    • gh-pages ๋ธŒ๋žœ์น˜์— ์ƒ์„ฑ๋˜๋Š” ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€
    • GitHub Actions ๋ด‡์˜ ์ด๋ฆ„์œผ๋กœ ์ปค๋ฐ‹๋จ
  1. Preview URL ์ฝ”๋ฉ˜ํŠธ
- name: Comment Preview URL   
 uses: actions/github-script@v6    
 with:
   script: |
     const previewUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/storybook/preview-${context.issue.number}`
     github.rest.issues.createComment({
       issue_number: context.issue.number,  
       owner: context.repo.owner,        
       repo: context.repo.repo,          
       body: `๐Ÿ“š Storybook preview deployed to: [Visit Storybook Preview](${previewUrl})`  
     })
  • uses: actions/github-script@v6
    • GitHub API๋ฅผ JavaScript๋กœ ์ง์ ‘ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์•ก์…˜
    • PR์— ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋‹ฌ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
  • github.rest.issues.createComment()
    • PR์— ์ฝ”๋ฉ˜ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” GitHub API ํ˜ธ์ถœ
    • ํŒŒ๋ผ๋ฏธํ„ฐ
      • issue_number: PR ๋ฒˆํ˜ธ
      • owner: GitHub ๊ณ„์ •/์กฐ์ง ์ด๋ฆ„
      • repo: ์ €์žฅ์†Œ ์ด๋ฆ„
      • body: ๋งˆํฌ๋‹ค์šด ํ˜•์‹์˜ ์ฝ”๋ฉ˜ํŠธ ๋‚ด์šฉ

์ž‘์—… ๋‹จ๊ณ„ - ์ž‘์—…2 (cleanup-preview)

  cleanup-preview:
    if: github.event.action == 'closed'
    runs-on: ubuntu-latest

    permissions:
      contents: write
      pull-requests: write

    defaults:
      run:
        working-directory: .
  • cleanup-preview
    • PR์ด ๋‹ซํ˜”์„ ๋•Œ preview๋ฅผ ์ •๋ฆฌํ•˜๋Š” job
  • if: github.event.action == 'closed'
    • PR์ด ๋‹ซํ˜”์„ ๋•Œ๋งŒ(closed or merged) ์‹คํ–‰
  • runs-on: ubuntu-latest
    • ์ตœ์‹  Ubuntu ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰
    • GitHub Actions ์‹คํ–‰ ํ™˜๊ฒฝ ์ง€์ •
  • permissions
    • contents:write ์ €์žฅ์†Œ ๋‚ด์šฉ ์ˆ˜์ • ๊ถŒํ•œ
    • pull-requests:write: PR ์ฝ”๋ฉ˜ํŠธ ์ž‘์„ฑ ๊ถŒํ•œ
  • working-directory: .
    • ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ(.)๋กœ ์„ค์ •
  1. ์ฒดํฌ์•„์›ƒ
- name: Checkout
 uses: actions/checkout@v4 
 with:
   ref: gh-pages 
  • uses: actions/checkout@v4
    • GitHub ์ €์žฅ์†Œ์˜ ์ฝ”๋“œ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ธฐ๋ณธ ์•ก์…˜
  • ref: gh-pages
    • checkoutํ•  ๋ธŒ๋žœ์น˜๋ฅผ ์ง€์ •
    • ๊ธฐ๋ณธ ๋ธŒ๋žœ์น˜๊ฐ€ ์•„๋‹Œ gh-pages ๋ธŒ๋žœ์น˜๋ฅผ ๊ฐ€์ ธ์˜ด
    • GitHub Pages ๋ฐฐํฌ์— ์‚ฌ์šฉ๋˜๋Š” ํŠน์ˆ˜ ๋ธŒ๋žœ์น˜
  1. preview ๋””๋ ‰ํ„ฐ๋ฆฌ ์‚ญ์ œ
- name: Delete preview directory
 run: |
   if [ -d "storybook/preview-${{ github.event.number }}" ]; then
     git config --global [user.name](http://user.name/) 'github-actions[bot]'
     git config --global user.email 'github-actions[bot]@users.noreply.github.com'
     git rm -rf "storybook/preview-${{ github.event.number }}"
     git commit -m "docs: remove storybook preview for PR #${{ github.event.number }}"
     git push origin gh-pages
   fi
  • if [ -d "storybook/preview-${{ github.event.number }}" ]
    • -d: ๋””๋ ‰ํ† ๋ฆฌ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ
    • PR ๋ฒˆํ˜ธ๋กœ ๋œ preview ํด๋”๊ฐ€ ์žˆ๋Š”์ง€ ์ฒดํฌ
  • git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com'
    • Git ์‚ฌ์šฉ์ž ์„ค์ •
    • GitHub Action ๋ด‡์œผ๋กœ ์ปค๋ฐ‹ํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •
  • git rm -rf "storybook/preview-${{ github.event.number }}โ€
    • git rm: Git์—์„œ ํŒŒ์ผ/๋””๋ ‰ํ† ๋ฆฌ ์‚ญ์ œ
    • -rf: ์žฌ๊ท€์ ์œผ๋กœ ๊ฐ•์ œ ์‚ญ์ œ
    • PR ๋ฒˆํ˜ธ์— ํ•ด๋‹นํ•˜๋Š” preview ํด๋” ์‚ญ์ œ
  • git commit -m "docs: remove storybook preview for PR #${{ github.event.number }}"
    • ์‚ญ์ œ ์ž‘์—…์„ ์ปค๋ฐ‹์œผ๋กœ ๊ธฐ๋ก
    • ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€์— PR ๋ฒˆํ˜ธ ํฌํ•จ
  • git push origin gh-pages
    • gh-pages ๋ธŒ๋žœ์น˜์— ๋ณ€๊ฒฝ์‚ฌํ•ญ push
    • preview ์‚ญ์ œ ์™„๋ฃŒ
  1. preview URL cleanup ์ฝ”๋ฉ˜ํŠธ
-name: Comment Cleanup Notification
uses: actions/github-script@v6
with:
  script: |
    github.rest.issues.createComment({
      issue_number: context.issue.number,
      owner: context.repo.owner,
      repo: context.repo.repo,
      body: `๐Ÿงน Storybook preview for PR #${context.issue.number} has been removed.`
    })
  • uses: actions/github-script@v6
    • GitHub API๋ฅผ JavaScript๋กœ ์ง์ ‘ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์•ก์…˜
    • PR์— ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋‹ฌ๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
  • github.rest.issues.createComment()
    • PR์— ์ฝ”๋ฉ˜ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” GitHub API ํ˜ธ์ถœ
    • ํŒŒ๋ผ๋ฏธํ„ฐ
      • issue_number: PR ๋ฒˆํ˜ธ
      • owner: GitHub ๊ณ„์ •/์กฐ์ง ์ด๋ฆ„
      • repo: ์ €์žฅ์†Œ ์ด๋ฆ„
      • body: ๋งˆํฌ๋‹ค์šด ํ˜•์‹์˜ ์ฝ”๋ฉ˜ํŠธ ๋‚ด์šฉ

๊ฐœ์„ 

  1. concurrency ์ถ”๊ฐ€
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.number }}
  cancel-in-progress: true
  • ๊ฐ™์€ PR์— ๋Œ€ํ•ด ์—ฌ๋Ÿฌ ๋ฒˆ ๋น ๋ฅด๊ฒŒ ์ƒ์„ฑ, ์žฌ์˜คํ”ˆ, ์ˆ˜์ •, ์‚ญ์ œ๋  ๋•Œ ๋ถˆํ•„์š”ํ•œ workflow ์ค‘๋ณต ์‹คํ–‰์„ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.
  • ์ด์ „ ์‹คํ–‰์ค‘์ธ workflow๋ฅผ ์ž๋™์œผ๋กœ ์ทจ์†Œํ•˜๊ณ  ์ตœ์‹  PR ์ƒ์„ฑ, ์žฌ์˜คํ”ˆ, ์ˆ˜์ •, ์‚ญ์ œ์— ๋Œ€ํ•œ workflow๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๊ฒฐ๊ณผ

๋ฐฐํฌ๋œ storybook

  • ์•„์ง main ๋ธŒ๋žœ์น˜์— pushํ•˜์ง€ ์•Š์•„์„œ ์ƒ์„ฑ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ๐Ÿ˜…

๋ฐฐํฌ๋œ storybook-develop

storybook

๋ฐฐํฌ๋œ storybook/prevew-${PR๋ฒˆํ˜ธ}

  • PR์ด merge๋˜๋ฉด ๋ฐฐํฌ๋œ ํด๋”๊ฐ€ ์‚ฌ๋ผ์ ธ 404๊ฐ€ ๋œจ๊ฒŒ ๋˜๋ฏ€๋กœ ๋งํฌ๋Š” ์ฒจ๋ถ€ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
  • ์•„๋ž˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ PR์„ ์ƒ์„ฑํ•˜๋ฉด preview๊ฐ€ ๋ฐฐํฌ๋˜๊ณ , PR์ด merge๋˜๋ฉด ๋ฐฐํฌ๋œ preview๊ฐ€ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.

image

์ฐธ๊ณ  ์ž๋ฃŒ

https://storybook.js.org/docs

https://yogjin.tistory.com/106

์ˆ˜์ •๋‹˜์˜ typedoc-ci-cd.yml

๐Ÿ˜Ž ์›จ๋ฒ ๋ฒ ๋ฒ ๋ฒฑ

๐Ÿ‘ฎ๐Ÿป ํŒ€ ๊ทœ์น™

๐Ÿ’ป ํ”„๋กœ์ ํŠธ

๐Ÿชต ์›จ๋ฒ ๋ฒฑ ๊ธฐ์ˆ ๋กœ๊ทธ

๐Ÿช„ ๋ฐ๋ชจ ๊ณต์œ 

๐Ÿ”„ ์Šคํ”„๋ฆฐํŠธ ๊ธฐ๋ก

๐Ÿ“— ํšŒ์˜๋ก

Clone this wiki locally