Skip to content

Commit d9e427c

Browse files
committed
chore: 添加 action
1 parent a9936d7 commit d9e427c

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Deploy Documentation and Release Package
2+
3+
on:
4+
push:
5+
branches: [ dev ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages"
15+
cancel-in-progress: false
16+
17+
jobs:
18+
# 构建文档 - 使用现有 docker-compose.yml
19+
build-docs:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Build documentation using docker-compose
28+
run: |
29+
# 使用现有的 docker-compose.yml 构建 mockm-dev 服务
30+
docker-compose build mockm-dev
31+
32+
# 运行文档构建命令
33+
docker-compose run --rm mockm-dev \
34+
sh -c "cd doc && cross-env NODE_OPTIONS=--openssl-legacy-provider vuepress build . --config .vuepress/config.github.js"
35+
36+
- name: Copy test resources
37+
run: |
38+
mkdir -p doc/.vuepress/dist/case
39+
cp -r test/res/* doc/.vuepress/dist/case/ || true
40+
41+
- name: Upload Pages artifact
42+
uses: actions/upload-pages-artifact@v3
43+
with:
44+
path: doc/.vuepress/dist
45+
46+
# 部署到 GitHub Pages
47+
deploy-pages:
48+
environment:
49+
name: github-pages
50+
url: ${{ steps.deployment.outputs.page_url }}
51+
runs-on: ubuntu-latest
52+
needs: build-docs
53+
steps:
54+
- name: Deploy to GitHub Pages
55+
id: deployment
56+
uses: actions/deploy-pages@v4
57+
58+
# 构建和发布包 - 使用现有 docker-compose.yml
59+
build-and-release:
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@v4
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Build using docker-compose
68+
run: |
69+
# 构建所需的服务
70+
docker-compose build mockm-client mockm-dev
71+
72+
# 构建客户端
73+
docker-compose run --rm mockm-client \
74+
sh -c "cd client && yarn build"
75+
76+
# 构建服务端包
77+
docker-compose run --rm mockm-dev \
78+
sh -c "cd release && pnpm run build"
79+
80+
- name: Get package info
81+
run: |
82+
VERSION=$(node -p "require('./package.json').version")
83+
echo "VERSION=$VERSION" >> $GITHUB_ENV
84+
echo "PACKAGE_NAME=mockm" >> $GITHUB_ENV
85+
86+
- name: Create Release
87+
uses: softprops/action-gh-release@v1
88+
with:
89+
tag_name: v${{ env.VERSION }}
90+
name: Release v${{ env.VERSION }}
91+
body: |
92+
## Changes in v${{ env.VERSION }}
93+
94+
Auto-generated release from dev branch using existing Docker Compose configuration.
95+
96+
### Package Info
97+
- Version: ${{ env.VERSION }}
98+
- Build Date: ${{ github.event.head_commit.timestamp }}
99+
- Commit: ${{ github.sha }}
100+
- Built with: Docker Compose (reusing existing config)
101+
102+
### Download
103+
- [mockm-${{ env.VERSION }}.tgz](https://github.com/${{ github.repository }}/releases/download/v${{ env.VERSION }}/mockm-${{ env.VERSION }}.tgz)
104+
draft: false
105+
prerelease: ${{ contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta') }}
106+
files: |
107+
./dist/${{ env.PACKAGE_NAME }}-${{ env.VERSION }}.tgz
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
111+
- name: Cleanup Docker resources
112+
if: always()
113+
run: |
114+
docker-compose down --volumes --remove-orphans || true
115+
docker system prune -f || true

doc/.vuepress/config.github.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const baseConfig = require('./config.js')
2+
3+
// 统一的链接替换函数
4+
function replaceHongqiyeLinks(url) {
5+
if (!url || typeof url !== 'string') return url
6+
return url.replace(/https?:\/\/(www\.)?hongqiye\.com\/doc\/mockm/g, '/mockm')
7+
}
8+
9+
module.exports = {
10+
...baseConfig,
11+
base: '/mockm/', // GitHub Pages 部署地址,格式:/仓库名/
12+
// 使用默认的 dist 目录,无需修改 dest
13+
14+
// 移除原配置中的服务器特定设置
15+
head: baseConfig.head.filter(item => {
16+
// 保留 favicon 和基本的统计代码,移除服务器特定的统计
17+
if (Array.isArray(item) && item[0] === 'script' && item[1].src) {
18+
return !item[1].src.includes('cnzz.com')
19+
}
20+
return true
21+
}),
22+
23+
// 扩展 markdown 配置,替换 hongqiye.com 链接
24+
markdown: {
25+
...baseConfig.markdown,
26+
extendMarkdown: md => {
27+
// 先执行原有的 markdown 扩展
28+
if (baseConfig.markdown && baseConfig.markdown.extendMarkdown) {
29+
baseConfig.markdown.extendMarkdown(md)
30+
}
31+
32+
// 添加链接替换规则
33+
md.core.ruler.push('replace_hongqiye_links', state => {
34+
state.tokens.forEach(token => {
35+
if (token.type === 'inline' && token.children) {
36+
token.children.forEach(child => {
37+
if (child.type === 'link_open') {
38+
const href = child.attrGet('href')
39+
const newHref = replaceHongqiyeLinks(href)
40+
if (newHref !== href) {
41+
child.attrSet('href', newHref)
42+
}
43+
}
44+
})
45+
}
46+
})
47+
})
48+
}
49+
},
50+
51+
// 更新导航栏和链接
52+
themeConfig: {
53+
...baseConfig.themeConfig,
54+
nav: baseConfig.themeConfig.nav.map(item => {
55+
// 更新版本信息
56+
if (item.text && item.text.includes('版本')) {
57+
return { ...item, text: `版本 v${require('../../package.json').version}` }
58+
}
59+
// 统一处理所有 hongqiye.com 链接
60+
if (item.link) {
61+
return { ...item, link: replaceHongqiyeLinks(item.link) }
62+
}
63+
return item
64+
})
65+
}
66+
}

0 commit comments

Comments
 (0)