Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromatic CI 파이프라인 구축 #25

Merged
merged 15 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# .github/workflows/chromatic.yml

name: 'Chromatic'

on: workflow_call

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-chromatic
cancel-in-progress: true
Comment on lines +7 to +9
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

동시성 그룹을 설정할 수 있는 건 처음 알았네요! 이렇게 되면 pull request, push가 동시에 일어난다해도 하나만 작동해서 두번 chromatic에 게시될 일은 없게 됩니다:)


permissions:
actions: write
contents: read

jobs:
chromatic:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install dependencies
# ⚠️ Pick one of these, matching the package manager for your project
# run: npm ci
# run: pnpm install
run: yarn install --immutable --immutable-cache --check-cache
Comment on lines +25 to +28
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후에 패키지 매니저를 pnpm으로 변경할 경우 변경 필요


- name: Run Chromatic
uses: chromaui/action@latest
with:
# ⚠️ Make sure to configure a `CHROMATIC_PROJECT_TOKEN` repository secret
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
workingDir: apps/docs
onlyChanged: true # 👈 Required option to enable TurboSnap / 터보스냅이 필요할지는 테스트 여부에 따라 상이할 예정
exitZeroOnChanges: true # 👈 Option to prevent the workflow from failing
autoAcceptChanges: 'master' # 👈 Option to accept all changes on master
# ignoreLastBuildOnBranch: 'my-branch' # 👈 Option to ignore the last build on target branch
Comment on lines +32 to +39
Copy link
Member Author

@minzzang144 minzzang144 May 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • projectToken: 크로마틱에서 발급해주는 토큰으로 인증할 때 필요. 없으면 절대 안되는 필수값
  • workingDir: 모노레포를 위해 디렉토리 설정 가능
  • onlyChanged: 크로마틱이 터보스냅을 사용해서 변경된 스토리에 한해서 스냅샷을 생성합니다. 대신 변경된 스토리 x 1.4~5배 정도 스냅샷을 더 생성한다고 하는데 어떤 것이 더 효율적인지는 계속 테스트를 해봐야 알 것 같습니다. 지금은 저와 이랑 둘만 사용하기 때문에 크게 문제되는 부분은 아닐 것 같아서 추가했습니다.
  • exitZeroOnChanges: 개발 환경에서 변경 사항이 있으면 빌드하지만 CI 환경에서는 시간이 꽤 소요되기 때문에 변경점이 있다면 빌드를 생략해주고 성공여부를 OK로 반환하는 옵션입니다.
  • autoAcceptChanges: merge/rebase 할 때 생기는 커밋에 대해 스냅샷을 생성하지 않고 자동으로 성공으로 처리
  • ignoreLastBuildOnBranch: 이 옵션은 혹시 사용할 일이 있을지 몰라서 주석으로 추가하였습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

하나하나 꼼꼼하게 설명까지 ㄷ ㄷ

43 changes: 43 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# .github/workflows/deploy.yml
name: 🚀 Deploy

