Skip to content

Commit

Permalink
feat: Add Storybook preview workflow
Browse files Browse the repository at this point in the history
- Setup automatic preview deployment for PRs
- Configure preview cleanup on PR close
  • Loading branch information
choiseona committed Nov 11, 2024
1 parent 2405cb8 commit a69eaba
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/storybook-preview-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Deploy Storybook Preview

on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
branches:
- main
- develop
paths:
- client/**

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@v2
with:
version: 8
run_install: false

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
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/pr-${{ github.event.number }}

- name: Comment Preview URL
uses: actions/github-script@v6
with:
script: |
const previewUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/storybook/preview/pr-${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: [${previewUrl}](${previewUrl})`
})
cleanup-preview:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Delete preview from gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./client/storybook-static
destination_dir: storybook/preview/pr-${{ github.event.number }}
keep_files: false

- 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.`
})

0 comments on commit a69eaba

Please sign in to comment.