Skip to content

Commit 69ab344

Browse files
authored
ci: WebサイトのCIを追加 (typst-jp#176)
1 parent 9c6205d commit 69ab344

File tree

11 files changed

+772
-63
lines changed

11 files changed

+772
-63
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

.github/workflows/website.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI/CD for website
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
build-and-deploy:
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18+
- uses: jdx/mise-action@13abe502c30c1559a5c37dff303831bab82c9402 # v2.2.3
19+
- run: mise run generate-docs
20+
- run: mise run generate-web
21+
- name: Upload build artifacts
22+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
23+
with:
24+
name: build-artifacts
25+
path: website/dist
26+
- name: Deploy
27+
if: github.ref == 'refs/heads/main'
28+
uses: JamesIves/github-pages-deploy-action@6c2d9db40f9296374acc17b90404b6e8864128c8 # v4.7.3
29+
with:
30+
folder: website/dist # The folder the action should deploy.
31+
32+
textlint-md:
33+
runs-on: ubuntu-24.04
34+
steps:
35+
- name: Checkout the repository
36+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
37+
- name: Setup tools
38+
uses: jdx/mise-action@13abe502c30c1559a5c37dff303831bab82c9402 # v2.2.3
39+
- name: Install dependencies
40+
run: bun install --frozen-lockfile
41+
- name: Lint Markdown using textlint
42+
run: bun run --bun textlint-md
43+
44+
textlint-html:
45+
runs-on: ubuntu-24.04
46+
needs: build-and-deploy
47+
steps:
48+
- name: Checkout the repository
49+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
50+
- name: Download build artifacts
51+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
52+
with:
53+
name: build-artifacts
54+
path: website/dist
55+
- uses: jdx/mise-action@13abe502c30c1559a5c37dff303831bab82c9402 # v2.2.3
56+
- name: Install dependencies
57+
run: bun install --frozen-lockfile
58+
- name: Lint HTML using textlint
59+
run: bun run --bun textlint-html
60+
61+
website-ci:
62+
runs-on: ubuntu-24.04
63+
defaults:
64+
run:
65+
working-directory: ./website
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
include:
70+
- task: biome
71+
name: "Run Biome CI"
72+
command: "bun biome ci ."
73+
- task: vitest
74+
name: "Run test runner"
75+
command: "bun run test"
76+
steps:
77+
- name: Checkout the repository
78+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
79+
- name: Setup tools
80+
uses: jdx/mise-action@13abe502c30c1559a5c37dff303831bab82c9402 # v2.2.3
81+
- name: Install dependencies
82+
run: bun install --frozen-lockfile
83+
- name: ${{ matrix.name }}
84+
run: ${{ matrix.command }}

.mise.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
rust = "1.83.0"
33
node = "22.11.0"
44
bun = "1.1.37"
5+
pinact = "3.1.1"
56

67
[settings]
78
yes = true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Typst 日本語ドキュメント (非公式)
22

3-
[![CI/CD for Documentation](https://github.com/typst-jp/typst-jp.github.io/actions/workflows/deploy.yml/badge.svg?branch=main&event=push)](https://github.com/typst-jp/typst-jp.github.io/actions/workflows/deploy.yml)
3+
[![CI/CD for website](https://github.com/typst-jp/typst-jp.github.io/actions/workflows/website.yml/badge.svg?branch=main&event=push)](https://github.com/typst-jp/typst-jp.github.io/actions/workflows/website.yml)
44
[![翻訳進捗](https://img.shields.io/badge/Translation%20Progress%20%2f%20翻訳進捗-28%25-orange.svg)](https://github.com/typst-jp/typst-jp.github.io/issues/44)
55

66
> [!NOTE]

website/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ bun run build
2525
```sh
2626
bun run preview
2727
```
28+
29+
### Check
30+
31+
```sh
32+
# コードスタイルをチェックする
33+
bun run check
34+
35+
# 自動修正を行う
36+
bun run check:write
37+
```
38+
39+
### Test
40+
41+
```sh
42+
bun run test
43+
```

website/bun.lockb

13.4 KB
Binary file not shown.

website/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"preview": "vite preview",
99
"update-search-index": "pagefind --site ./dist/ --glob \"docs/**/*.html\"",
1010
"check": "biome check .",
11-
"check:write": "biome check --write ."
11+
"check:write": "biome check --write .",
12+
"test": "vitest"
1213
},
1314
"devDependencies": {
1415
"@biomejs/biome": "1.9.4",
@@ -21,6 +22,7 @@
2122
"pagefind": "^1.3.0",
2223
"tailwind-merge": "^3.3.0",
2324
"tailwindcss": "^4.1.5",
24-
"vite": "^6.2.5"
25+
"vite": "^6.2.5",
26+
"vitest": "^3.1.4"
2527
}
2628
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { Page } from "../types/model";
3+
import { flattenDocs } from "./flattenDocs";
4+
5+
describe("flattenDocs", () => {
6+
const createMockPage = (
7+
route: string,
8+
title: string,
9+
children: Page[] = [],
10+
): Page => ({
11+
route,
12+
title,
13+
description: `Description for ${title}`,
14+
part: null,
15+
outline: [],
16+
body: {
17+
kind: "html",
18+
content: `<p>${title} content</p>`,
19+
},
20+
children,
21+
});
22+
23+
it("空の配列を渡すと空の結果を返す", () => {
24+
const [flattenedPages, pagePaths] = flattenDocs([]);
25+
26+
expect(flattenedPages).toEqual([]);
27+
expect(pagePaths).toEqual([]);
28+
});
29+
30+
it("子を持たない単一ページを平坦化する", () => {
31+
const page = createMockPage("/docs/", "Documentation");
32+
const [flattenedPages, pagePaths] = flattenDocs([page]);
33+
34+
expect(flattenedPages).toEqual([page]);
35+
expect(pagePaths).toEqual([[page]]);
36+
});
37+
38+
it("複数の子を持たないページを平坦化する", () => {
39+
const page1 = createMockPage("/docs/", "Documentation");
40+
const page2 = createMockPage("/tutorial/", "Tutorial");
41+
const [flattenedPages, pagePaths] = flattenDocs([page1, page2]);
42+
43+
expect(flattenedPages).toEqual([page1, page2]);
44+
expect(pagePaths).toEqual([[page1], [page2]]);
45+
});
46+
47+
it("子を持つページを平坦化する", () => {
48+
const childPage = createMockPage("/docs/tutorial/", "Tutorial");
49+
const parentPage = createMockPage("/docs/", "Documentation", [childPage]);
50+
const [flattenedPages, pagePaths] = flattenDocs([parentPage]);
51+
52+
expect(flattenedPages).toEqual([parentPage, childPage]);
53+
expect(pagePaths).toEqual([[parentPage], [parentPage, childPage]]);
54+
});
55+
56+
it("複数階層のページを平坦化する", () => {
57+
const grandChildPage = createMockPage("/docs/tutorial/basics/", "Basics");
58+
const childPage = createMockPage("/docs/tutorial/", "Tutorial", [
59+
grandChildPage,
60+
]);
61+
const parentPage = createMockPage("/docs/", "Documentation", [childPage]);
62+
const [flattenedPages, pagePaths] = flattenDocs([parentPage]);
63+
64+
expect(flattenedPages).toEqual([parentPage, childPage, grandChildPage]);
65+
expect(pagePaths).toEqual([
66+
[parentPage],
67+
[parentPage, childPage],
68+
[parentPage, childPage, grandChildPage],
69+
]);
70+
});
71+
72+
it("複数の子を持つページを平坦化する", () => {
73+
const child1 = createMockPage("/docs/tutorial/", "Tutorial");
74+
const child2 = createMockPage("/docs/reference/", "Reference");
75+
const parentPage = createMockPage("/docs/", "Documentation", [
76+
child1,
77+
child2,
78+
]);
79+
const [flattenedPages, pagePaths] = flattenDocs([parentPage]);
80+
81+
expect(flattenedPages).toEqual([parentPage, child1, child2]);
82+
expect(pagePaths).toEqual([
83+
[parentPage],
84+
[parentPage, child1],
85+
[parentPage, child2],
86+
]);
87+
});
88+
89+
it("複雑な階層構造を平坦化する", () => {
90+
// docs/
91+
// ├── tutorial/
92+
// │ ├── basics/
93+
// │ └── advanced/
94+
// └── reference/
95+
// └── functions/
96+
const basics = createMockPage("/docs/tutorial/basics/", "Basics");
97+
const advanced = createMockPage("/docs/tutorial/advanced/", "Advanced");
98+
const tutorial = createMockPage("/docs/tutorial/", "Tutorial", [
99+
basics,
100+
advanced,
101+
]);
102+
103+
const functions = createMockPage("/docs/reference/functions/", "Functions");
104+
const reference = createMockPage("/docs/reference/", "Reference", [
105+
functions,
106+
]);
107+
108+
const docs = createMockPage("/docs/", "Documentation", [
109+
tutorial,
110+
reference,
111+
]);
112+
113+
const [flattenedPages, pagePaths] = flattenDocs([docs]);
114+
115+
expect(flattenedPages).toEqual([
116+
docs,
117+
tutorial,
118+
basics,
119+
advanced,
120+
reference,
121+
functions,
122+
]);
123+
expect(pagePaths).toEqual([
124+
[docs],
125+
[docs, tutorial],
126+
[docs, tutorial, basics],
127+
[docs, tutorial, advanced],
128+
[docs, reference],
129+
[docs, reference, functions],
130+
]);
131+
});
132+
133+
it("複数のルートページを持つ階層構造を平坦化する", () => {
134+
const tutorialChild = createMockPage("/tutorial/basics/", "Basics");
135+
const tutorial = createMockPage("/tutorial/", "Tutorial", [tutorialChild]);
136+
137+
const docsChild = createMockPage("/docs/reference/", "Reference");
138+
const docs = createMockPage("/docs/", "Documentation", [docsChild]);
139+
140+
const [flattenedPages, pagePaths] = flattenDocs([tutorial, docs]);
141+
142+
expect(flattenedPages).toEqual([tutorial, tutorialChild, docs, docsChild]);
143+
expect(pagePaths).toEqual([
144+
[tutorial],
145+
[tutorial, tutorialChild],
146+
[docs],
147+
[docs, docsChild],
148+
]);
149+
});
150+
151+
it("パス情報が正しく設定される", () => {
152+
const grandChild = createMockPage("/a/b/c/", "C");
153+
const child = createMockPage("/a/b/", "B", [grandChild]);
154+
const parent = createMockPage("/a/", "A", [child]);
155+
156+
const [flattenedPages, pagePaths] = flattenDocs([parent]);
157+
158+
expect(pagePaths[0]).toEqual([parent]);
159+
expect(pagePaths[1]).toEqual([parent, child]);
160+
expect(pagePaths[2]).toEqual([parent, child, grandChild]);
161+
162+
expect(pagePaths[0][0].route).toBe("/a/");
163+
expect(pagePaths[1][1].route).toBe("/a/b/");
164+
expect(pagePaths[2][2].route).toBe("/a/b/c/");
165+
});
166+
});

0 commit comments

Comments
 (0)