Skip to content

Commit 6697527

Browse files
committed
chore: setup multiple storybooks to deploy
1 parent 11432bd commit 6697527

File tree

9 files changed

+105
-44
lines changed

9 files changed

+105
-44
lines changed

.github/workflows/docsite-publish-ghpages.yml

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,14 @@ name: 'Docsite publish to Github Pages'
44
on:
55
push:
66
branches:
7-
- master
7+
- chore/ghp-deployments-test
88
workflow_dispatch:
99

1010
jobs:
11-
check:
12-
runs-on: ubuntu-latest
13-
if: ${{ github.repository_owner == 'microsoft' }} && ${{ contains(github.event.head_commit.message, 'applying package updates') || github.event_name == 'workflow_dispatch' }}
14-
15-
outputs:
16-
status: ${{ steps.verify-react-components-changed.outputs.any_changed == 'true' || github.event_name == 'workflow_dispatch' }}
17-
18-
steps:
19-
- uses: actions/checkout@v4
20-
name: Checkout [master]
21-
22-
- name: Verify react-compoenents has changed
23-
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5
24-
id: verify-react-components-changed
25-
with:
26-
files: |
27-
packages/react-components/react-components/package.json
2811
build:
2912
runs-on: ubuntu-latest
30-
needs: check
31-
if: needs.check.outputs.status == 'true'
13+
outputs:
14+
artifact_id: ${{ steps.artifact_upload.outputs.artifact_id }}
3215

3316
steps:
3417
- uses: actions/checkout@v4
@@ -43,23 +26,32 @@ jobs:
4326
- name: Install packages
4427
run: yarn install --frozen-lockfile
4528

46-
- name: Install Playwright Browsers
47-
run: yarn playwright install --with-deps
29+
# - name: Install Playwright Browsers
30+
# run: yarn playwright install --with-deps
31+
#
32+
#
33+
- name: Affected Deployable Storybooks
34+
id: affected_storybooks_count
35+
run: |
36+
affected_count=$(yarn --silent nx show projects -t build-storybook:docsite --affected --verbose false | wc -l | tr -d ' ')
37+
echo "value=$affected_count" >> $GITHUB_OUTPUT
4838
49-
- name: Build storybook
50-
run: yarn nx run public-docsite-v9:build-storybook --nxBail
51-
env:
52-
STORYBOOK_APPINSIGHTS_INSTRUMENTATION_KEY: ${{ secrets.STORYBOOK_APPINSIGHTS_INSTRUMENTATION_KEY }}
39+
- name: Build affected storybooks
40+
if: steps.affected_storybooks_count.outputs.value > 0
41+
run: |
42+
yarn nx run-many -t build-storybook:docsite --nxBail
5343
5444
- name: Upload Pages Artifact
45+
if: steps.affected_storybooks_count.outputs.value > 0
46+
id: artifact_upload
5547
uses: actions/upload-pages-artifact@v3
5648
with:
57-
path: './apps/public-docsite-v9/dist/storybook/'
49+
path: './apps/public-docsite-v9/dist/'
5850

5951
deploy:
6052
runs-on: ubuntu-latest
6153
needs: build
62-
54+
if: needs.build.outputs.artifact_id
6355
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
6456
permissions:
6557
pages: write # to deploy to Pages

apps/chart-docsite/.storybook/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import type { StorybookConfig } from '@storybook/react-webpack5';
33
// eslint-disable-next-line @nx/enforce-module-boundaries
44
import rootConfig from '../../../.storybook/main';
55

6-
const config: StorybookConfig = {
6+
const config = {
77
...rootConfig,
8+
build: {
9+
previewUrl: process.env.DEPLOY_PATH,
10+
},
811
stories: [
912
// docsite stories
1013
'../src/**/*.mdx',
1114
'../src/**/index.stories.@(js|jsx|ts|tsx)',
1215
// packages stories
1316
'../../../packages/charts/react-charts/stories/**/index.stories.@(js|jsx|ts|tsx)',
1417
],
15-
};
18+
} satisfies StorybookConfig;
1619

1720
export default config;

