Skip to content

Commit fb5b5d2

Browse files
authored
Merge pull request #124 from gimmyhehe/github-deploy-all
ci: add GitHub Pages deployment workflow and build scripts
2 parents dd0c82a + 9c6ae9f commit fb5b5d2

11 files changed

Lines changed: 258 additions & 15 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Deploy GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: pages
16+
cancel-in-progress: false
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
environment: github-pages
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
submodules: recursive
28+
29+
- name: Setup pnpm
30+
uses: pnpm/action-setup@v4
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: 20
36+
cache: pnpm
37+
38+
- name: Install dependencies
39+
run: pnpm install --frozen-lockfile
40+
41+
- name: Build sites for GitHub Pages
42+
env:
43+
NODE_OPTIONS: --max_old_space_size=4096
44+
VITE_GENUI_DOCS_BASE: ${{ vars.DOCS_BASE }}
45+
VITE_GENUI_PLAYGROUND_HREF: ${{ vars.PLAYGROUND_HREF }}
46+
VITE_CHAT_URL: ${{ vars.PLAYGROUND_BACKEND_URL }}/chat-genui
47+
VITE_GET_MODELS_URL: ${{ vars.PLAYGROUND_BACKEND_URL }}/get-models
48+
VITE_CHECK_MCP_URL: ${{ vars.PLAYGROUND_BACKEND_URL }}/check-mcp
49+
run: node scripts/build-github-pages.mjs
50+
51+
- name: Upload Pages artifact
52+
uses: actions/upload-pages-artifact@v3
53+
with:
54+
path: _site
55+
56+
deploy:
57+
needs: build
58+
runs-on: ubuntu-latest
59+
environment:
60+
name: github-pages
61+
url: ${{ steps.deployment.outputs.page_url }}
62+
steps:
63+
- name: Deploy to GitHub Pages
64+
id: deployment
65+
uses: actions/deploy-pages@v4

.github/workflows/deploy-obs-playground.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: Deploy GenUI SDK Playground to Huawei OBS
22

33
on:
4-
push:
5-
branches:
6-
- dev
7-
- main
84
workflow_dispatch:
95
inputs:
106
env:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,6 @@ vite.config.ts.timestamp-*
145145

146146
# Rollup visualizer files
147147
stats.html
148+
149+
# GitHub Pages 本地合并输出
150+
_site/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"build:playground": "pnpm --filter genui-sdk-playground build",
1919
"build:playground-web": "pnpm prebuild:playground && pnpm --filter genui-sdk-playground-web build",
2020
"build:homepage": "pnpm --filter genui-sdk-homepage-web build",
21+
"build:docs": "pnpm --filter genui-sdk-docs build",
2122
"build": "pnpm build:playground"
2223
},
2324
"pnpm": {

packages/frameworks/angular/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"zod": "^3.25.76",
8585
"zod-to-json-schema": "^3.24.6",
8686
"jsonrepair": "^3.13.3",
87-
"ai": "6.0.116"
87+
"ai": "6.0.116",
88+
"tsx": "^4.18.0"
8889
}
8990
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build-github-pages.mjs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* 构建 homepage、文档、playground-web,合并到仓库根目录 _site/,供 GitHub Pages 上传。。
3+
*
4+
* 本地调试:
5+
* export ROOT_BASE=/ VITE_GENUI_DOCS_BASE=/docs VITE_GENUI_PLAYGROUND_HREF=/playground && node scripts/build-github-pages.mjs
6+
*/
7+
import { spawnSync } from 'node:child_process'
8+
import { copyFile, cp, rm } from 'node:fs/promises'
9+
import path from 'node:path'
10+
import { fileURLToPath } from 'node:url'
11+
12+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
13+
const ROOT = path.resolve(__dirname, '..')
14+
15+
16+
function withTrailingSlash(s) {
17+
return s.endsWith('/') ? s : `${s}/`
18+
}
19+
20+
function run(cmd, args, options = {}) {
21+
const r = spawnSync(cmd, args, {
22+
cwd: ROOT,
23+
stdio: 'inherit',
24+
env: process.env,
25+
...options,
26+
})
27+
if (r.error) throw r.error
28+
if (r.status !== 0) process.exit(r.status ?? 1)
29+
}
30+
31+
function runPnpm(args, options = {}) {
32+
run('pnpm', args, options)
33+
}
34+
35+
async function buildAllPages() {
36+
const rootBase = process.env.ROOT_BASE || '/genui-sdk'
37+
const siteBase = withTrailingSlash(`${rootBase}`)
38+
const playgroundBase = withTrailingSlash(`${siteBase}playground`)
39+
const docsBase = withTrailingSlash(`${siteBase}docs`)
40+
41+
console.log(`site base: ${siteBase}`)
42+
console.log(`playground base: ${playgroundBase}`)
43+
console.log(`docs base: ${docsBase}`)
44+
45+
46+
console.log('>>> prebuild')
47+
runPnpm(['run', 'prebuild:playground'])
48+
49+
console.log('>>> build:playground-web')
50+
runPnpm(['exec', 'vite', 'build', `--base=${playgroundBase}`], {
51+
cwd: path.join(ROOT, 'sites/playground/web'),
52+
})
53+
54+
console.log('>>> build:docs')
55+
runPnpm(['exec', 'pnpm', 'build', `--base=${docsBase}`], {
56+
cwd: path.join(ROOT, 'docs'),
57+
})
58+
59+
console.log('>>> build:homepage')
60+
runPnpm(['exec', 'pnpm', 'build:web', `--base=${siteBase}`], {
61+
cwd: path.join(ROOT, 'sites/homepage/web'),
62+
})
63+
64+
const pgDist = path.join(ROOT, 'sites/playground/web/dist')
65+
await copyFile(path.join(pgDist, 'index.html'), path.join(pgDist, '404.html'))
66+
67+
console.log('>>> assemble _site')
68+
const out = path.join(ROOT, '_site')
69+
await rm(out, { recursive: true, force: true })
70+
// 目标不存在时 cp 会把 dist 整棵拷成 _site,等价于 bash 的 dist/. → _site/
71+
await cp(path.join(ROOT, 'sites/homepage/web/dist'), out, { recursive: true })
72+
await cp(path.join(ROOT, 'docs/.vitepress/dist'), path.join(out, 'docs'), { recursive: true })
73+
await cp(path.join(ROOT, 'sites/playground/web/dist'), path.join(out, 'playground'), {
74+
recursive: true,
75+
})
76+
77+
console.log(`Done. Output: ${out}`)
78+
}
79+
80+
buildAllPages().catch((err) => {
81+
console.error(err)
82+
process.exit(1)
83+
})

sites/homepage/web/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VITE_GENUI_DOC_DOMAIN=/doc-domain
1+
VITE_GENUI_DOCS_BASE=/doc-domain
22
VITE_GENUI_PLAYGROUND_HREF=/playground-href

sites/homepage/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"scripts": {
88
"dev": "vite",
99
"build": "vue-tsc --noEmit && vite build",
10+
"build:web": "vue-tsc --noEmit && vite build --config vite-web.config.ts",
1011
"preview": "vite preview"
1112
},
1213
"dependencies": {

sites/homepage/web/src/utils/link.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const DOC_DOMAIN = import.meta.env.VITE_GENUI_DOC_DOMAIN || 'https://docs.opentiny.design';
1+
const DOCS_BASE = import.meta.env.VITE_GENUI_DOCS_BASE || 'https://docs.opentiny.design/genui-sdk';
22
const PLAYGROUND_HREF = import.meta.env.VITE_GENUI_PLAYGROUND_HREF || 'https://playground.opentiny.design/genui-sdk';
33

44
export const linkMap = {
5-
devDoc: `${DOC_DOMAIN}/genui-sdk/guide/quick-start`,
5+
devDoc: `${DOCS_BASE}/guide/quick-start`,
66
playground: PLAYGROUND_HREF,
7-
chatDoc: `${DOC_DOMAIN}/genui-sdk/components/chat`,
8-
dcologicalCompatibility: `${DOC_DOMAIN}/genui-sdk/examples/chat/custom-fetch`,
9-
defineTheme: `${DOC_DOMAIN}/genui-sdk/examples/config-provider/theme`,
10-
defineComponent: `${DOC_DOMAIN}/genui-sdk/examples/chat/custom-components`,
11-
defineAction: `${DOC_DOMAIN}/genui-sdk/examples/chat/custom-actions`,
12-
multiTechnology: `${DOC_DOMAIN}/genui-sdk/components/angular/renderer`,
13-
moreFeatures: `${DOC_DOMAIN}/genui-sdk/examples/chat/custom-examples`,
7+
chatDoc: `${DOCS_BASE}/components/chat`,
8+
dcologicalCompatibility: `${DOCS_BASE}/examples/chat/custom-fetch`,
9+
defineTheme: `${DOCS_BASE}/examples/config-provider/theme`,
10+
defineComponent: `${DOCS_BASE}/examples/chat/custom-components`,
11+
defineAction: `${DOCS_BASE}/examples/chat/custom-actions`,
12+
multiTechnology: `${DOCS_BASE}/components/angular/renderer`,
13+
moreFeatures: `${DOCS_BASE}/examples/chat/custom-examples`,
1414
};
1515

1616
export enum LinkKey {

0 commit comments

Comments
 (0)