on:
push:
branches:
- master
- devlop
- feature/**
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
actions: write
contents: read

jobs:
changed-files:
runs-on: ubuntu-latest
name: changed-files
outputs:
all_changed_files: ${{ steps.changed-files.outputs.all_changed_files }}
any_changed: ${{ steps.changed-files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
apps/docs/**

chromatic:
name: Run visual tests
needs: [changed-files]
if: ${{ needs.changed-files.outputs.any_changed == 'true' }}
uses: ./.github/workflows/chromatic.yml
secrets: inherit
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ out
coverage

# Turbo
.turbo
.turbo

# Env
.env
32 changes: 23 additions & 9 deletions apps/docs/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
import fs from 'fs';
import path from 'path';
import path, { dirname, join } from 'path';
import type { StorybookConfig } from '@storybook/react-webpack5';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';

function findStories() {
const filePattern = /^.*\.stories\.tsx$/;
const pkgStoriesPath = `./stories`;
const files = fs.readdirSync(`${pkgStoriesPath}`);
const pkgStoriesPath = `../stories`;
const files = fs.readdirSync(path.resolve(__dirname, pkgStoriesPath));

return files
.filter((file) => filePattern.test(file))
.map((file) => `../${pkgStoriesPath}/${file}`);
.map((file) => `${pkgStoriesPath}/${file}`);
}

const config: StorybookConfig = {
stories: [...findStories()],

addons: [
'@storybook/addon-links',
'@chromatic-com/storybook',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
'@storybook/addon-links',
'@storybook/addon-webpack5-compiler-swc',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vite -> webpack 변경하면서 babel -> swc 교체해봤습니다!

'storybook-dark-mode',
],

framework: {
name: '@storybook/react-webpack5',
options: {},
},
docs: {
autodocs: 'tag',
},

docs: {},

// NOTE: https://storybook.js.org/docs/configure/compilers#the-swc-compiler-doesnt-work-with-react
swc: () => ({
jsc: {
transform: {
react: {
runtime: 'automatic',
},
},
},
}),

webpackFinal: async (config) => {
if (config.resolve) {
config.resolve.plugins = [
Expand All @@ -37,7 +52,6 @@ const config: StorybookConfig = {
}),
];
}

return config;
},
};
Expand Down
1 change: 0 additions & 1 deletion apps/docs/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function CustomDjProvider(props: PropsWithChildren) {

const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v7 -> v8 업그레이드 하면서 deprecated 될 옵션

controls: {
matchers: {
color: /(background|color)$/i,
Expand Down
7 changes: 0 additions & 7 deletions apps/docs/babel.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions apps/docs/chromatic.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"projectId": "Project:664871fb3ef2a81e82b1f66f",
"autoAcceptChanges": "master",
"onlyChanged": true,
"exitOnceUploaded": true,
"storybookBaseDir": "apps/docs",
"zip": true
}
34 changes: 19 additions & 15 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@
"homepage": "",
"license": "ISC",
"scripts": {
"dev": "storybook dev -p 6006",
"build": "storybook build --docs",
"storybook": "storybook dev -p 6006",
"build": "storybook build",
"build-storybook": "storybook build",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: build 스크립트가 있는데 왜 build-storybook 스크립트가 또 있을까?
A: chromatic cli는 기본적으로 build-storybook 이라는 명령어를 찾아 storybook을 빌드할 수 있도록 합니다. chromatic cli에서 제공하는 옵션 중 --build-script-name이 존재하지만 chormatic에서는 이 옵션을 제대로 읽지 못하는 에러가 있습니다.
Q: build 대신 build-storybook를 사용하면 안될까?
A: yarn run multitask를 사용할 수 없게됩니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조금 더 찾아봐야할 것 같아요,
지금 당장 생각나는 방식은

"build": yarn run build-storybook ..?

"preview": "serve storybook-static",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf storybook-static"
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf storybook-static",
"chromatic": "dotenv -e apps/docs/.env chromatic --project-token=$CHROMATIC_PROJECT_TOKEN"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 명령어를 사용하기 위해서는 .env 파일에 CHROMATIC_PROJECT_TOKEN 값이 필요합니다.
추후 따로 공유 예정

},
"dependencies": {
"@danji/components": "^0.0.0",
"@danji/css": "^0.0.0",
"@danji/styled": "^0.0.0",
"@danji/css": "^0.0.0"
"@storybook/test": "^8.0.9"
},
"devDependencies": {
"serve": "^14.2.1",
"@storybook/addon-essentials": "^7.0.18",
"@storybook/addon-interactions": "^7.0.18",
"@storybook/addon-links": "^7.0.18",
"@storybook/blocks": "^7.0.18",
"@storybook/cli": "^7.0.18",
"@storybook/react": "^7.0.18",
"@storybook/react-webpack5": "^7.0.18",
"@storybook/testing-library": "^0.0.14-next.2",
"@chromatic-com/storybook": "^1.3.3",
"@storybook/addon-essentials": "^8.1.1",
"@storybook/addon-interactions": "^8.1.1",
"@storybook/addon-links": "^8.1.1",
"@storybook/addon-webpack5-compiler-swc": "^1.0.2",
"@storybook/blocks": "^8.1.1",
"@storybook/cli": "^8.1.1",
"@storybook/react": "^8.1.1",
"@storybook/react-webpack5": "^8.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.0.18",
"storybook-dark-mode": "^3.0.3",
"serve": "^14.2.1",
"storybook": "^8.0.9",
"storybook-dark-mode": "^4.0.1",
"tsconfig-paths-webpack-plugin": "^4.1.0"
},
"eslintConfig": {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"cross-env": "^7.0.3",
"dotenv-cli": "^7.4.2",
"eslint": "^8.41.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
Expand All @@ -26,7 +27,7 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-storybook": "^0.6.12",
"eslint-plugin-storybook": "^0.8.0",
"husky": "^9.0.11",
"hygen": "^6.2.11",
"jest": "^29.5.0",
Expand Down
Loading