apps/chart-docsite/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"description": "Fluent UI React Charts Preview documentation",
66
"scripts": {
77
"build-storybook": "storybook build -o ./dist/storybook --docs",
8-
"postbuild-storybook": "yarn rewrite-title && yarn generate-llms-docs",
8+
"build-storybook:docsite": "cross-env DEPLOY_PATH=/charts/ storybook build -o ../public-docsite-v9/dist/charts/ --docs",
9+
"postbuild-storybook": "yarn rewrite-title",
910
"rewrite-title": "node -r ../../scripts/ts-node/src/register ../../scripts/storybook/src/scripts/rewrite-title.ts --title 'Fluent UI Charts v9' --distPath ./dist/storybook",
1011
"generate-llms-docs": "yarn storybook-llms-extractor --distPath ./dist/storybook --summaryBaseUrl \"https://fluentuipr.z22.web.core.windows.net/pull/34838/chart-docsite/storybook\" --summaryTitle \"Fluent UI Charts v9\" --summaryDescription \"Fluent UI React charts is a set of modern, accessible, interactive, lightweight and highly customizable visualization library representing the Microsoft design system. These charts are used across 100s of projects inside Microsoft across Microsoft 365, Copilot and Azure.\"",
1112
"clean": "just-scripts clean",

apps/public-docsite-v9/.storybook/main.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ module.exports = /** @type {Omit<import('../../../.storybook/main'), 'typescript
3333
],
3434
staticDirs: ['../public'],
3535
addons: [...rootMain.addons],
36+
build: {
37+
previewUrl: process.env.DEPLOY_PATH,
38+
},
3639
webpackFinal: (config, options) => {
3740
const localConfig = /** @type config */ ({ ...rootMain.webpackFinal?.(config, options) });
3841

@@ -49,12 +52,5 @@ module.exports = /** @type {Omit<import('../../../.storybook/main'), 'typescript
4952
expanded: false,
5053
sourceUrl: 'https://github.com/microsoft/fluentui-contrib',
5154
},
52-
charts: {
53-
title: 'Charts v9',
54-
// Workaround to enable docsite using PR workflow till master workflow is enabled
55-
url: 'https://fluentuipr.z22.web.core.windows.net/pull/33270/chart-docsite/storybook',
56-
expanded: false,
57-
sourceUrl: 'https://github.com/microsoft/fluentui/charts/react-charts',
58-
},
5955
},
6056
});

apps/public-docsite-v9/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"private": true,
55
"description": "Fluent UI React v9 documentation",
66
"scripts": {
7-
"build-storybook": "cross-env NODE_OPTIONS=--max_old_space_size=3072 storybook build -o ./dist/storybook --docs",
8-
"postbuild-storybook": "yarn rewrite-title && yarn generate-llms-docs",
9-
"rewrite-title": "node -r ../../scripts/ts-node/src/register ../../scripts/storybook/src/scripts/rewrite-title.ts --title 'Fluent UI React v9' --distPath ./dist/storybook",
7+
"build-storybook": "cross-env NODE_OPTIONS=--max_old_space_size=3072 DEPLOY_PATH=/react/ storybook build -o ./dist/react --docs",
8+
"postbuild-storybook": "yarn rewrite-title",
9+
"rewrite-title": "node -r ../../scripts/ts-node/src/register ../../scripts/storybook/src/scripts/rewrite-title.ts --title 'Fluent UI React v9' --distPath ./dist/react",
10+
"inject-redirect": "node -r ../../scripts/ts-node/src/register ../../scripts/storybook/src/scripts/inject-redirect.ts --distPath ./dist/ --redirectUrl https://mainframev.github.io/fluentui/react",
1011
"generate-llms-docs": "yarn storybook-llms-extractor --config storybook-llms.config.js",
1112
"clean": "just-scripts clean",
1213
"code-style": "just-scripts code-style",

apps/public-docsite-v9/project.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
"implicitDependencies": ["tag:type:stories"],
66
"tags": ["platform:web", "vNext"],
77
"targets": {
8-
"build-storybook": {
8+
"build-storybook:docsite": {
9+
"executor": "nx:noop",
910
"dependsOn": [
11+
"build-storybook",
12+
"inject-redirect",
1013
{
11-
"projects": ["react-storybook-addon", "react-storybook-addon-export-to-sandbox", "storybook-llms-extractor"],
12-
"target": "build"
14+
"projects": ["chart-docsite", "web-components"],
15+
"target": "build-storybook:docsite"
1316
}
1417
]
1518
}

packages/web-components/.storybook/main.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ module.exports =
3535
},
3636
},
3737
],
38+
build: {
39+
previewUrl: process.env.DEPLOY_PATH,
40+
},
3841
webpackFinal: async config => {
3942
config.resolve = config.resolve ?? {};
4043
config.resolve.extensions = config.resolve.extensions ?? [];

packages/web-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"start": "yarn start-storybook -p 6006 --docs",
6666
"start-storybook": "storybook dev",
6767
"build-storybook": "storybook build -o ./dist/storybook --docs",
68+
"build-storybook:docsite": "cross-env DEPLOY_PATH=/web-components/ storybook build -o ../../apps/public-docsite-v9/dist/web-components --docs",
6869
"e2e": "node ./scripts/e2e.js",
6970
"e2e:local": "node ./scripts/e2e.js --ui"
7071
},
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { writeFileSync } from 'node:fs';
2+
import { join } from 'node:path';
3+
import { cwd } from 'node:process';
4+
import dedent from 'dedent';
5+
6+
import yargs from 'yargs';
7+
8+
main();
9+
10+
function main(): void {
11+
try {
12+
const { distPath, redirectUrl } = processArgs();
13+
const normalizedDistPath = join(cwd(), distPath);
14+
15+
const indexPath = join(normalizedDistPath, 'index.html');
16+
17+
injectRedirect(indexPath, redirectUrl);
18+
19+
console.log(`root index.html redirect to ${distPath} has been added.`);
20+
} catch (error) {
21+
console.log('Failed to add redirect.');
22+
console.error(error);
23+
process.exit(1);
24+
}
25+
}
26+
27+
function processArgs(): { distPath: string; redirectUrl: string } {
28+
const argv = yargs(process.argv)
29+
.usage('CLI to inject html redirect')
30+
.option('distPath', {
31+
type: 'string',
32+
demandOption: true,
33+
describe: 'Relative path to the Storybook distribution folder',
34+
})
35+
.option('redirectUrl', {
36+
type: 'string',
37+
demandOption: true,
38+
describe: 'URL to redirect to',
39+
})
40+
.alias('h', 'help')
41+
.version(false).argv;
42+
43+
return { redirectUrl: argv.redirectUrl, distPath: argv.distPath };
44+
}
45+
46+
function injectRedirect(filePath: string, url: string) {
47+
const content = dedent`
48+
<!DOCTYPE html>
49+
<html>
50+
<head>
51+
<meta http-equiv="refresh" content="0; url=${url}">
52+
<title>Redirecting...</title>
53+
</head>
54+
<body>
55+
<p>The has moved to <a href="${url}">${url}</a>. You will be automatically redirected.</p>
56+
</body>
57+
</html>
58+
`;
59+
60+
writeFileSync(filePath, content, 'utf-8');
61+
}

0 commit comments

Comments
 (0)