Skip to content

Commit

Permalink
build: use dotenvx to customise storybook setup depending on runtime …
Browse files Browse the repository at this point in the history
…environment
  • Loading branch information
Parsium committed Dec 11, 2024
1 parent 0e4e9f0 commit 14145aa
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 119 deletions.
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
STORYBOOK_BUILD=true
USE_DEBUG_THEME=true
USE_VERSION_PICKER=false
IGNORE_TESTS=false
STORYBOOK_VIEW_MODE=docs
5 changes: 5 additions & 0 deletions .env.chromatic
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
STORYBOOK_BUILD=true
USE_DEBUG_THEME=false
USE_VERSION_PICKER=false
IGNORE_TESTS=false
STORYBOOK_VIEW_MODE=docs
5 changes: 5 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
STORYBOOK_BUILD=true
USE_DEBUG_THEME=false
USE_VERSION_PICKER=true
IGNORE_TESTS=true
STORYBOOK_VIEW_MODE=docs
1 change: 1 addition & 0 deletions .github/workflows/chromatic-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
buildScriptName: build-storybook:chromatic
onlyChanged: true
exitOnceUploaded: true # We don't want it to fail CI, we'll be using the GitHub Check
7 changes: 6 additions & 1 deletion .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ jobs:
run: npm ci

- name: Run chromatic on branch
run: npx chromatic@latest --project-token ${{ secrets.CHROMATIC_PROJECT_TOKEN }} --exit-once-uploaded --branch-name="${{ needs.check.outputs.branch_name }}" --only-changed true
run: npx chromatic@latest \
--project-token ${{ secrets.CHROMATIC_PROJECT_TOKEN }} \
--buildScriptName build-storybook:chromatic \
--exit-once-uploaded \
--branch-name "${{ needs.check.outputs.branch_name }}" \
--only-changed true
2 changes: 1 addition & 1 deletion .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- run: npm ci
- name: Generate metadata file
run: npm run generate-metadata
- run: NODE_ENV=production IGNORE_TESTS=true STORYBOOK_VIEW_MODE=docs npm run build-storybook
- run: npm run build-storybook:prod
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
node-version: ">=20.9.0 20"
- run: npm ci
- run: NODE_ENV=production IGNORE_TESTS=true STORYBOOK_VIEW_MODE=docs npm run build-storybook
- run: npm run build-storybook:prod
- uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
6 changes: 4 additions & 2 deletions .storybook/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { ADDON_ID, TOOL_ID } from "./version-picker/constants";
import { VersionPicker } from "./version-picker";
import { API_PreparedIndexEntry, API_StatusObject } from "@storybook/types";

if (process.env.NODE_ENV === "production") {
const useVersionPicker = process.env.USE_VERSION_PICKER === "true";

if (useVersionPicker) {
addons.register(ADDON_ID, () => {
addons.add(TOOL_ID, {
type: types.TOOL,
Expand All @@ -23,7 +25,7 @@ addons.setConfig({
patterns: (
item: API_PreparedIndexEntry & {
status: Record<string, API_StatusObject | null>;
}
},
): boolean => {
return !(item.tags ?? []).includes("hideInSidebar");
},
Expand Down
3 changes: 2 additions & 1 deletion .storybook/withThemeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const themes = [noTheme, sageTheme].reduce((themesObject, theme) => {
return themesObject;
}, {});

if (process.env.STORYBOOK_DEBUG_THEME === "true") {
const useDebugTheme = process.env.USE_DEBUG_THEME === "true";
if (useDebugTheme) {
themes["sage-debug"] = sageDebugTheme;
}

Expand Down
Loading

0 comments on commit 14145aa

Please sign in to comment.