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
Monorepo support #197
Comments
Hi there, This feature would be very helpful to me right now. Is there any due date or plan to add this feature to the github action? |
I'm interested in this too. Haven't tried it yet, but in the interim, can just checkout the repo into a subdir, and then copy your own path out of that into the GITHUB_WORKSPACE itself :) # .github/workflows/chromatic.yml
# name of our action
name: 'Chromatic'
# the event that will trigger the action
on: push
# what the action will do
jobs:
test:
# the operating system it will run on
runs-on: ubuntu-latest
# the list of steps that the action will go through
steps:
- uses: actions/checkout@v2 # Note the v2, not v1 from chromatic docs
with:
path: monorepo
# Copy all files (including hidden dotfiles)
- run: |
shopt -s dotglob
cp -r monorepo/mysubdir/* .
- run: yarn
- uses: chromaui/action@v1
# options required to the GitHub chromatic action
with:
projectToken: project-token
token: ${{ secrets.GITHUB_TOKEN }} EDIT: shoot. doesn't work: EDIT2: Ok, this change is a bit kludgey, but seems to work fine: # Move all react files to root (including hidden dotfiles)
- run: |
shopt -s dotglob
git mv react-ui/* ./ -fk |
Actually I implemented this on forked repo within the feature branch but to be honest I couldn't have spare time to follow contribution guidelines and open a PR after doing those and probably I won't have time to do that in near future. Anyone can do these steps is more than welcome 😄 Here you can find the changes I did. Btw it works as expected. |
You could've just disappeared back into the night, so thanks for share back :) if someone else cares enough, they'll pick up where you left off. Thanks for carrying it partway! |
I really need this enhancement. And I must thank @yigityuce Its work for me too, and help me a lot I fork your repo and merge the And set
I wish this will be the real feature in the next version, |
Looks like the fix for this has been implemented: #212. Adding a
Only request to the team is to add this to the github action's docs! |
to fix The "path" argument muyst be one of type string,... reference: chromaui/chromatic-cli#197 (comment)
I changed my only one line
it did not work for me,
|
It didn't work for me though. Still had to explicitly set working directory as well as "workingDir" param, otherwise it fails on "Collecting Storybook metadata" step. |
I think this is not clear for the documentation but if your package.json lives in the monorepo or a subdirectory then you'll need something like:
|
I had issues in a monrepo using yarn v1 workspaces that # ./package.json (root)
{
"scripts": {
"build:storybook": "yarn workspace @my-scope/storybook run build"
},
"devDependencies": {
"rimraf": "^3.0.2"
}
} Storybook project in subfolder (located under # ./packages/storybook/package.json (extract)
{
"name": "@my-scope/storybook",
"scripts": {
"build": "build-storybook -c .storybook",
"prebuild": "rimraf ./storybook-static/*"
},
"dependencies": {
"@storybook/addon-essentials": "^6.3.6",
"@storybook/react": "^6.3.6",
"react": "^17.0.0",
"react-dom": "^17.0.0"
},
"devDependencies": {
"@storybook/builder-webpack5": "^6.3.6",
"@storybook/manager-webpack5": "^6.3.6",
"chromatic": "^5.9.0",
"webpack": "^5"
}
} Running the following GitHub Action workflow failed: # .github/workflows/chromatic.yml
jobs:
# Deploy Chromatic
chromatic:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/storybook
steps:
# [...] checkout git history, setup node, cache etc.
# Install dependencies
- name: Install
run: yarn install --frozen-lockfile
working-directory: packages/storybook
# Chromatic deployment
- uses: chromaui/action@v1
with:
buildScriptName: build # script defined in packages/storybook/package.json
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
workingDir: packages/storybook The "prebuild" script fails, I guess because chromaui/action uses npm to build storybook, which is unaware of hoisted dependencies in my case?
I solved that by building storybook with yarn before invoking the action with # .github/workflows/chromatic.yml
jobs:
# Deploy Chromatic
chromatic:
runs-on: ubuntu-latest
steps:
# [...] checkout git history, setup node, cache etc.
# Install dependencies
- name: Install
run: yarn install --frozen-lockfile
# Build Storybook
- name: Build Storybook
run: yarn run build:storybook # script defined in root ./package.json
# Chromatic deployment
- uses: chromaui/action@v1
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
storybookBuildDir: storybook-static # or align that to whichever name you use if you set it with "build-storybook -o XXX"
token: ${{ secrets.GITHUB_TOKEN }}
workingDir: packages/storybook |
I know this is an old issue, but personally it took a lot of trial and error before I got this working for me I'll put my learnings here - maybe it'll help someone else :) I have a Drupal (CMS), with a theme folder where I had my package.json and .storybook (among other things) I quickly found out that I had to move package.json out in the root of the git, or Chromatic would never work. Sigh. In my "config": {
"themepath": "web/themes/custom/THEMENAME"
},
"scripts": {
"build-storybook": "build-storybook --config-dir $npm_package_config_themepath/.storybook"
} So far so good! Now for the Github Action:
name: 'Chromatic Deployment'
# the event that will trigger the action
on: push
jobs:
# Deploy Chromatic
chromatic:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # 👈 Required to retrieve git history
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm install
- run: npm run build
- run: npm run build-storybook
# Chromatic deployment
- uses: chromaui/action@v1
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
storybookBuildDir: storybook-static
token: ${{ secrets.GITHUB_TOKEN }}
workingDir: ./ Thank you all for your examples :) I would never have figured this out without this thread. |
By @isaac-martin in https://github.com/chromaui/action/issues/30:
Would love an option on this action to run the job inside a certain directory.
We have a mono repo with the below dir structure
Github actions need to live in the root - so currently we cant use this action and have to manually run chromatic using the script in our
package.json
I can implement this change if someone can point me in the right direction.
By wendylw in https://github.com/chromaui/action/issues/61:
Also requested by another customer.
┆Issue is synchronized with this Asana task by Unito
The text was updated successfully, but these errors were encountered: