Skip to content

Commit abda3b6

Browse files
acid-chickensyuilo
andauthored
ci(#10336): use TurboSnap (#10494)
* ci(#10336): use TurboSnap * build: fix version * ci(#10336): update build dir * chore(#10336): fire changes * chore: stabilize icon width on `PageHeader` * chore: fire changes * ci: invalid ignore * ci: trace logs * chore: debug * revert: debug This reverts commit 2329165. * chore: do not reuse build dir * build: scripts * ci: tweak * revert: re-revert debug This reverts commit 596ef05. * chore: detect changes manually * fix: syntax * ci: do not use only-changed * ci: fix command * revert: re-re-revert debug This reverts commit b027170. * ci: use build dir * revert: re-re-re-revert debug This reverts commit 529ab12. * ci: fix path * revert: re-re-re-re-revert debug This reverts commit 0b0c0b9. * ci: fix typo * ci: only show story files * revert: re-re-re-re-re-revert debug This reverts commit 9f5b88d. * ci: skip when no stories found * ci: use skip * revert: re-re-re-re-re-re-revert debug This reverts commit 0df4bdc. * ci: fix micromatch version * revert: re-re-re-re-re-re-re-revert debug This reverts commit 63063b0. * revert: re-re-re-re-re-re-re-re-revert debug This reverts commit 01d9669. * chore: pin tabler icon width globally * ci: notify when Chromatic skips * ci: fix endpoint --------- Co-authored-by: syuilo <[email protected]>
1 parent 191ed3c commit abda3b6

File tree

11 files changed

+176
-181
lines changed

11 files changed

+176
-181
lines changed

.github/workflows/storybook.yml

+26-14
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ name: Storybook
22

33
on:
44
push:
5-
branches:
6-
- master
7-
- develop
8-
pull_request:
95
branches-ignore:
106
- l10n_develop
117

128
jobs:
139
build:
1410
runs-on: ubuntu-latest
1511

12+
env:
13+
NODE_OPTIONS: "--max_old_space_size=7168"
14+
1615
steps:
1716
- uses: actions/[email protected]
1817
with:
@@ -36,21 +35,34 @@ jobs:
3635
run: pnpm --filter misskey-js build
3736
- name: Build storybook
3837
run: pnpm --filter frontend build-storybook
38+
- name: Publish to Chromatic
39+
if: github.ref == 'refs/heads/master'
40+
run: pnpm --filter frontend chromatic --exit-once-uploaded -d storybook-static
3941
env:
40-
NODE_OPTIONS: "--max_old_space_size=7168"
42+
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
4143
- name: Publish to Chromatic
44+
if: github.ref != 'refs/heads/master'
4245
id: chromatic
43-
uses: chromaui/action@v1
44-
with:
45-
exitOnceUploaded: true
46-
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
47-
storybookBuildDir: storybook-static
48-
workingDir: packages/frontend
49-
- name: Compare on Chromatic
50-
if: github.event_name == 'pull_request_target'
51-
run: pnpm --filter frontend chromatic -d storybook-static --exit-once-uploaded --patch-build ${{ github.head_ref }}...${{ github.base_ref }}
46+
run: |
47+
CHROMATIC_PARAMETER="$(node packages/frontend/.storybook/changes.js $(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }} HEAD | xargs))"
48+
if [ "$CHROMATIC_PARAMETER" = " --skip" ]; then
49+
echo "skip=true" >> $GITHUB_OUTPUT
50+
fi
51+
pnpm --filter frontend chromatic --exit-once-uploaded -d storybook-static $(echo "$CHROMATIC_PARAMETER")
5252
env:
5353
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
54+
- name: Notify that Chromatic will skip testing
55+
uses: actions/[email protected]
56+
if: github.ref != 'refs/heads/master' && steps.chromatic.outputs.skip == 'true'
57+
with:
58+
github-token: ${{ secrets.GITHUB_TOKEN }}
59+
script: |
60+
github.rest.repos.createCommitComment({
61+
owner: context.repo.owner,
62+
repo: context.repo.repo,
63+
commit_sha: context.sha,
64+
body: 'Chromatic will skip testing but you may still have to [review the changes on Chromatic](https://www.chromatic.com/pullrequests?appId=6428f7d7b962f0b79f97d6e4).'
65+
})
5466
- name: Upload Artifacts
5567
uses: actions/upload-artifact@v3
5668
with:

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"scripts": {
1717
"build-pre": "node ./scripts/build-pre.js",
1818
"build": "pnpm build-pre && pnpm -r build && pnpm gulp",
19+
"build-storybook": "pnpm --filter frontend build-storybook",
1920
"start": "pnpm check:connect && cd packages/backend && node ./built/boot/index.js",
2021
"start:test": "cd packages/backend && cross-env NODE_ENV=test node ./built/boot/index.js",
2122
"init": "pnpm migrate",
+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# (cd path/to/frontend; pnpm tsc -p .storybook)
2-
# (cd path/to/frontend; node .storybook/generate.js)
1+
/changes.js
32
/generate.js
4-
# (cd path/to/frontend; node .storybook/preload-locale.js)
53
/preload-locale.js
64
/locale.ts
7-
# (cd path/to/frontend; node .storybook/preload-theme.js)
5+
/main.js
86
/preload-theme.js
97
/themes.ts
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import fs from 'node:fs/promises';
2+
import path from 'node:path';
3+
import micromatch from 'micromatch';
4+
import main from './main';
5+
6+
interface Stats {
7+
readonly modules: readonly {
8+
readonly id: string;
9+
readonly name: string;
10+
readonly reasons: readonly {
11+
readonly moduleName: string;
12+
}[];
13+
}[];
14+
}
15+
16+
fs.readFile(
17+
path.resolve(__dirname, '../storybook-static/preview-stats.json')
18+
).then((buffer) => {
19+
const stats: Stats = JSON.parse(buffer.toString());
20+
const keys = new Set(stats.modules.map((stat) => stat.id));
21+
const map = new Map(
22+
Array.from(keys, (key) => [
23+
key,
24+
new Set(
25+
stats.modules
26+
.filter((stat) => stat.id === key)
27+
.flatMap((stat) => stat.reasons)
28+
.map((reason) => reason.moduleName)
29+
),
30+
])
31+
);
32+
const modules = new Set(
33+
process.argv
34+
.slice(2)
35+
.map((arg) =>
36+
path.relative(
37+
path.resolve(__dirname, '..'),
38+
path.resolve(__dirname, '../../..', arg)
39+
)
40+
)
41+
.map((path) => (path.startsWith('.') ? path : `./${path}`))
42+
);
43+
if (
44+
micromatch(Array.from(modules), [
45+
'../../assets/**',
46+
'../../fluent-emojis/**',
47+
'../../locales/**',
48+
'../../misskey-assets/**',
49+
'assets/**',
50+
'public/**',
51+
'../../pnpm-lock.yaml',
52+
]).length
53+
) {
54+
return;
55+
}
56+
for (;;) {
57+
const oldSize = modules.size;
58+
for (const module of Array.from(modules)) {
59+
if (map.has(module)) {
60+
for (const dependency of Array.from(map.get(module)!)) {
61+
modules.add(dependency);
62+
}
63+
}
64+
}
65+
if (modules.size === oldSize) {
66+
break;
67+
}
68+
}
69+
const stories = micromatch(
70+
Array.from(modules),
71+
main.stories.map((story) => `./${path.relative('..', story)}`)
72+
);
73+
if (stories.length) {
74+
for (const story of stories) {
75+
process.stdout.write(` --only-story-files ${story}`);
76+
}
77+
} else {
78+
process.stdout.write(` --skip`);
79+
}
80+
});

packages/frontend/.storybook/main.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { resolve } from 'node:path';
22
import type { StorybookConfig } from '@storybook/vue3-vite';
33
import { mergeConfig } from 'vite';
4+
import turbosnap from 'vite-plugin-turbosnap';
45
const config = {
56
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
67
addons: [
@@ -20,8 +21,13 @@ const config = {
2021
core: {
2122
disableTelemetry: true,
2223
},
23-
async viteFinal(config, options) {
24+
async viteFinal(config) {
2425
return mergeConfig(config, {
26+
plugins: [
27+
turbosnap({
28+
rootDir: config.root ?? process.cwd(),
29+
}),
30+
],
2531
build: {
2632
target: [
2733
'chrome108',

packages/frontend/.storybook/tsconfig.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@
1818
"jsx": "react",
1919
"jsxFactory": "h"
2020
},
21-
"files": ["./generate.tsx", "./preload-locale.ts", "./preload-theme.ts"]
21+
"files": [
22+
"./changes.ts",
23+
"./generate.tsx",
24+
"./preload-locale.ts",
25+
"./preload-theme.ts"
26+
]
2227
}

packages/frontend/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"@types/gulp": "4.0.10",
9999
"@types/gulp-rename": "2.0.1",
100100
"@types/matter-js": "0.18.2",
101+
"@types/micromatch": "3.1.1",
101102
"@types/node": "18.15.11",
102103
"@types/punycode": "2.1.0",
103104
"@types/sanitize-html": "2.9.0",
@@ -112,8 +113,8 @@
112113
"@typescript-eslint/parser": "5.57.1",
113114
"@vitest/coverage-c8": "^0.29.8",
114115
"@vue/runtime-core": "3.2.47",
115-
"astring": "^1.8.4",
116-
"chokidar-cli": "^3.0.0",
116+
"astring": "1.8.4",
117+
"chokidar-cli": "3.0.0",
117118
"chromatic": "6.17.3",
118119
"cross-env": "7.0.3",
119120
"cypress": "12.9.0",
@@ -122,6 +123,7 @@
122123
"eslint-plugin-vue": "9.10.0",
123124
"fast-glob": "3.2.12",
124125
"happy-dom": "8.9.0",
126+
"micromatch": "3.1.10",
125127
"msw": "1.2.1",
126128
"msw-storybook-addon": "1.8.0",
127129
"prettier": "2.8.7",
@@ -131,6 +133,7 @@
131133
"storybook": "7.0.2",
132134
"storybook-addon-misskey-theme": "github:misskey-dev/storybook-addon-misskey-theme",
133135
"summaly": "github:misskey-dev/summaly",
136+
"vite-plugin-turbosnap": "^1.0.1",
134137
"vitest": "0.29.8",
135138
"vitest-fetch-mock": "0.2.2",
136139
"vue-eslint-parser": "9.1.1",

packages/frontend/src/components/global/MkA.stories.impl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const Default = {
2222
};
2323
},
2424
},
25-
template: '<MkA v-bind="props">Text</MkA>',
25+
template: '<MkA v-bind="props">Misskey</MkA>',
2626
};
2727
},
2828
async play({ canvasElement }) {

packages/frontend/src/components/global/MkPageHeader.stories.impl.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable @typescript-eslint/explicit-function-return-type */
2+
import { waitFor } from '@storybook/testing-library';
23
import { StoryObj } from '@storybook/vue3';
34
import MkPageHeader from './MkPageHeader.vue';
45
export const Empty = {
@@ -22,16 +23,16 @@ export const Empty = {
2223
template: '<MkPageHeader v-bind="props" />',
2324
};
2425
},
26+
async play() {
27+
const wait = new Promise((resolve) => setTimeout(resolve, 800));
28+
await waitFor(async () => await wait);
29+
},
2530
args: {
2631
static: true,
2732
tabs: [],
2833
},
2934
parameters: {
3035
layout: 'centered',
31-
chromatic: {
32-
/* This component has animations that are implemented with JavaScript. So it's unstable to take a snapshot. */
33-
disableSnapshot: true,
34-
},
3536
},
3637
} satisfies StoryObj<typeof MkPageHeader>;
3738
export const OneTab = {

packages/frontend/src/style.scss

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ hr {
127127
}
128128

129129
.ti {
130+
width: 1.28em;
130131
vertical-align: -12%;
131132
line-height: 1em;
132133

0 commit comments

Comments
 (0)